dolibarr 23.0.3
account.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2016-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array('accountancy', 'admin', 'bills', 'compta', 'salaries'));
44
45$action = GETPOST('action', 'aZ09');
46$cancel = GETPOST('cancel', 'alpha');
48$rowid = GETPOSTINT('rowid');
49$massaction = GETPOST('massaction', 'aZ09');
50$optioncss = GETPOST('optioncss', 'alpha');
51$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search
52$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
53
54$search_account = GETPOST('search_account', 'alpha');
55$search_label = GETPOST('search_label', 'alpha');
56$search_labelshort = GETPOST('search_labelshort', 'alpha');
57$search_accountparent = GETPOST('search_accountparent', 'alpha');
58$search_pcgtype = GETPOST('search_pcgtype', 'alpha');
59$search_import_key = GETPOST('search_import_key', 'alpha');
60$search_reconcilable = GETPOST("search_reconcilable", 'int');
61$search_centralized = GETPOST("search_centralized", 'int');
62$search_active = GETPOST("search_active", 'int');
63$toselect = GETPOST('toselect', 'array:int');
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$confirm = GETPOST('confirm', 'alpha');
66
67$chartofaccounts = GETPOSTINT('chartofaccounts');
68
69$permissiontoadd = $user->hasRight('accounting', 'chartofaccount');
70$permissiontodelete = $user->hasRight('accounting', 'chartofaccount');
71
72// Security check
73if ($user->socid > 0) {
75}
76if (!$permissiontoadd) {
78}
79// now $permissiontoadd or $user->hasRight('accounting', 'chartofaccount') are always equal to 1
80
81// Load variable for pagination
82$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
83$sortfield = GETPOST('sortfield', 'aZ09comma');
84$sortorder = GETPOST('sortorder', 'aZ09comma');
85$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
86if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
87 // If $page is not defined, or '' or -1 or if we click on clear filters
88 $page = 0;
89}
90$offset = $limit * $page;
91$pageprev = $page - 1;
92$pagenext = $page + 1;
93if (!$sortfield) {
94 $sortfield = "aa.account_number";
95}
96if (!$sortorder) {
97 $sortorder = "ASC";
98}
99
101
102$arrayfields = array(
103 'aa.account_number' => array('label' => "AccountNumber", 'checked' => '1', 'csslist' => 'maxwidth50'),
104 'aa.label' => array('label' => "Label", 'checked' => '1'),
105 'aa.labelshort' => array('label' => "ShortLabel", 'checked' => '1'),
106 'aa.account_parent' => array('label' => "Accountparent", 'checked' => '1'),
107 'aa.pcg_type' => array('label' => "Pcgtype", 'checked' => '1', 'help' => 'PcgtypeDesc'),
108 'categories' => array('label' => "AccountingCategories", 'checked' => '-1', 'help' => 'AccountingCategoriesDesc'),
109 'aa.reconcilable' => array('label' => "Reconcilable", 'checked' => '1'),
110 'aa.centralized' => array('label' => "Centralized", 'checked' => '1', 'help' => 'CentralizedAccountHelp'),
111 'aa.import_key' => array('label' => "ImportId", 'checked' => '-1', 'help' => ''),
112 'aa.active' => array('label' => "Activated", 'checked' => '1')
113);
114
115if (!getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
116 unset($arrayfields['categories']);
117 unset($arrayfields['aa.reconcilable']);
118}
119
120$accounting = new AccountingAccount($db);
121
122// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
123$hookmanager->initHooks(array('accountancyadminaccount'));
124
125
126/*
127 * Actions
128 */
129
130if (GETPOST('cancel', 'alpha')) {
131 $action = 'list';
132 $massaction = '';
133}
134if (!GETPOST('confirmmassaction', 'alpha')) {
135 $massaction = '';
136}
137
138$parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
139$reshook = $hookmanager->executeHooks('doActions', $parameters, $accounting, $action); // Note that $action and $object may have been monowraponalldified by some hooks
140if ($reshook < 0) {
141 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
142}
143
144if (empty($reshook)) {
145 if (!empty($cancel)) {
146 $action = '';
147 }
148
149 $objectclass = 'AccountingAccount';
150 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
151 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
152
153 if ($action == "delete") {
154 $action = "";
155 }
156 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
157
158 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
159 $search_account = "";
160 $search_label = "";
161 $search_labelshort = "";
162 $search_accountparent = "";
163 $search_pcgtype = "";
164 $search_import_key = "";
165 $search_reconcilable = "";
166 $search_centralized = "";
167 $search_active = "";
168 $search_array_options = array();
169 }
170 if ((GETPOSTINT('valid_change_chart') && GETPOSTINT('chartofaccounts') > 0) // explicit click on button 'Change and load' with js on
171 || (GETPOSTINT('chartofaccounts') > 0 && GETPOSTINT('chartofaccounts') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified
172 $error = 0;
173
174 if ($chartofaccounts > 0 /* && $permissiontoadd */) {
175 $country_code = '';
176 // Get language code for this $chartofaccounts
177 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
178 $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
179 $resql = $db->query($sql);
180 if ($resql) {
181 $obj = $db->fetch_object($resql);
182 if ($obj) {
183 $country_code = $obj->code;
184 }
185 } else {
186 dol_print_error($db);
187 }
188
189 // Try to load sql file
190 if ($country_code) {
191 $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
192
193 $offsetforchartofaccount = 0;
194 // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
195 // 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.
196 // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
197 $tmp = file_get_contents($sqlfile);
198 $reg = array();
199 if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
200 $offsetforchartofaccount += $reg[1];
201 }
202 $offsetforchartofaccount += ($conf->entity * 100000000);
203
204 $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
205
206 if ($result > 0) {
207 setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
208 } else {
209 setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
210 }
211 }
212
213 if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
214 $error++;
215 }
216 } else {
217 $error++;
218 }
219 }
220
221 if ($action == 'disable' /* && $permissiontoadd */) {
222 if ($accounting->fetch($id)) {
223 $mode = GETPOSTINT('mode');
224 $result = $accounting->accountDeactivate($id, $mode);
225 if ($result < 0) {
226 setEventMessages($accounting->error, $accounting->errors, 'errors');
227 }
228 }
229
230 $action = 'update';
231 } elseif ($action == 'enable' /* && $permissiontoadd */) {
232 if ($accounting->fetch($id)) {
233 $mode = GETPOSTINT('mode');
234 $result = $accounting->accountActivate($id, $mode);
235 if ($result < 0) {
236 setEventMessages($accounting->error, $accounting->errors, 'errors');
237 }
238 }
239 $action = 'update';
240 }
241}
242
243
244/*
245 * View
246 */
247$form = new Form($db);
248$formaccounting = new FormAccounting($db);
249
250$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
251
252llxHeader('', $langs->trans("ListAccounts"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_account');
253
254if ($action == 'delete') {
255 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
256 print $formconfirm;
257}
258
259$pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
260
261$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent, aa.label, aa.labelshort, aa.fk_accounting_category,";
262$sql .= " aa.reconcilable, aa.centralized, aa.active, aa.import_key,";
263$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
264
265// Add fields from hooks
266$parameters = array();
267$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
268$sql .= $hookmanager->resPrint;
269$sql = preg_replace('/,\s*$/', '', $sql);
270
271$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
272$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity);
273$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity);
274
275// Add table from hooks
276$parameters = array();
277$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
278$sql .= $hookmanager->resPrint;
279
280$sql .= " WHERE asy.rowid = ".((int) $pcgver);
281
282if (strlen(trim($search_account))) {
283 $lengthpaddingaccount = 0;
284 if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) {
285 $lengthpaddingaccount = max(getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT'), getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT'));
286 }
287 $search_account_tmp = $search_account;
288 $weremovedsomezero = 0;
289 if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
290 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
291 if (preg_match('/0$/', $search_account_tmp)) {
292 $weremovedsomezero++;
293 $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
294 }
295 }
296 }
297
298 //var_dump($search_account); exit;
299 if ($search_account_tmp) {
300 if ($weremovedsomezero) {
301 $search_account_tmp_clean = $search_account_tmp;
302 $search_account_clean = $search_account;
303 $startchar = '%';
304 if (substr($search_account_tmp, 0, 1) === '^') {
305 $startchar = '';
306 $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
307 $search_account_clean = preg_replace('/^\^/', '', $search_account);
308 }
309 $sql .= " AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean)."'";
310 $sql .= " OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean)."%')";
311 } else {
312 $sql .= natural_search("aa.account_number", $search_account_tmp);
313 }
314 }
315}
316if (strlen(trim($search_label))) {
317 $sql .= natural_search("aa.label", $search_label);
318}
319if (strlen(trim($search_labelshort))) {
320 $sql .= natural_search("aa.labelshort", $search_labelshort);
321}
322if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') {
323 $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
324}
325if (strlen(trim($search_pcgtype))) {
326 $sql .= natural_search("aa.pcg_type", $search_pcgtype);
327}
328if ($search_reconcilable != '' && $search_reconcilable != '-1') {
329 $sql .= " AND aa.reconcilable = ".((int) $search_reconcilable);
330}
331if ($search_centralized != '' && $search_centralized != '-1') {
332 $sql .= " AND aa.centralized = ".((int) $search_centralized);
333}
334if ($search_active != '' && $search_active != '-1') {
335 $sql .= " AND aa.active = ".((int) $search_active);
336}
337if (strlen(trim($search_import_key))) {
338 $sql .= natural_search("aa.import_key", $search_import_key);
339}
340
341// Add where from hooks
342$parameters = array();
343$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
344$sql .= $hookmanager->resPrint;
345
346$sql .= $db->order($sortfield, $sortorder);
347//print $sql;
348
349// Count total nb of records
350$nbtotalofrecords = '';
351if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
352 $resql = $db->query($sql);
353 $nbtotalofrecords = $db->num_rows($resql);
354 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
355 $page = 0;
356 $offset = 0;
357 }
358}
359
360$sql .= $db->plimit($limit + 1, $offset);
361
362dol_syslog("accountancy/admin/account.php:: sql=".$sql);
363$resql = $db->query($sql);
364
365if ($resql) {
366 $num = $db->num_rows($resql);
367
368 $arrayofselected = is_array($toselect) ? $toselect : array();
369
370 $param = '';
371 // if null contextpage is forced to 'accountingaccountlist' so never empty
372 if (/* !empty($contextpage) && */$contextpage != $_SERVER["PHP_SELF"]) {
373 $param .= '&contextpage='.urlencode($contextpage);
374 }
375 if ($limit > 0 && $limit != $conf->liste_limit) {
376 $param .= '&limit='.((int) $limit);
377 }
378 if ($search_account) {
379 $param .= '&search_account='.urlencode($search_account);
380 }
381 if ($search_label) {
382 $param .= '&search_label='.urlencode($search_label);
383 }
384 if ($search_labelshort) {
385 $param .= '&search_labelshort='.urlencode($search_labelshort);
386 }
387 if ($search_accountparent > 0 || $search_accountparent == '0') {
388 $param .= '&search_accountparent='.urlencode($search_accountparent);
389 }
390 if ($search_pcgtype) {
391 $param .= '&search_pcgtype='.urlencode($search_pcgtype);
392 }
393 if ($search_import_key) {
394 $param .= '&search_import_key='.urlencode($search_import_key);
395 }
396 if ($optioncss != '') {
397 $param .= '&optioncss='.urlencode($optioncss);
398 }
399
400 // Add $param from hooks
401 $parameters = array();
402 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
403 $param .= $hookmanager->resPrint;
404
405 if (!empty($conf->use_javascript_ajax)) {
406 print '<!-- Add javascript to reload page when we click "Change plan" -->
407 <script type="text/javascript">
408 $(document).ready(function () {
409 $("#change_chart").on("click", function (e) {
410 console.log("chartofaccounts selected = "+$("#chartofaccounts").val());
411 // reload page
412 window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
413 });
414 });
415 </script>';
416 }
417
418 // List of mass actions available
419 $arrayofmassactions = array();
420 // if ($permissiontoadd) { // test is always true
421 $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
422 // }
423 if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
424 $arrayofmassactions = array();
425 }
426
427 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
428
429 $newcardbutton = '';
430 $newcardbutton = dolGetButtonTitle($langs->trans('Addanaccount'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/accountancy/admin/card.php?action=create', '', $permissiontoadd);
431
432
433 print '<form method="POST" id="searchFormList" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
434 if ($optioncss != '') {
435 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
436 }
437 print '<input type="hidden" name="token" value="'.newToken().'">';
438 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
439 print '<input type="hidden" name="action" value="list">';
440 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
441 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
442 print '<input type="hidden" name="page" value="'.$page.'">';
443 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
444 print '<input type="hidden" name="page_y" value="">';
445
446 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
447 print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1);
448
449 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
450
451 // Box to select active chart of account
452 print $langs->trans("Selectchartofaccounts")." : ";
453 print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
454 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
455 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
456 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
457 $sql .= " WHERE a.active = 1";
458 $sql .= " ORDER BY c.code, a.pcg_version";
459
460 dol_syslog("accountancy/admin/account.php sql=".$sql);
461
462 $resqlchart = $db->query($sql);
463 if ($resqlchart) {
464 $numbis = $db->num_rows($resqlchart);
465 $i = 0;
466 print '<option value="-1">&nbsp;</option>';
467 while ($i < $numbis) {
468 $obj = $db->fetch_object($resqlchart);
469 if ($obj) {
470 $labeltoshow = $obj->country_code.' - '.$obj->pcg_version.' - '.$obj->label;
471 $htmltoshow = picto_from_langcode($obj->country_code).' '.$obj->country_code.' - '.$obj->pcg_version.' <span class="opacitymedium">- '.$obj->label.'</span>';
472 print '<option value="'.$obj->rowid.'" data-html="'.dolPrintHTMLForAttribute($htmltoshow).'"';
473 print ($pcgver == $obj->rowid) ? ' selected' : '';
474 print '>'.$labeltoshow.'</option>';
475 }
476 $i++;
477 }
478 } else {
479 dol_print_error($db);
480 }
481 print "</select>";
482 print ajax_combobox("chartofaccounts");
483 print '<input type="'.(empty($conf->use_javascript_ajax) ? 'submit' : 'button').'" class="button button-edit small" name="change_chart" id="change_chart" value="'.dol_escape_htmltag($langs->trans("ChangeAndLoad")).'">';
484
485 print '<br>';
486
487 $parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
488 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $accounting, $action); // Note that $action and $object may have been modified by hook
489 print $hookmanager->resPrint;
490
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
493 print $hookmanager->resPrint;
494
495 print '<br>';
496
497 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
498 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
499 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
500 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
501
502 $accountstatic = new AccountingAccount($db);
503 $accountparent = new AccountingAccount($db);
504 $totalarray = array();
505 $totalarray['nbfield'] = 0;
506
507 $moreforfilter = '';
508 // if ($moreforfilter) {
509 // print '<div class="liste_titre liste_titre_bydiv centpercent">';
510 // print $moreforfilter;
511 // print '</div>';
512 // }
513
514 print '<div class="div-table-responsive">';
515 // print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
516 print '<table class="tagtable liste">'."\n";
517
518 // Fields title search
519 // --------------------------------------------------------------------
520 print '<tr class="liste_titre_filter">';
521
522 // Action column
523 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
524 print '<td class="liste_titre center maxwidthsearch">';
525 $searchpicto = $form->showFilterButtons('left');
526 print $searchpicto;
527 print '</td>';
528 }
529 if (!empty($arrayfields['aa.account_number']['checked'])) {
530 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_account" value="'.$search_account.'"></td>';
531 }
532 if (!empty($arrayfields['aa.label']['checked'])) {
533 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_label" value="'.$search_label.'"></td>';
534 }
535 if (!empty($arrayfields['aa.labelshort']['checked'])) {
536 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.'"></td>';
537 }
538 if (!empty($arrayfields['aa.account_parent']['checked'])) {
539 print '<td class="liste_titre">';
540 print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2, array(), 0, 0, 'maxwidth150');
541 print '</td>';
542 }
543 // Predefined group
544 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
545 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
546 }
547 // Custom groups
548 if (!empty($arrayfields['categories']['checked'])) {
549 print '<td class="liste_titre"></td>';
550 }
551
552 // Fields from hook
553 $parameters = array('arrayfields' => $arrayfields);
554 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
555 print $hookmanager->resPrint;
556
557 // Import key
558 if (!empty($arrayfields['aa.import_key']['checked'])) {
559 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_import_key" value="'.$search_import_key.'"></td>';
560 }
561
562 // Reconcilable
563 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
564 print '<td class="liste_titre center">';
565 print $form->selectyesno('search_reconcilable', $search_reconcilable, 1, false, 1, 1, 'search_status onrightofpage width75');
566 print '</td>';
567 }
568
569 // Centralized
570 if (!empty($arrayfields['aa.centralized']['checked'])) {
571 print '<td class="liste_titre center">';
572 print $form->selectyesno('search_centralized', $search_centralized, 1, false, 1, 1, 'search_status onrightofpage width75');
573 print '</td>';
574 }
575
576 // Active
577 if (!empty($arrayfields['aa.active']['checked'])) {
578 print '<td class="liste_titre center parentonrightofpage">';
579 print $form->selectyesno('search_active', $search_active, 1, false, 1, 1, 'search_status onrightofpage width75');
580 print '</td>';
581 }
582
583 // Action column
584 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
585 print '<td class="liste_titre center maxwidthsearch">';
586 $searchpicto = $form->showFilterButtons();
587 print $searchpicto;
588 print '</td>';
589 }
590 print '</tr>'."\n";
591
592 $totalarray = array();
593 $totalarray['nbfield'] = 0;
594
595 // Fields title label
596 // --------------------------------------------------------------------
597 print '<tr class="liste_titre">';
598 // Action column
599 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
600 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');
601 $totalarray['nbfield']++;
602 }
603 if (!empty($arrayfields['aa.account_number']['checked'])) {
604 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
605 $totalarray['nbfield']++;
606 }
607 if (!empty($arrayfields['aa.label']['checked'])) {
608 print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
609 $totalarray['nbfield']++;
610 }
611 if (!empty($arrayfields['aa.labelshort']['checked'])) {
612 print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
613 $totalarray['nbfield']++;
614 }
615 if (!empty($arrayfields['aa.account_parent']['checked'])) {
616 print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
617 $totalarray['nbfield']++;
618 }
619 // Main group
620 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
621 print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type,aa.account_number', '', $param, '', $sortfield, $sortorder, 'right ', $arrayfields['aa.pcg_type']['help'].'::-1', 1);
622 $totalarray['nbfield']++;
623 }
624 // Number of custom groups
625 if (!empty($arrayfields['categories']['checked'])) {
626 print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'].'::-1', 1);
627 $totalarray['nbfield']++;
628 }
629
630 // Hook fields
631 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
632 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
633 print $hookmanager->resPrint;
634
635 if (!empty($arrayfields['aa.import_key']['checked'])) {
636 print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'].'::-1', 1);
637 $totalarray['nbfield']++;
638 }
639 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
640 print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder, 'center ');
641 $totalarray['nbfield']++;
642 }
643 if (!empty($arrayfields['aa.centralized']['checked'])) {
644 print_liste_field_titre($arrayfields['aa.centralized']['label'], $_SERVER["PHP_SELF"], 'aa.centralized', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.centralized']['help'].'::-1', 1);
645 $totalarray['nbfield']++;
646 }
647 if (!empty($arrayfields['aa.active']['checked'])) {
648 print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder, 'center ');
649 $totalarray['nbfield']++;
650 }
651 // Action column
652 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
653 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
654 $totalarray['nbfield']++;
655 }
656 print "</tr>\n";
657
658 // Loop on record
659 // --------------------------------------------------------------------
660 $i = 0;
661 while ($i < min($num, $limit)) {
662 $obj = $db->fetch_object($resql);
663
664 $accountstatic->id = $obj->rowid;
665 $accountstatic->label = $obj->label;
666 $accountstatic->account_number = $obj->account_number;
667
668 print '<tr class="oddeven">';
669
670 // Action column
671 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
672 print '<td class="center nowraponall">';
673 // if ($permissiontoadd) { // test is always true
674 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
675 print img_edit();
676 print '</a>';
677 print '&nbsp;';
678 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
679 print img_delete();
680 print '</a>';
681 print '&nbsp;';
682 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
683 $selected = 0;
684 if (in_array($obj->rowid, $arrayofselected)) {
685 $selected = 1;
686 }
687 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
688 }
689 // }
690 print '</td>'."\n";
691 if (!$i) {
692 $totalarray['nbfield']++;
693 }
694 }
695
696 // Account number
697 if (!empty($arrayfields['aa.account_number']['checked'])) {
698 print "<td>";
699 print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1, 0, 'accountcard');
700 print "</td>\n";
701 if (!$i) {
702 $totalarray['nbfield']++;
703 }
704 }
705
706 // Account label
707 if (!empty($arrayfields['aa.label']['checked'])) {
708 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">';
709 print dol_escape_htmltag($obj->label);
710 print "</td>\n";
711 if (!$i) {
712 $totalarray['nbfield']++;
713 }
714 }
715
716 // Account label to show (label short)
717 if (!empty($arrayfields['aa.labelshort']['checked'])) {
718 print "<td>";
719 print dol_escape_htmltag($obj->labelshort);
720 print "</td>\n";
721 if (!$i) {
722 $totalarray['nbfield']++;
723 }
724 }
725
726 // Account parent
727 if (!empty($arrayfields['aa.account_parent']['checked'])) {
728 // 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.
729 // So for orphans, obj->account_parent is set but not obj->rowid2
730 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
731 print "<td>";
732 print '<!-- obj->account_parent = '.$obj->account_parent.' obj->rowid2 = '.$obj->rowid2.' -->';
733 $accountparent->id = $obj->rowid2;
734 $accountparent->label = $obj->label2;
735 $accountparent->account_number = $obj->account_number2; // Store an account number for output
736 print $accountparent->getNomUrl(1);
737 print "</td>\n";
738 if (!$i) {
739 $totalarray['nbfield']++;
740 }
741 } else {
742 print '<td>';
743 if (!empty($obj->account_parent)) {
744 print '<!-- Bad value for obj->account_parent = '.$obj->account_parent.': is a rowid that does not exists -->';
745 }
746 print '</td>';
747 if (!$i) {
748 $totalarray['nbfield']++;
749 }
750 }
751 }
752
753 // Predefined group (deprecated)
754 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
755 print "<td>";
756 print dol_escape_htmltag($obj->pcg_type);
757 print "</td>\n";
758 if (!$i) {
759 $totalarray['nbfield']++;
760 }
761 }
762 // Custom accounts
763 if (!empty($arrayfields['categories']['checked'])) {
764 print '<td class="right">';
765 // TODO Get all custom groups labels the account is in
766 print dol_escape_htmltag($obj->fk_accounting_category);
767 print "</td>\n";
768 if (!$i) {
769 $totalarray['nbfield']++;
770 }
771 }
772
773 // Fields from hook
774 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
775 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
776 print $hookmanager->resPrint;
777
778 // Import id
779 if (!empty($arrayfields['aa.import_key']['checked'])) {
780 print "<td>";
781 print dol_escape_htmltag($obj->import_key);
782 print "</td>\n";
783 if (!$i) {
784 $totalarray['nbfield']++;
785 }
786 }
787
788 // Activated or not reconciliation on an accounting account
789 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
790 print '<td class="center">';
791 if (empty($obj->reconcilable)) {
792 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&page='.$page.'&mode=1&token='.newToken().'">';
793 print img_picto($langs->trans("Disabled"), 'switch_off');
794 print '</a>';
795 } else {
796 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&page='.$page.'&mode=1&token='.newToken().'">';
797 print img_picto($langs->trans("Activated"), 'switch_on');
798 print '</a>';
799 }
800 print '</td>';
801 if (!$i) {
802 $totalarray['nbfield']++;
803 }
804 }
805
806 // Centralized or not
807 if (!empty($arrayfields['aa.centralized']['checked'])) {
808 print '<td class="center">';
809 if (empty($obj->centralized)) {
810 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&page='.$page.'&mode=2&token='.newToken().'">';
811 print img_picto($langs->trans("Disabled"), 'switch_off');
812 print '</a>';
813 } else {
814 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&page='.$page.'&mode=2&token='.newToken().'">';
815 print img_picto($langs->trans("Activated"), 'switch_on');
816 print '</a>';
817 }
818 print '</td>';
819 if (!$i) {
820 $totalarray['nbfield']++;
821 }
822 }
823
824 // Activated or not
825 if (!empty($arrayfields['aa.active']['checked'])) {
826 print '<td class="center">';
827 if (empty($obj->active)) {
828 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&page='.$page.'&mode=0&token='.newToken().'">';
829 print img_picto($langs->trans("Disabled"), 'switch_off');
830 print '</a>';
831 } else {
832 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&page='.$page.'&mode=0&token='.newToken().'">';
833 print img_picto($langs->trans("Activated"), 'switch_on');
834 print '</a>';
835 }
836 print '</td>';
837 if (!$i) {
838 $totalarray['nbfield']++;
839 }
840 }
841
842 // Action column
843 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
844 print '<td class="center nowraponall">';
845 // if ($permissiontoadd) { // test is always true
846 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param.'&page='.$page).'">';
847 print img_edit();
848 print '</a>';
849 print '&nbsp;';
850 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param.'&page='.$page).'">';
851 print img_delete();
852 print '</a>';
853 print '&nbsp;';
854 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
855 $selected = 0;
856 if (in_array($obj->rowid, $arrayofselected)) {
857 $selected = 1;
858 }
859 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
860 }
861 // }
862 print '</td>'."\n";
863 if (!$i) {
864 $totalarray['nbfield']++;
865 }
866 }
867
868 print "</tr>\n";
869 $i++;
870 }
871
872 if ($num == 0) {
873 $colspan = 1;
874 foreach ($arrayfields as $key => $val) {
875 if (!empty($val['checked'])) {
876 $colspan++;
877 }
878 }
879 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
880 }
881
882 $db->free($resql);
883
884 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
885 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
886 print $hookmanager->resPrint;
887
888 print '</table>'."\n";
889 print '</div>'."\n";
890
891 print '</form>'."\n";
892} else {
893 dol_print_error($db);
894}
895
896// End of page
897llxFooter();
898$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition export.php:1216
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage accounting accounts.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.