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