dolibarr 22.0.5
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-2025 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 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';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array('accountancy', 'admin', 'bills', 'compta', 'salaries'));
45
46$action = GETPOST('action', 'aZ09');
47$cancel = GETPOST('cancel', 'alpha');
49$rowid = GETPOSTINT('rowid');
50$massaction = GETPOST('massaction', 'aZ09');
51$optioncss = GETPOST('optioncss', 'alpha');
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search
53$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
54
55$search_account = GETPOST('search_account', 'alpha');
56$search_label = GETPOST('search_label', 'alpha');
57$search_labelshort = GETPOST('search_labelshort', 'alpha');
58$search_accountparent = GETPOST('search_accountparent', 'alpha');
59$search_pcgtype = GETPOST('search_pcgtype', 'alpha');
60$search_import_key = GETPOST('search_import_key', 'alpha');
61$search_reconcilable = GETPOST("search_reconcilable", 'int');
62$search_centralized = GETPOST("search_centralized", 'int');
63$search_active = GETPOST("search_active", 'int');
64$toselect = GETPOST('toselect', 'array');
65$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
66$confirm = GETPOST('confirm', 'alpha');
67
68$chartofaccounts = GETPOSTINT('chartofaccounts');
69
70$permissiontoadd = $user->hasRight('accounting', 'chartofaccount');
71$permissiontodelete = $user->hasRight('accounting', 'chartofaccount');
72
73// Security check
74if ($user->socid > 0) {
76}
77if (!$permissiontoadd) {
79}
80// now $permissiontoadd or $user->hasRight('accounting', 'chartofaccount') are always equal to 1
81
82// Load variable for pagination
83$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
84$sortfield = GETPOST('sortfield', 'aZ09comma');
85$sortorder = GETPOST('sortorder', 'aZ09comma');
86$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
87if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
88 // If $page is not defined, or '' or -1 or if we click on clear filters
89 $page = 0;
90}
91$offset = $limit * $page;
92$pageprev = $page - 1;
93$pagenext = $page + 1;
94if (!$sortfield) {
95 $sortfield = "aa.account_number";
96}
97if (!$sortorder) {
98 $sortorder = "ASC";
99}
100
101$arrayfields = array(
102 'aa.account_number' => array('label' => "AccountNumber", 'checked' => '1'),
103 'aa.label' => array('label' => "Label", 'checked' => '1'),
104 'aa.labelshort' => array('label' => "LabelToShow", 'checked' => '1'),
105 'aa.account_parent' => array('label' => "Accountparent", 'checked' => '1'),
106 'aa.pcg_type' => array('label' => "Pcgtype", 'checked' => '1', 'help' => 'PcgtypeDesc'),
107 'categories' => array('label' => "AccountingCategories", 'checked' => '-1', 'help' => 'AccountingCategoriesDesc'),
108 'aa.reconcilable' => array('label' => "Reconcilable", 'checked' => '1'),
109 'aa.centralized' => array('label' => "Centralized", 'checked' => '1'),
110 'aa.import_key' => array('label' => "ImportId", 'checked' => '-1', 'help' => ''),
111 'aa.active' => array('label' => "Activated", 'checked' => '1')
112);
113
114if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
115 unset($arrayfields['categories']);
116 unset($arrayfields['aa.reconcilable']);
117}
118
119$accounting = new AccountingAccount($db);
120
121// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
122$hookmanager->initHooks(array('accountancyadminaccount'));
123
124
125/*
126 * Actions
127 */
128
129if (GETPOST('cancel', 'alpha')) {
130 $action = 'list';
131 $massaction = '';
132}
133if (!GETPOST('confirmmassaction', 'alpha')) {
134 $massaction = '';
135}
136
137$parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
138$reshook = $hookmanager->executeHooks('doActions', $parameters, $accounting, $action); // Note that $action and $object may have been monowraponalldified by some hooks
139if ($reshook < 0) {
140 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
141}
142
143if (empty($reshook)) {
144 if (!empty($cancel)) {
145 $action = '';
146 }
147
148 $objectclass = 'AccountingAccount';
149 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
150 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
151
152 if ($action == "delete") {
153 $action = "";
154 }
155 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
156
157 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
158 $search_account = "";
159 $search_label = "";
160 $search_labelshort = "";
161 $search_accountparent = "";
162 $search_pcgtype = "";
163 $search_import_key = "";
164 $search_reconcilable = "";
165 $search_centralized = "";
166 $search_active = "";
167 $search_array_options = array();
168 }
169 if ((GETPOSTINT('valid_change_chart') && GETPOSTINT('chartofaccounts') > 0) // explicit click on button 'Change and load' with js on
170 || (GETPOSTINT('chartofaccounts') > 0 && GETPOSTINT('chartofaccounts') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified
171 $error = 0;
172
173 if ($chartofaccounts > 0 /* && $permissiontoadd */) {
174 $country_code = '';
175 // Get language code for this $chartofaccounts
176 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
177 $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
178 $resql = $db->query($sql);
179 if ($resql) {
180 $obj = $db->fetch_object($resql);
181 if ($obj) {
182 $country_code = $obj->code;
183 }
184 } else {
185 dol_print_error($db);
186 }
187
188 // Try to load sql file
189 if ($country_code) {
190 $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
191
192 $offsetforchartofaccount = 0;
193 // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
194 // 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.
195 // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
196 $tmp = file_get_contents($sqlfile);
197 $reg = array();
198 if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
199 $offsetforchartofaccount += $reg[1];
200 }
201 $offsetforchartofaccount += ($conf->entity * 100000000);
202
203 $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
204
205 if ($result > 0) {
206 setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
207 } else {
208 setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
209 }
210 }
211
212 if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
213 $error++;
214 }
215 } else {
216 $error++;
217 }
218 }
219
220 if ($action == 'disable' /* && $permissiontoadd */) {
221 if ($accounting->fetch($id)) {
222 $mode = GETPOSTINT('mode');
223 $result = $accounting->accountDeactivate($id, $mode);
224 if ($result < 0) {
225 setEventMessages($accounting->error, $accounting->errors, 'errors');
226 }
227 }
228
229 $action = 'update';
230 } elseif ($action == 'enable' /* && $permissiontoadd */) {
231 if ($accounting->fetch($id)) {
232 $mode = GETPOSTINT('mode');
233 $result = $accounting->accountActivate($id, $mode);
234 if ($result < 0) {
235 setEventMessages($accounting->error, $accounting->errors, 'errors');
236 }
237 }
238 $action = 'update';
239 }
240}
241
242
243/*
244 * View
245 */
246$form = new Form($db);
247$formaccounting = new FormAccounting($db);
248
249$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
250
251llxHeader('', $langs->trans("ListAccounts"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_account');
252
253if ($action == 'delete') {
254 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
255 print $formconfirm;
256}
257
258$pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
259
260$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,";
261$sql .= " aa.reconcilable, aa.centralized, aa.active, aa.import_key,";
262$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
263
264// Add fields from hooks
265$parameters = array();
266$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
267$sql .= $hookmanager->resPrint;
268$sql = preg_replace('/,\s*$/', '', $sql);
269
270$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
271$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity);
272$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity);
273
274// Add table from hooks
275$parameters = array();
276$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
277$sql .= $hookmanager->resPrint;
278
279$sql .= " WHERE asy.rowid = ".((int) $pcgver);
280
281if (strlen(trim($search_account))) {
282 $lengthpaddingaccount = 0;
283 if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) {
284 $lengthpaddingaccount = max(getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT'), getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT'));
285 }
286 $search_account_tmp = $search_account;
287 $weremovedsomezero = 0;
288 if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
289 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
290 if (preg_match('/0$/', $search_account_tmp)) {
291 $weremovedsomezero++;
292 $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
293 }
294 }
295 }
296
297 //var_dump($search_account); exit;
298 if ($search_account_tmp) {
299 if ($weremovedsomezero) {
300 $search_account_tmp_clean = $search_account_tmp;
301 $search_account_clean = $search_account;
302 $startchar = '%';
303 if (substr($search_account_tmp, 0, 1) === '^') {
304 $startchar = '';
305 $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
306 $search_account_clean = preg_replace('/^\^/', '', $search_account);
307 }
308 $sql .= " AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean)."'";
309 $sql .= " OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean)."%')";
310 } else {
311 $sql .= natural_search("aa.account_number", $search_account_tmp);
312 }
313 }
314}
315if (strlen(trim($search_label))) {
316 $sql .= natural_search("aa.label", $search_label);
317}
318if (strlen(trim($search_labelshort))) {
319 $sql .= natural_search("aa.labelshort", $search_labelshort);
320}
321if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') {
322 $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
323}
324if (strlen(trim($search_pcgtype))) {
325 $sql .= natural_search("aa.pcg_type", $search_pcgtype);
326}
327if ($search_reconcilable != '' && $search_reconcilable != '-1') {
328 $sql .= " AND aa.reconcilable = ".((int) $search_reconcilable);
329}
330if ($search_centralized != '' && $search_centralized != '-1') {
331 $sql .= " AND aa.centralized = ".((int) $search_centralized);
332}
333if ($search_active != '' && $search_active != '-1') {
334 $sql .= " AND aa.active = ".((int) $search_active);
335}
336if (strlen(trim($search_import_key))) {
337 $sql .= natural_search("aa.import_key", $search_import_key);
338}
339
340// Add where from hooks
341$parameters = array();
342$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
343$sql .= $hookmanager->resPrint;
344
345$sql .= $db->order($sortfield, $sortorder);
346//print $sql;
347
348// Count total nb of records
349$nbtotalofrecords = '';
350if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
351 $resql = $db->query($sql);
352 $nbtotalofrecords = $db->num_rows($resql);
353 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
354 $page = 0;
355 $offset = 0;
356 }
357}
358
359$sql .= $db->plimit($limit + 1, $offset);
360
361dol_syslog("accountancy/admin/account.php:: sql=".$sql);
362$resql = $db->query($sql);
363
364if ($resql) {
365 $num = $db->num_rows($resql);
366
367 $arrayofselected = is_array($toselect) ? $toselect : array();
368
369 $param = '';
370 // if null contextpage is forced to 'accountingaccountlist' so never empty
371 if (/* !empty($contextpage) && */$contextpage != $_SERVER["PHP_SELF"]) {
372 $param .= '&contextpage='.urlencode($contextpage);
373 }
374 if ($limit > 0 && $limit != $conf->liste_limit) {
375 $param .= '&limit='.((int) $limit);
376 }
377 if ($search_account) {
378 $param .= '&search_account='.urlencode($search_account);
379 }
380 if ($search_label) {
381 $param .= '&search_label='.urlencode($search_label);
382 }
383 if ($search_labelshort) {
384 $param .= '&search_labelshort='.urlencode($search_labelshort);
385 }
386 if ($search_accountparent > 0 || $search_accountparent == '0') {
387 $param .= '&search_accountparent='.urlencode($search_accountparent);
388 }
389 if ($search_pcgtype) {
390 $param .= '&search_pcgtype='.urlencode($search_pcgtype);
391 }
392 if ($search_import_key) {
393 $param .= '&search_import_key='.urlencode($search_import_key);
394 }
395 if ($optioncss != '') {
396 $param .= '&optioncss='.urlencode($optioncss);
397 }
398
399 // Add $param from hooks
400 $parameters = array();
401 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
402 $param .= $hookmanager->resPrint;
403
404 if (!empty($conf->use_javascript_ajax)) {
405 print '<!-- Add javascript to reload page when we click "Change plan" -->
406 <script type="text/javascript">
407 $(document).ready(function () {
408 $("#change_chart").on("click", function (e) {
409 console.log("chartofaccounts selected = "+$("#chartofaccounts").val());
410 // reload page
411 window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
412 });
413 });
414 </script>';
415 }
416
417 // List of mass actions available
418 $arrayofmassactions = array();
419 // if ($permissiontoadd) { // test is always true
420 $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
421 // }
422 if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
423 $arrayofmassactions = array();
424 }
425
426 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
427
428 $newcardbutton = '';
429 $newcardbutton = dolGetButtonTitle($langs->trans('Addanaccount'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/accountancy/admin/card.php?action=create', '', $permissiontoadd);
430
431
432 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
433 if ($optioncss != '') {
434 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
435 }
436 print '<input type="hidden" name="token" value="'.newToken().'">';
437 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
438 print '<input type="hidden" name="action" value="list">';
439 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
440 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
441 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
442
443 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
444 print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1);
445
446 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
447
448 // Box to select active chart of account
449 print $langs->trans("Selectchartofaccounts")." : ";
450 print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
451 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
452 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
453 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
454 $sql .= " WHERE a.active = 1";
455 $sql .= " ORDER BY c.code, a.pcg_version";
456
457 dol_syslog("accountancy/admin/account.php sql=".$sql);
458
459 $resqlchart = $db->query($sql);
460 if ($resqlchart) {
461 $numbis = $db->num_rows($resqlchart);
462 $i = 0;
463 print '<option value="-1">&nbsp;</option>';
464 while ($i < $numbis) {
465 $obj = $db->fetch_object($resqlchart);
466 if ($obj) {
467 $labeltoshow = $obj->country_code.' - '.$obj->pcg_version.' - '.$obj->label;
468 $htmltoshow = picto_from_langcode($obj->country_code).' '.$obj->country_code.' - '.$obj->pcg_version.' - '.$obj->label;
469 print '<option value="'.$obj->rowid.'" data-html="'.dolPrintHTMLForAttribute($htmltoshow).'"';
470 print ($pcgver == $obj->rowid) ? ' selected' : '';
471 print '>'.$labeltoshow.'</option>';
472 }
473 $i++;
474 }
475 } else {
476 dol_print_error($db);
477 }
478 print "</select>";
479 print ajax_combobox("chartofaccounts");
480 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")).'">';
481
482 print '<br>';
483
484 $parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
485 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $accounting, $action); // Note that $action and $object may have been modified by hook
486 print $hookmanager->resPrint;
487
488 $parameters = array();
489 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
490 print $hookmanager->resPrint;
491
492 print '<br>';
493
494 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
495 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
496 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
497 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
498
499 $accountstatic = new AccountingAccount($db);
500 $accountparent = new AccountingAccount($db);
501 $totalarray = array();
502 $totalarray['nbfield'] = 0;
503
504 $moreforfilter = '';
505 // if ($moreforfilter) {
506 // print '<div class="liste_titre liste_titre_bydiv centpercent">';
507 // print $moreforfilter;
508 // print '</div>';
509 // }
510
511 print '<div class="div-table-responsive">';
512 // print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
513 print '<table class="tagtable liste">'."\n";
514
515 // Fields title search
516 // --------------------------------------------------------------------
517 print '<tr class="liste_titre_filter">';
518
519 // Action column
520 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
521 print '<td class="liste_titre center maxwidthsearch">';
522 $searchpicto = $form->showFilterButtons('left');
523 print $searchpicto;
524 print '</td>';
525 }
526 if (!empty($arrayfields['aa.account_number']['checked'])) {
527 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="'.$search_account.'"></td>';
528 }
529 if (!empty($arrayfields['aa.label']['checked'])) {
530 print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$search_label.'"></td>';
531 }
532 if (!empty($arrayfields['aa.labelshort']['checked'])) {
533 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.'"></td>';
534 }
535 if (!empty($arrayfields['aa.account_parent']['checked'])) {
536 print '<td class="liste_titre">';
537 print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2, array(), 0, 0, 'maxwidth150');
538 print '</td>';
539 }
540 // Predefined group
541 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
542 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
543 }
544 // Custom groups
545 if (!empty($arrayfields['categories']['checked'])) {
546 print '<td class="liste_titre"></td>';
547 }
548
549 // Fields from hook
550 $parameters = array('arrayfields' => $arrayfields);
551 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
552 print $hookmanager->resPrint;
553
554 // Import key
555 if (!empty($arrayfields['aa.import_key']['checked'])) {
556 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_import_key" value="'.$search_import_key.'"></td>';
557 }
558
559 // Reconcilable
560 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
561 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
562 print '<td class="liste_titre center">';
563 print $form->selectyesno('search_reconcilable', $search_reconcilable, 1, false, 1, 1, 'search_status onrightofpage width75');
564 print '</td>';
565 }
566 }
567
568 // Centralized
569 if (!empty($arrayfields['aa.centralized']['checked'])) {
570 print '<td class="liste_titre center">';
571 print $form->selectyesno('search_centralized', $search_centralized, 1, false, 1, 1, 'search_status onrightofpage width75');
572 print '</td>';
573 }
574
575 // Active
576 if (!empty($arrayfields['aa.active']['checked'])) {
577 print '<td class="liste_titre center">';
578 print $form->selectyesno('search_active', $search_active, 1, false, 1, 1, 'search_status onrightofpage width75');
579 print '</td>';
580 }
581 // Action column
582 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
583 print '<td class="liste_titre center maxwidthsearch">';
584 $searchpicto = $form->showFilterButtons();
585 print $searchpicto;
586 print '</td>';
587 }
588 print '</tr>'."\n";
589
590 $totalarray = array();
591 $totalarray['nbfield'] = 0;
592
593 // Fields title label
594 // --------------------------------------------------------------------
595 print '<tr class="liste_titre">';
596 // Action column
597 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
598 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');
599 $totalarray['nbfield']++;
600 }
601 if (!empty($arrayfields['aa.account_number']['checked'])) {
602 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
603 $totalarray['nbfield']++;
604 }
605 if (!empty($arrayfields['aa.label']['checked'])) {
606 print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
607 $totalarray['nbfield']++;
608 }
609 if (!empty($arrayfields['aa.labelshort']['checked'])) {
610 print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
611 $totalarray['nbfield']++;
612 }
613 if (!empty($arrayfields['aa.account_parent']['checked'])) {
614 print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
615 $totalarray['nbfield']++;
616 }
617 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
618 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);
619 $totalarray['nbfield']++;
620 }
621 if (!empty($arrayfields['categories']['checked'])) {
622 print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'], 1);
623 $totalarray['nbfield']++;
624 }
625
626 // Hook fields
627 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
628 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
629 print $hookmanager->resPrint;
630
631 if (!empty($arrayfields['aa.import_key']['checked'])) {
632 print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'], 1);
633 $totalarray['nbfield']++;
634 }
635 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
636 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
637 print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder, 'center ');
638 $totalarray['nbfield']++;
639 }
640 }
641 if (!empty($arrayfields['aa.centralized']['checked'])) {
642 print_liste_field_titre($arrayfields['aa.centralized']['label'], $_SERVER["PHP_SELF"], 'aa.centralized', '', $param, '', $sortfield, $sortorder);
643 $totalarray['nbfield']++;
644 }
645 if (!empty($arrayfields['aa.active']['checked'])) {
646 print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder);
647 $totalarray['nbfield']++;
648 }
649 // Action column
650 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
651 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
652 $totalarray['nbfield']++;
653 }
654 print "</tr>\n";
655
656 // Loop on record
657 // --------------------------------------------------------------------
658 $i = 0;
659 while ($i < min($num, $limit)) {
660 $obj = $db->fetch_object($resql);
661
662 $accountstatic->id = $obj->rowid;
663 $accountstatic->label = $obj->label;
664 $accountstatic->account_number = $obj->account_number;
665
666 print '<tr class="oddeven">';
667
668 // Action column
669 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
670 print '<td class="center nowraponall">';
671 // if ($permissiontoadd) { // test is always true
672 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
673 print img_edit();
674 print '</a>';
675 print '&nbsp;';
676 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
677 print img_delete();
678 print '</a>';
679 print '&nbsp;';
680 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
681 $selected = 0;
682 if (in_array($obj->rowid, $arrayofselected)) {
683 $selected = 1;
684 }
685 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
686 }
687 // }
688 print '</td>'."\n";
689 if (!$i) {
690 $totalarray['nbfield']++;
691 }
692 }
693
694 // Account number
695 if (!empty($arrayfields['aa.account_number']['checked'])) {
696 print "<td>";
697 print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1, 0, 'accountcard');
698 print "</td>\n";
699 if (!$i) {
700 $totalarray['nbfield']++;
701 }
702 }
703
704 // Account label
705 if (!empty($arrayfields['aa.label']['checked'])) {
706 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">';
707 print dol_escape_htmltag($obj->label);
708 print "</td>\n";
709 if (!$i) {
710 $totalarray['nbfield']++;
711 }
712 }
713
714 // Account label to show (label short)
715 if (!empty($arrayfields['aa.labelshort']['checked'])) {
716 print "<td>";
717 print dol_escape_htmltag($obj->labelshort);
718 print "</td>\n";
719 if (!$i) {
720 $totalarray['nbfield']++;
721 }
722 }
723
724 // Account parent
725 if (!empty($arrayfields['aa.account_parent']['checked'])) {
726 // 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.
727 // So for orphans, obj->account_parent is set but not obj->rowid2
728 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
729 print "<td>";
730 print '<!-- obj->account_parent = '.$obj->account_parent.' obj->rowid2 = '.$obj->rowid2.' -->';
731 $accountparent->id = $obj->rowid2;
732 $accountparent->label = $obj->label2;
733 $accountparent->account_number = $obj->account_number2; // Store an account number for output
734 print $accountparent->getNomUrl(1);
735 print "</td>\n";
736 if (!$i) {
737 $totalarray['nbfield']++;
738 }
739 } else {
740 print '<td>';
741 if (!empty($obj->account_parent)) {
742 print '<!-- Bad value for obj->account_parent = '.$obj->account_parent.': is a rowid that does not exists -->';
743 }
744 print '</td>';
745 if (!$i) {
746 $totalarray['nbfield']++;
747 }
748 }
749 }
750
751 // Predefined group (deprecated)
752 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
753 print "<td>";
754 print dol_escape_htmltag($obj->pcg_type);
755 print "</td>\n";
756 if (!$i) {
757 $totalarray['nbfield']++;
758 }
759 }
760 // Custom accounts
761 if (!empty($arrayfields['categories']['checked'])) {
762 print "<td>";
763 // TODO Get all custom groups labels the account is in
764 print dol_escape_htmltag($obj->fk_accounting_category);
765 print "</td>\n";
766 if (!$i) {
767 $totalarray['nbfield']++;
768 }
769 }
770
771 // Fields from hook
772 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
773 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
774 print $hookmanager->resPrint;
775
776 // Import id
777 if (!empty($arrayfields['aa.import_key']['checked'])) {
778 print "<td>";
779 print dol_escape_htmltag($obj->import_key);
780 print "</td>\n";
781 if (!$i) {
782 $totalarray['nbfield']++;
783 }
784 }
785
786 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
787 // Activated or not reconciliation on a general accounting account
788 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
789 print '<td class="center">';
790 if (empty($obj->reconcilable)) {
791 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&page='.$page.'&mode=1&token='.newToken().'">';
792 print img_picto($langs->trans("Disabled"), 'switch_off');
793 print '</a>';
794 } else {
795 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&page='.$page.'&mode=1&token='.newToken().'">';
796 print img_picto($langs->trans("Activated"), 'switch_on');
797 print '</a>';
798 }
799 print '</td>';
800 if (!$i) {
801 $totalarray['nbfield']++;
802 }
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).'">';
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).'">';
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:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$totalarray
Definition export.php:1206
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)
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.