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