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