2014-08-27 07:03:42 +02:00
< ? php
2016-02-27 16:21:40 +01:00
/* Copyright ( C ) 2013 - 2016 Olivier Geffroy < jeff @ jeffinfo . com >
2020-01-03 22:05:49 +01:00
* Copyright ( C ) 2013 - 2020 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-04-09 11:31:24 +02:00
* Copyright ( C ) 2016 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-08-27 07:03:42 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-08-27 07:03:42 +02:00
*/
/**
2016-02-27 16:21:40 +01:00
* \file htdocs / accountancy / admin / account . php
2019-05-13 22:25:15 +02:00
* \ingroup Accountancy ( Double entries )
2016-02-27 16:21:40 +01:00
* \brief List accounting account
2014-08-27 07:03:42 +02:00
*/
2016-02-01 14:50:25 +01:00
2016-10-07 12:10:16 +02:00
require '../../main.inc.php' ;
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php' ;
2020-01-21 21:36:40 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php' ;
2014-08-27 07:03:42 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2019-11-13 19:35:39 +01:00
$langs -> loadLangs ( array ( " compta " , " bills " , " admin " , " accountancy " , " salaries " ));
2014-08-27 07:03:42 +02:00
$mesg = '' ;
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2014-08-27 07:03:42 +02:00
$id = GETPOST ( 'id' , 'int' );
$rowid = GETPOST ( 'rowid' , 'int' );
2019-10-06 21:11:29 +02:00
$massaction = GETPOST ( 'massaction' , 'aZ09' );
2021-10-23 21:14:32 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2019-11-13 19:35:39 +01:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'accountingaccountlist' ; // To manage different context of search
2017-01-31 06:08:40 +01:00
2019-01-27 11:55:16 +01:00
$search_account = GETPOST ( 'search_account' , 'alpha' );
$search_label = GETPOST ( 'search_label' , 'alpha' );
2020-01-03 22:05:49 +01:00
$search_labelshort = GETPOST ( 'search_labelshort' , 'alpha' );
2019-01-27 11:55:16 +01:00
$search_accountparent = GETPOST ( 'search_accountparent' , 'alpha' );
$search_pcgtype = GETPOST ( 'search_pcgtype' , 'alpha' );
2021-04-03 10:12:05 +02:00
$toselect = GETPOST ( 'toselect' , 'array' );
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
$confirm = GETPOST ( 'confirm' , 'alpha' );
2014-08-27 07:03:42 +02:00
2020-02-26 15:41:46 +01:00
$chartofaccounts = GETPOST ( 'chartofaccounts' , 'int' );
2021-10-22 22:05:04 +02:00
$permissiontoadd = ! empty ( $user -> rights -> accounting -> chartofaccount );
$permissiontodelete = ! empty ( $user -> rights -> accounting -> chartofaccount );
2021-04-03 10:12:05 +02:00
2014-08-27 07:03:42 +02:00
// Security check
2021-02-22 21:36:42 +01:00
if ( $user -> socid > 0 ) {
accessforbidden ();
}
2021-10-22 22:05:04 +02:00
if ( empty ( $user -> rights -> accounting -> chartofaccount )) {
2021-02-22 21:36:42 +01:00
accessforbidden ();
}
2014-08-27 07:03:42 +02:00
2016-05-12 21:32:24 +02:00
// Load variable for pagination
2020-01-30 01:48:28 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:30:10 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-22 21:36:42 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2016-05-12 21:32:24 +02:00
$offset = $limit * $page ;
2014-08-27 07:03:42 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-22 21:36:42 +01:00
if ( ! $sortfield ) {
$sortfield = " aa.account_number " ;
}
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
2014-08-27 07:03:42 +02:00
2019-11-13 19:35:39 +01:00
$arrayfields = array (
2020-10-31 14:32:18 +01:00
'aa.account_number' => array ( 'label' => $langs -> trans ( " AccountNumber " ), 'checked' => 1 ),
'aa.label' => array ( 'label' => $langs -> trans ( " Label " ), 'checked' => 1 ),
2020-01-03 22:05:49 +01:00
'aa.labelshort' => array ( 'label' => $langs -> trans ( " LabelToShow " ), 'checked' => 1 ),
2018-09-18 11:49:35 +02:00
'aa.account_parent' => array ( 'label' => $langs -> trans ( " Accountparent " ), 'checked' => 1 ),
2020-10-31 14:32:18 +01:00
'aa.pcg_type' => array ( 'label' => $langs -> trans ( " Pcgtype " ), 'checked' => 1 , 'help' => 'PcgtypeDesc' ),
'aa.reconcilable' => array ( 'label' => $langs -> trans ( " Reconcilable " ), 'checked' => 1 ),
2020-03-15 07:49:24 +01:00
'aa.active' => array ( 'label' => $langs -> trans ( " Activated " ), 'checked' => 1 )
2017-01-31 06:08:40 +01:00
);
2021-02-22 21:36:42 +01:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) {
unset ( $arrayfields [ 'aa.reconcilable' ]);
}
2020-03-15 07:49:24 +01:00
2014-08-27 07:03:42 +02:00
$accounting = new AccountingAccount ( $db );
2017-05-29 11:17:33 +02:00
2016-05-12 21:32:24 +02:00
/*
* Actions
*/
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = 'list' ; $massaction = '' ;
}
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' )) {
$massaction = '' ;
}
2016-05-12 21:32:24 +02:00
2019-11-13 19:35:39 +01:00
$parameters = array ();
2021-04-07 01:09:23 +02:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been monowraponalldified by some hooks
2021-02-22 21:36:42 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2016-05-12 21:32:24 +02:00
2021-02-22 21:36:42 +01:00
if ( empty ( $reshook )) {
if ( ! empty ( $cancel )) {
$action = '' ;
}
2021-04-13 09:46:50 +02:00
2021-04-03 10:12:05 +02:00
$objectclass = 'AccountingAccount' ;
$uploaddir = $conf -> accounting -> multidir_output [ $conf -> entity ];
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2021-04-13 09:46:50 +02:00
2021-04-03 10:12:05 +02:00
if ( $action == " delete " ) {
$action = " " ;
}
2020-10-31 14:32:18 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
2017-08-31 18:29:57 +02:00
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$search_account = " " ;
$search_label = " " ;
2020-01-03 22:05:49 +01:00
$search_labelshort = " " ;
$search_accountparent = " " ;
2020-10-31 14:32:18 +01:00
$search_pcgtype = " " ;
2019-11-13 19:35:39 +01:00
$search_array_options = array ();
2020-10-31 14:32:18 +01:00
}
if (( GETPOST ( 'valid_change_chart' , 'alpha' ) && GETPOST ( 'chartofaccounts' , 'int' ) > 0 ) // explicit click on button 'Change and load' with js on
2021-02-22 21:36:42 +01:00
|| ( GETPOST ( 'chartofaccounts' , 'int' ) > 0 && GETPOST ( 'chartofaccounts' , 'int' ) != $conf -> global -> CHARTOFACCOUNTS )) { // a submit of form is done and chartofaccounts combo has been modified
2021-04-13 09:46:50 +02:00
if ( $chartofaccounts > 0 && $permissiontoadd ) {
2017-10-23 20:42:09 +02:00
// Get language code for this $chartofaccounts
2019-11-13 19:35:39 +01:00
$sql = 'SELECT code FROM ' . MAIN_DB_PREFIX . 'c_country as c, ' . MAIN_DB_PREFIX . 'accounting_system as a' ;
$sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = ' . ( int ) $chartofaccounts ;
2017-10-23 20:42:09 +02:00
$resql = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( $resql ) {
2017-10-23 20:42:09 +02:00
$obj = $db -> fetch_object ( $resql );
$country_code = $obj -> code ;
2021-02-22 21:36:42 +01:00
} else {
dol_print_error ( $db );
}
2017-10-23 20:42:09 +02:00
// Try to load sql file
2021-02-22 21:36:42 +01:00
if ( $country_code ) {
2017-10-23 20:42:09 +02:00
$sqlfile = DOL_DOCUMENT_ROOT . '/install/mysql/data/llx_accounting_account_' . strtolower ( $country_code ) . '.sql' ;
2018-09-03 14:00:12 +02:00
2018-09-17 21:02:07 +02:00
$offsetforchartofaccount = 0 ;
// Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
// and pass CCCNNNNN + (num of company * 100 000 000) as offset to the run_sql as a new parameter to say to update sql on the fly to add offset to rowid and account_parent value.
// This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
$tmp = file_get_contents ( $sqlfile );
2021-03-10 10:45:01 +01:00
$reg = array ();
2021-02-22 21:36:42 +01:00
if ( preg_match ( '/-- ADD (\d+) to rowid/ims' , $tmp , $reg )) {
2018-09-17 21:02:07 +02:00
$offsetforchartofaccount += $reg [ 1 ];
}
2019-11-13 19:35:39 +01:00
$offsetforchartofaccount += ( $conf -> entity * 100000000 );
2018-09-17 21:02:07 +02:00
2018-09-18 11:49:35 +02:00
$result = run_sql ( $sqlfile , 1 , $conf -> entity , 1 , '' , 'default' , 32768 , 0 , $offsetforchartofaccount );
2018-09-17 21:02:07 +02:00
2021-02-22 21:36:42 +01:00
if ( $result > 0 ) {
2019-11-05 10:01:21 +01:00
setEventMessages ( $langs -> trans ( " ChartLoaded " ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2018-09-17 21:02:07 +02:00
setEventMessages ( $langs -> trans ( " ErrorDuringChartLoad " ), null , 'warnings' );
}
2017-10-23 20:42:09 +02:00
}
2017-08-31 18:29:57 +02:00
2020-10-31 14:32:18 +01:00
if ( ! dolibarr_set_const ( $db , 'CHARTOFACCOUNTS' , $chartofaccounts , 'chaine' , 0 , '' , $conf -> entity )) {
$error ++ ;
}
} else {
$error ++ ;
}
}
2021-04-13 09:46:50 +02:00
if ( $action == 'disable' && $permissiontoadd ) {
2020-10-31 14:32:18 +01:00
if ( $accounting -> fetch ( $id )) {
$mode = GETPOST ( 'mode' , 'int' );
$result = $accounting -> accountDeactivate ( $id , $mode );
}
$action = 'update' ;
if ( $result < 0 ) {
setEventMessages ( $accounting -> error , $accounting -> errors , 'errors' );
}
2021-04-13 09:46:50 +02:00
} elseif ( $action == 'enable' && $permissiontoadd ) {
2020-10-31 14:32:18 +01:00
if ( $accounting -> fetch ( $id )) {
$mode = GETPOST ( 'mode' , 'int' );
2021-06-04 11:35:12 +02:00
$result = $accounting -> accountActivate ( $id , $mode );
2020-10-31 14:32:18 +01:00
}
$action = 'update' ;
if ( $result < 0 ) {
setEventMessages ( $accounting -> error , $accounting -> errors , 'errors' );
}
}
2014-08-27 07:03:42 +02:00
}
2014-10-31 07:37:59 +01:00
2014-08-27 07:03:42 +02:00
/*
* View
*/
2017-05-29 11:17:33 +02:00
2019-11-13 19:35:39 +01:00
$form = new Form ( $db );
2020-01-21 21:36:40 +01:00
$formaccounting = new FormAccounting ( $db );
2016-05-12 21:32:24 +02:00
2014-08-27 07:03:42 +02:00
llxHeader ( '' , $langs -> trans ( " ListAccounts " ));
2016-05-12 21:32:24 +02:00
if ( $action == 'delete' ) {
2019-11-13 19:35:39 +01:00
$formconfirm = $html -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $id , $langs -> trans ( 'DeleteAccount' ), $langs -> trans ( 'ConfirmDeleteAccount' ), 'confirm_delete' , '' , 0 , 1 );
2016-05-12 21:32:24 +02:00
print $formconfirm ;
}
2014-08-27 07:03:42 +02:00
$pcgver = $conf -> global -> CHARTOFACCOUNTS ;
2020-03-16 06:41:14 +01:00
$sql = " SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent , aa.label, aa.labelshort, aa.reconcilable, aa.active, " ;
2016-02-27 16:21:40 +01:00
$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2 " ;
2019-11-13 19:35:39 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_account as aa " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = " . $conf -> entity ;
2021-02-22 21:36:42 +01:00
if ( $db -> type == 'pgsql' ) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = " . $conf -> entity ;
} else {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = " . $conf -> entity ;
}
2021-03-30 17:53:25 +02:00
$sql .= " WHERE asy.rowid = " . (( int ) $pcgver );
2018-04-09 11:31:24 +02:00
//print $sql;
2020-01-21 22:20:32 +01:00
if ( strlen ( trim ( $search_account ))) {
$lengthpaddingaccount = 0 ;
if ( $conf -> global -> ACCOUNTING_LENGTH_GACCOUNT || $conf -> global -> ACCOUNTING_LENGTH_AACCOUNT ) {
$lengthpaddingaccount = max ( $conf -> global -> ACCOUNTING_LENGTH_GACCOUNT , $conf -> global -> ACCOUNTING_LENGTH_AACCOUNT );
}
$search_account_tmp = $search_account ;
$weremovedsomezero = 0 ;
if ( strlen ( $search_account_tmp ) <= $lengthpaddingaccount ) {
2020-01-30 01:48:28 +01:00
for ( $i = 0 ; $i < $lengthpaddingaccount ; $i ++ ) {
2020-01-21 22:20:32 +01:00
if ( preg_match ( '/0$/' , $search_account_tmp )) {
$weremovedsomezero ++ ;
$search_account_tmp = preg_replace ( '/0$/' , '' , $search_account_tmp );
}
}
}
2020-01-21 22:26:37 +01:00
2020-01-21 22:20:32 +01:00
//var_dump($search_account); exit;
if ( $search_account_tmp ) {
2020-01-21 22:26:37 +01:00
if ( $weremovedsomezero ) {
2020-01-21 22:26:37 +01:00
$search_account_tmp_clean = $search_account_tmp ;
$search_account_clean = $search_account ;
2020-01-21 22:26:37 +01:00
$startchar = '%' ;
2021-02-22 21:36:42 +01:00
if ( strpos ( $search_account_tmp , '^' ) === 0 ) {
2020-01-21 22:26:37 +01:00
$startchar = '' ;
$search_account_tmp_clean = preg_replace ( '/^\^/' , '' , $search_account_tmp );
$search_account_clean = preg_replace ( '/^\^/' , '' , $search_account );
}
2020-09-19 20:11:04 +02:00
$sql .= " AND (aa.account_number LIKE ' " . $db -> escape ( $startchar . $search_account_tmp_clean ) . " ' " ;
$sql .= " OR aa.account_number LIKE ' " . $db -> escape ( $startchar . $search_account_clean ) . " %') " ;
2021-02-22 21:36:42 +01:00
} else {
$sql .= natural_search ( " aa.account_number " , $search_account_tmp );
}
2020-01-21 22:20:32 +01:00
}
}
2021-02-22 21:36:42 +01:00
if ( strlen ( trim ( $search_label ))) {
$sql .= natural_search ( " aa.label " , $search_label );
}
if ( strlen ( trim ( $search_labelshort ))) {
$sql .= natural_search ( " aa.labelshort " , $search_labelshort );
}
if ( strlen ( trim ( $search_accountparent )) && $search_accountparent != '-1' ) {
$sql .= natural_search ( " aa.account_parent " , $search_accountparent , 2 );
}
if ( strlen ( trim ( $search_pcgtype ))) {
$sql .= natural_search ( " aa.pcg_type " , $search_pcgtype );
}
2014-08-27 07:03:42 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2021-04-13 10:18:23 +02:00
//print $sql;
2016-05-12 21:32:24 +02:00
// Count total nb of records
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2021-02-22 21:36:42 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2016-10-15 16:20:08 +02:00
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
2021-02-22 21:36:42 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2018-04-24 11:37:57 +02:00
$page = 0 ;
$offset = 0 ;
}
2017-08-31 18:29:57 +02:00
}
2016-05-12 21:32:24 +02:00
2021-04-03 10:12:05 +02:00
// List of mass actions available
if ( $user -> rights -> accounting -> chartofaccount ) {
$arrayofmassactions [ 'predelete' ] = '<span class="fa fa-trash paddingrightonly"></span>' . $langs -> trans ( " Delete " );
}
if ( in_array ( $massaction , array ( 'presend' , 'predelete' , 'closed' ))) {
$arrayofmassactions = array ();
}
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2014-08-27 07:03:42 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2019-11-13 19:35:39 +01:00
dol_syslog ( 'accountancy/admin/account.php:: $sql=' . $sql );
2016-10-15 16:20:08 +02:00
$resql = $db -> query ( $sql );
2014-08-27 07:03:42 +02:00
2021-02-22 21:36:42 +01:00
if ( $resql ) {
2016-10-15 16:20:08 +02:00
$num = $db -> num_rows ( $resql );
2017-01-31 06:08:40 +01:00
2020-05-23 10:18:41 +02:00
$param = '' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $search_account ) {
$param .= '&search_account=' . urlencode ( $search_account );
}
if ( $search_label ) {
$param .= '&search_label=' . urlencode ( $search_label );
}
if ( $search_labelshort ) {
$param .= '&search_labelshort=' . urlencode ( $search_labelshort );
}
if ( $search_accountparent > 0 || $search_accountparent == '0' ) {
$param .= '&search_accountparent=' . urlencode ( $search_accountparent );
}
if ( $search_pcgtype ) {
$param .= '&search_pcgtype=' . urlencode ( $search_pcgtype );
}
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-10-31 14:32:18 +01:00
print ' <!-- Add javascript to reload page when we click " Change plan " -->
2019-10-06 21:13:55 +02:00
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
2020-02-26 15:41:46 +01:00
$ ( " #change_chart " ) . on ( " click " , function ( e ) {
console . log ( " chartofaccounts seleted = " + $ ( " #chartofaccounts " ) . val ());
// reload page
window . location . href = " '. $_SERVER["PHP_SELF"] .'?valid_change_chart=1&chartofaccounts= " + $ ( " #chartofaccounts " ) . val ();
2019-10-06 21:13:55 +02:00
});
});
</ script > ' ;
2020-10-31 14:32:18 +01:00
}
2017-01-31 06:08:40 +01:00
2022-06-12 07:33:28 +02:00
$newcardbutton = '' ;
2019-11-13 19:35:39 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-02-22 21:36:42 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-05-29 11:17:33 +02:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2017-08-31 18:29:57 +02:00
2020-10-31 14:32:18 +01:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( " New " ), $langs -> trans ( " Addanaccount " ), 'fa fa-plus-circle' , './card.php?action=create' );
2021-04-03 10:12:05 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2021-12-18 23:51:14 +01:00
print_barre_liste ( $langs -> trans ( 'ListAccounts' ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'accounting_account' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2017-08-31 18:29:57 +02:00
2016-11-16 18:00:37 +01:00
// Box to select active chart of account
2020-10-31 14:32:18 +01:00
print $langs -> trans ( " Selectchartofaccounts " ) . " : " ;
2021-03-10 10:45:01 +01:00
print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">' ;
2020-10-31 14:32:18 +01:00
$sql = " SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_system as a " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON a.fk_country = c.rowid AND c.active = 1 " ;
$sql .= " WHERE a.active = 1 " ;
dol_syslog ( 'accountancy/admin/account.php $sql=' . $sql );
2021-03-31 19:50:43 +02:00
2020-10-31 14:32:18 +01:00
$resqlchart = $db -> query ( $sql );
if ( $resqlchart ) {
$numbis = $db -> num_rows ( $resqlchart );
$i = 0 ;
2021-03-10 10:45:01 +01:00
print '<option value="-1"> </option>' ;
2020-10-31 14:32:18 +01:00
while ( $i < $numbis ) {
$obj = $db -> fetch_object ( $resqlchart );
print '<option value="' . $obj -> rowid . '"' ;
print ( $pcgver == $obj -> rowid ) ? ' selected' : '' ;
print '>' . $obj -> pcg_version . ' - ' . $obj -> label . ' - (' . $obj -> country_code . ')</option>' ;
$i ++ ;
}
2021-02-22 21:36:42 +01:00
} else {
dol_print_error ( $db );
}
2020-10-31 14:32:18 +01:00
print " </select> " ;
print ajax_combobox ( " chartofaccounts " );
2021-08-24 17:04:17 +02:00
print '<input type="' . ( empty ( $conf -> use_javascript_ajax ) ? 'submit' : 'button' ) . '" class="button button-edit" name="change_chart" id="change_chart" value="' . dol_escape_htmltag ( $langs -> trans ( " ChangeAndLoad " )) . '">' ;
2020-10-31 14:32:18 +01:00
print '<br>' ;
2017-03-03 17:59:49 +01:00
print '<br>' ;
2017-08-31 18:29:57 +02:00
2019-11-13 19:35:39 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
2020-10-31 14:32:18 +01:00
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
2021-04-03 10:12:05 +02:00
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2017-08-31 18:29:57 +02:00
2020-10-31 14:32:18 +01:00
$moreforfilter = '' ;
2019-10-06 21:11:29 +02:00
2021-12-18 15:46:08 +01:00
$accountstatic = new AccountingAccount ( $db );
$accountparent = new AccountingAccount ( $db );
$totalarray = array ();
$totalarray [ 'nbfield' ] = 0 ;
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-01-31 06:08:40 +01:00
// Line for search fields
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.account_number' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="' . $search_account . '"></td>' ;
}
if ( ! empty ( $arrayfields [ 'aa.label' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="' . $search_label . '"></td>' ;
}
if ( ! empty ( $arrayfields [ 'aa.labelshort' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="' . $search_labelshort . '"></td>' ;
}
2020-01-21 21:36:40 +01:00
if ( ! empty ( $arrayfields [ 'aa.account_parent' ][ 'checked' ])) {
print '<td class="liste_titre">' ;
print $formaccounting -> select_account ( $search_accountparent , 'search_accountparent' , 2 );
print '</td>' ;
}
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.pcg_type' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat width100" name="search_pcgtype" value="' . $search_pcgtype . '"></td>' ;
}
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 2 ) {
if ( ! empty ( $arrayfields [ 'aa.reconcilable' ][ 'checked' ])) {
print '<td class="liste_titre"> </td>' ;
}
}
if ( ! empty ( $arrayfields [ 'aa.active' ][ 'checked' ])) {
print '<td class="liste_titre"> </td>' ;
}
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2021-04-06 19:44:31 +02:00
$searchpicto = $form -> showFilterButtons ();
2017-01-31 06:08:40 +01:00
print $searchpicto ;
2014-08-27 07:03:42 +02:00
print '</td>' ;
print '</tr>' ;
2020-10-31 14:32:18 +01:00
print '<tr class="liste_titre">' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.account_number' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.account_number' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " aa.account_number " , " " , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'aa.label' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.label' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " aa.label " , " " , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'aa.labelshort' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.labelshort' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " aa.labelshort " , " " , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'aa.account_parent' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.account_parent' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " aa.account_parent " , " " , $param , '' , $sortfield , $sortorder , 'left ' );
}
if ( ! empty ( $arrayfields [ 'aa.pcg_type' ][ 'checked' ])) {
2021-04-13 10:18:23 +02:00
print_liste_field_titre ( $arrayfields [ 'aa.pcg_type' ][ 'label' ], $_SERVER [ " PHP_SELF " ], 'aa.pcg_type,aa.account_number' , '' , $param , '' , $sortfield , $sortorder , '' , $arrayfields [ 'aa.pcg_type' ][ 'help' ], 1 );
2021-02-22 21:36:42 +01:00
}
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 2 ) {
if ( ! empty ( $arrayfields [ 'aa.reconcilable' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.reconcilable' ][ 'label' ], $_SERVER [ " PHP_SELF " ], 'aa.reconcilable' , '' , $param , '' , $sortfield , $sortorder );
}
}
if ( ! empty ( $arrayfields [ 'aa.active' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'aa.active' ][ 'label' ], $_SERVER [ " PHP_SELF " ], 'aa.active' , '' , $param , '' , $sortfield , $sortorder );
}
2021-04-06 09:42:05 +02:00
print_liste_field_titre ( $selectedfields , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' );
2017-04-01 12:46:47 +02:00
print " </tr> \n " ;
2019-11-13 19:35:39 +01:00
$i = 0 ;
2021-02-22 21:36:42 +01:00
while ( $i < min ( $num , $limit )) {
2014-08-27 07:03:42 +02:00
$obj = $db -> fetch_object ( $resql );
2016-11-16 18:00:37 +01:00
2016-02-01 14:50:25 +01:00
$accountstatic -> id = $obj -> rowid ;
$accountstatic -> label = $obj -> label ;
$accountstatic -> account_number = $obj -> account_number ;
2017-08-31 18:29:57 +02:00
2017-04-01 12:46:47 +02:00
print '<tr class="oddeven">' ;
2017-01-31 06:08:40 +01:00
// Account number
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.account_number' ][ 'checked' ])) {
2017-01-31 06:08:40 +01:00
print " <td> " ;
2020-09-08 04:44:04 +02:00
print $accountstatic -> getNomUrl ( 1 , 0 , 0 , '' , 0 , 1 , 0 , 'accountcard' );
2017-01-31 06:08:40 +01:00
print " </td> \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2016-02-27 16:21:40 +01:00
}
2017-01-31 06:08:40 +01:00
// Account label
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.label' ][ 'checked' ])) {
2017-01-31 06:08:40 +01:00
print " <td> " ;
print $obj -> label ;
print " </td> \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2016-02-27 16:21:40 +01:00
}
2017-01-31 06:08:40 +01:00
2020-01-03 22:05:49 +01:00
// Account label to show (label short)
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.labelshort' ][ 'checked' ])) {
2020-01-03 22:05:49 +01:00
print " <td> " ;
print $obj -> labelshort ;
print " </td> \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-01-03 22:05:49 +01:00
}
2017-01-31 06:08:40 +01:00
// Account parent
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.account_parent' ][ 'checked' ])) {
2020-10-09 19:34:57 +02:00
// Note: obj->account_parent is a foreign key to a rowid. It is field in child table and obj->rowid2 is same, but in parent table.
// So for orphans, obj->account_parent is set but not obj->rowid2
2021-02-22 21:36:42 +01:00
if ( ! empty ( $obj -> account_parent ) && ! empty ( $obj -> rowid2 )) {
2020-10-09 19:34:57 +02:00
print " <td> " ;
print '<!-- obj->account_parent = ' . $obj -> account_parent . ' obj->rowid2 = ' . $obj -> rowid2 . ' -->' ;
2017-01-31 06:08:40 +01:00
$accountparent -> id = $obj -> rowid2 ;
$accountparent -> label = $obj -> label2 ;
2020-10-31 14:32:18 +01:00
$accountparent -> account_number = $obj -> account_number2 ; // Sotre an account number for output
2017-01-31 06:08:40 +01:00
print $accountparent -> getNomUrl ( 1 );
print " </td> \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-09 19:34:57 +02:00
print '<td>' ;
if ( ! empty ( $obj -> account_parent )) {
print '<!-- Bad value for obj->account_parent = ' . $obj -> account_parent . ': is a rowid that does not exists -->' ;
}
print '</td>' ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-01-31 06:08:40 +01:00
}
2014-08-27 07:03:42 +02:00
}
2017-01-31 06:08:40 +01:00
// Chart of accounts type
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.pcg_type' ][ 'checked' ])) {
2017-01-31 06:08:40 +01:00
print " <td> " ;
print $obj -> pcg_type ;
print " </td> \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-01-31 06:08:40 +01:00
}
2020-03-15 07:49:24 +01:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 2 ) {
// Activated or not reconciliation on accounting account
2020-03-16 06:41:14 +01:00
if ( ! empty ( $arrayfields [ 'aa.reconcilable' ][ 'checked' ])) {
2020-03-15 07:49:24 +01:00
print '<td class="center">' ;
2020-03-16 06:41:14 +01:00
if ( empty ( $obj -> reconcilable )) {
2021-03-19 12:44:59 +01:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $obj -> rowid . '&action=enable&mode=1&token=' . newToken () . '">' ;
2020-03-15 07:49:24 +01:00
print img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' );
print '</a>' ;
} else {
2021-03-19 12:44:59 +01:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $obj -> rowid . '&action=disable&mode=1&token=' . newToken () . '">' ;
2020-03-15 07:49:24 +01:00
print img_picto ( $langs -> trans ( " Activated " ), 'switch_on' );
print '</a>' ;
}
print '</td>' ;
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
}
}
2017-01-31 06:08:40 +01:00
// Activated or not
2021-02-22 21:36:42 +01:00
if ( ! empty ( $arrayfields [ 'aa.active' ][ 'checked' ])) {
2020-03-15 07:49:24 +01:00
print '<td class="center">' ;
2017-01-31 06:08:40 +01:00
if ( empty ( $obj -> active )) {
2021-03-19 12:44:59 +01:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $obj -> rowid . '&action=enable&mode=0&token=' . newToken () . '">' ;
2017-01-31 06:08:40 +01:00
print img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' );
print '</a>' ;
} else {
2021-03-19 12:44:59 +01:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $obj -> rowid . '&action=disable&mode=0&token=' . newToken () . '">' ;
2017-01-31 06:08:40 +01:00
print img_picto ( $langs -> trans ( " Activated " ), 'switch_on' );
print '</a>' ;
}
print '</td>' ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-01-31 06:08:40 +01:00
}
2014-10-31 07:37:59 +01:00
// Action
2021-04-07 01:09:23 +02:00
print '<td class="center nowraponall">' ;
2017-03-03 17:59:49 +01:00
if ( $user -> rights -> accounting -> chartofaccount ) {
2020-10-10 10:22:58 +02:00
print '<a class="editfielda" href="./card.php?action=update&token=' . newToken () . '&id=' . $obj -> rowid . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?' . $param ) . '">' ;
2014-08-27 07:03:42 +02:00
print img_edit ();
2014-10-31 07:37:59 +01:00
print '</a>' ;
print ' ' ;
2020-10-10 10:22:58 +02:00
print '<a class="marginleftonly" href="./card.php?action=delete&token=' . newToken () . '&id=' . $obj -> rowid . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?' . $param ) . '">' ;
2014-08-27 07:03:42 +02:00
print img_delete ();
print '</a>' ;
2021-04-03 10:12:05 +02:00
print ' ' ;
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0 ;
if ( in_array ( $obj -> rowid , $arrayofselected )) {
$selected = 1 ;
}
2021-04-07 01:09:23 +02:00
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2021-04-03 10:12:05 +02:00
}
2014-08-27 07:03:42 +02:00
}
2019-11-13 19:35:39 +01:00
print '</td>' . " \n " ;
2021-02-22 21:36:42 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-08-31 18:29:57 +02:00
2014-08-27 07:03:42 +02:00
print " </tr> \n " ;
2016-11-16 18:00:37 +01:00
$i ++ ;
2014-08-27 07:03:42 +02:00
}
2017-08-31 18:29:57 +02:00
2021-03-26 12:27:23 +01:00
if ( $num == 0 ) {
2021-12-18 15:46:08 +01:00
$colspan = 1 ;
foreach ( $arrayfields as $key => $val ) {
if ( ! empty ( $val [ 'checked' ])) {
$colspan ++ ;
}
}
print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2021-03-26 12:27:23 +01:00
}
2014-08-27 07:03:42 +02:00
print " </table> " ;
2017-01-31 06:08:40 +01:00
print " </div> " ;
2014-08-27 07:03:42 +02:00
print '</form>' ;
} else {
dol_print_error ( $db );
}
2018-07-28 14:02:33 +02:00
// End of page
2014-08-27 07:03:42 +02:00
llxFooter ();
2014-11-23 09:58:19 +01:00
$db -> close ();