dolibarr  18.0.0
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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
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
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
31 require_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 
44 $search_account = GETPOST('search_account', 'alpha');
45 $search_label = GETPOST('search_label', 'alpha');
46 $search_labelshort = GETPOST('search_labelshort', 'alpha');
47 $search_accountparent = GETPOST('search_accountparent', 'alpha');
48 $search_pcgtype = GETPOST('search_pcgtype', 'alpha');
49 $search_import_key = GETPOST('search_import_key', 'alpha');
50 $toselect = GETPOST('toselect', 'array');
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 $confirm = GETPOST('confirm', 'alpha');
53 
54 $chartofaccounts = GETPOST('chartofaccounts', 'int');
55 
56 $permissiontoadd = $user->hasRight('accounting', 'chartofaccount');
57 $permissiontodelete = $user->hasRight('accounting', 'chartofaccount');
58 
59 // Security check
60 if ($user->socid > 0) {
62 }
63 if (!$user->hasRight('accounting', 'chartofaccount')) {
65 }
66 
67 // Load variable for pagination
68 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
69 $sortfield = GETPOST('sortfield', 'aZ09comma');
70 $sortorder = GETPOST('sortorder', 'aZ09comma');
71 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
72 if (empty($page) || $page == -1) {
73  $page = 0;
74 } // If $page is not defined, or '' or -1
75 $offset = $limit * $page;
76 $pageprev = $page - 1;
77 $pagenext = $page + 1;
78 if (!$sortfield) {
79  $sortfield = "aa.account_number";
80 }
81 if (!$sortorder) {
82  $sortorder = "ASC";
83 }
84 
85 $arrayfields = array(
86  'aa.account_number'=>array('label'=>"AccountNumber", 'checked'=>1),
87  'aa.label'=>array('label'=>"Label", 'checked'=>1),
88  'aa.labelshort'=>array('label'=>"LabelToShow", 'checked'=>1),
89  'aa.account_parent'=>array('label'=>"Accountparent", 'checked'=>1),
90  'aa.pcg_type'=>array('label'=>"Pcgtype", 'checked'=>1, 'help'=>'PcgtypeDesc'),
91  'categories'=>array('label'=>"AccountingCategories", 'checked'=>-1, 'help'=>'AccountingCategoriesDesc'),
92  'aa.reconcilable'=>array('label'=>"Reconcilable", 'checked'=>1),
93  'aa.active'=>array('label'=>"Activated", 'checked'=>1),
94  'aa.import_key'=>array('label'=>"ImportId", 'checked'=>-1)
95 );
96 
97 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
98  unset($arrayfields['categories']);
99  unset($arrayfields['aa.reconcilable']);
100 }
101 
102 $accounting = new AccountingAccount($db);
103 
104 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
105 $hookmanager->initHooks(array('accountancyadminaccount'));
106 
107 
108 /*
109  * Actions
110  */
111 
112 if (GETPOST('cancel', 'alpha')) {
113  $action = 'list'; $massaction = '';
114 }
115 if (!GETPOST('confirmmassaction', 'alpha')) {
116  $massaction = '';
117 }
118 
119 $parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
120 $reshook = $hookmanager->executeHooks('doActions', $parameters, $accounting, $action); // Note that $action and $object may have been monowraponalldified by some hooks
121 if ($reshook < 0) {
122  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
123 }
124 
125 if (empty($reshook)) {
126  if (!empty($cancel)) {
127  $action = '';
128  }
129 
130  $objectclass = 'AccountingAccount';
131  $uploaddir = $conf->accounting->multidir_output[$conf->entity];
132  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
133 
134  if ($action == "delete") {
135  $action = "";
136  }
137  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
138 
139  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
140  $search_account = "";
141  $search_label = "";
142  $search_labelshort = "";
143  $search_accountparent = "";
144  $search_pcgtype = "";
145  $search_array_options = array();
146  }
147  if ((GETPOST('valid_change_chart', 'alpha') && GETPOST('chartofaccounts', 'int') > 0) // explicit click on button 'Change and load' with js on
148  || (GETPOST('chartofaccounts', 'int') > 0 && GETPOST('chartofaccounts', 'int') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified
149  if ($chartofaccounts > 0 && $permissiontoadd) {
150  // Get language code for this $chartofaccounts
151  $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
152  $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
153  $resql = $db->query($sql);
154  if ($resql) {
155  $obj = $db->fetch_object($resql);
156  $country_code = $obj->code;
157  } else {
158  dol_print_error($db);
159  }
160 
161  // Try to load sql file
162  if ($country_code) {
163  $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
164 
165  $offsetforchartofaccount = 0;
166  // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
167  // 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.
168  // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
169  $tmp = file_get_contents($sqlfile);
170  $reg = array();
171  if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
172  $offsetforchartofaccount += $reg[1];
173  }
174  $offsetforchartofaccount += ($conf->entity * 100000000);
175 
176  $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
177 
178  if ($result > 0) {
179  setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
180  } else {
181  setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
182  }
183  }
184 
185  if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
186  $error++;
187  }
188  } else {
189  $error++;
190  }
191  }
192 
193  if ($action == 'disable' && $permissiontoadd) {
194  if ($accounting->fetch($id)) {
195  $mode = GETPOST('mode', 'int');
196  $result = $accounting->accountDeactivate($id, $mode);
197  }
198 
199  $action = 'update';
200  if ($result < 0) {
201  setEventMessages($accounting->error, $accounting->errors, 'errors');
202  }
203  } elseif ($action == 'enable' && $permissiontoadd) {
204  if ($accounting->fetch($id)) {
205  $mode = GETPOST('mode', 'int');
206  $result = $accounting->accountActivate($id, $mode);
207  }
208  $action = 'update';
209  if ($result < 0) {
210  setEventMessages($accounting->error, $accounting->errors, 'errors');
211  }
212  }
213 }
214 
215 
216 /*
217  * View
218  */
219 
220 $form = new Form($db);
221 $formaccounting = new FormAccounting($db);
222 
223 llxHeader('', $langs->trans("ListAccounts"));
224 
225 if ($action == 'delete') {
226  $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
227  print $formconfirm;
228 }
229 
230 $pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
231 
232 $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,";
233 $sql .= " aa.reconcilable, aa.active, aa.import_key,";
234 $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
235 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
236 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity);
237 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity);
238 $sql .= " WHERE asy.rowid = ".((int) $pcgver);
239 //print $sql;
240 if (strlen(trim($search_account))) {
241  $lengthpaddingaccount = 0;
242  if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) {
243  $lengthpaddingaccount = max(getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT'), getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT'));
244  }
245  $search_account_tmp = $search_account;
246  $weremovedsomezero = 0;
247  if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
248  for ($i = 0; $i < $lengthpaddingaccount; $i++) {
249  if (preg_match('/0$/', $search_account_tmp)) {
250  $weremovedsomezero++;
251  $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
252  }
253  }
254  }
255 
256  //var_dump($search_account); exit;
257  if ($search_account_tmp) {
258  if ($weremovedsomezero) {
259  $search_account_tmp_clean = $search_account_tmp;
260  $search_account_clean = $search_account;
261  $startchar = '%';
262  if (strpos($search_account_tmp, '^') === 0) {
263  $startchar = '';
264  $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
265  $search_account_clean = preg_replace('/^\^/', '', $search_account);
266  }
267  $sql .= " AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean)."'";
268  $sql .= " OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean)."%')";
269  } else {
270  $sql .= natural_search("aa.account_number", $search_account_tmp);
271  }
272  }
273 }
274 if (strlen(trim($search_label))) {
275  $sql .= natural_search("aa.label", $search_label);
276 }
277 if (strlen(trim($search_labelshort))) {
278  $sql .= natural_search("aa.labelshort", $search_labelshort);
279 }
280 if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') {
281  $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
282 }
283 if (strlen(trim($search_pcgtype))) {
284  $sql .= natural_search("aa.pcg_type", $search_pcgtype);
285 }
286 $sql .= $db->order($sortfield, $sortorder);
287 //print $sql;
288 
289 // Count total nb of records
290 $nbtotalofrecords = '';
291 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
292  $resql = $db->query($sql);
293  $nbtotalofrecords = $db->num_rows($resql);
294  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
295  $page = 0;
296  $offset = 0;
297  }
298 }
299 
300 // List of mass actions available
301 if ($user->hasRight('accounting', 'chartofaccount')) {
302  $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
303 }
304 if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
305  $arrayofmassactions = array();
306 }
307 
308 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
309 $arrayofselected = is_array($toselect) ? $toselect : array();
310 $sql .= $db->plimit($limit + 1, $offset);
311 
312 dol_syslog('accountancy/admin/account.php:: $sql='.$sql);
313 $resql = $db->query($sql);
314 
315 if ($resql) {
316  $num = $db->num_rows($resql);
317 
318  $param = '';
319  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
320  $param .= '&contextpage='.urlencode($contextpage);
321  }
322  if ($limit > 0 && $limit != $conf->liste_limit) {
323  $param .= '&limit='.((int) $limit);
324  }
325  if ($search_account) {
326  $param .= '&search_account='.urlencode($search_account);
327  }
328  if ($search_label) {
329  $param .= '&search_label='.urlencode($search_label);
330  }
331  if ($search_labelshort) {
332  $param .= '&search_labelshort='.urlencode($search_labelshort);
333  }
334  if ($search_accountparent > 0 || $search_accountparent == '0') {
335  $param .= '&search_accountparent='.urlencode($search_accountparent);
336  }
337  if ($search_pcgtype) {
338  $param .= '&search_pcgtype='.urlencode($search_pcgtype);
339  }
340  if ($optioncss != '') {
341  $param .= '&search_import_key='.urlencode($search_import_key);
342  }
343  if ($optioncss != '') {
344  $param .= '&optioncss='.urlencode($optioncss);
345  }
346 
347  if (!empty($conf->use_javascript_ajax)) {
348  print '<!-- Add javascript to reload page when we click "Change plan" -->
349  <script type="text/javascript">
350  $(document).ready(function () {
351  $("#change_chart").on("click", function (e) {
352  console.log("chartofaccounts seleted = "+$("#chartofaccounts").val());
353  // reload page
354  window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
355  });
356  });
357  </script>';
358  }
359 
360  $newcardbutton = '';
361 
362  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
363  if ($optioncss != '') {
364  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
365  }
366  print '<input type="hidden" name="token" value="'.newToken().'">';
367  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
368  print '<input type="hidden" name="action" value="list">';
369  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
370  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
371  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
372 
373  $newcardbutton .= dolGetButtonTitle($langs->trans("New"), $langs->trans("Addanaccount"), 'fa fa-plus-circle', './card.php?action=create');
374  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
375  print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1);
376 
377  // Box to select active chart of account
378  print $langs->trans("Selectchartofaccounts")." : ";
379  print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
380  $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
381  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
382  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
383  $sql .= " WHERE a.active = 1";
384  dol_syslog('accountancy/admin/account.php $sql='.$sql);
385 
386  $resqlchart = $db->query($sql);
387  if ($resqlchart) {
388  $numbis = $db->num_rows($resqlchart);
389  $i = 0;
390  print '<option value="-1">&nbsp;</option>';
391  while ($i < $numbis) {
392  $obj = $db->fetch_object($resqlchart);
393 
394  print '<option value="'.$obj->rowid.'"';
395  print ($pcgver == $obj->rowid) ? ' selected' : '';
396  print '>'.$obj->pcg_version.' - '.$obj->label.' - ('.$obj->country_code.')</option>';
397 
398  $i++;
399  }
400  } else {
401  dol_print_error($db);
402  }
403  print "</select>";
404  print ajax_combobox("chartofaccounts");
405  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")).'">';
406 
407  print '<br>';
408 
409  $parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
410  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $accounting, $action); // Note that $action and $object may have been modified by hook
411  print $hookmanager->resPrint;
412 
413  print '<br>';
414 
415  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
416  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
417  $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
418 
419  $moreforfilter = '';
420 
421  $accountstatic = new AccountingAccount($db);
422  $accountparent = new AccountingAccount($db);
423  $totalarray = array();
424  $totalarray['nbfield'] = 0;
425 
426  print '<div class="div-table-responsive">';
427  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
428 
429  // Line for search fields
430  print '<tr class="liste_titre_filter">';
431  if (!empty($arrayfields['aa.account_number']['checked'])) {
432  print '<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="'.$search_account.'"></td>';
433  }
434  if (!empty($arrayfields['aa.label']['checked'])) {
435  print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$search_label.'"></td>';
436  }
437  if (!empty($arrayfields['aa.labelshort']['checked'])) {
438  print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.'"></td>';
439  }
440  if (!empty($arrayfields['aa.account_parent']['checked'])) {
441  print '<td class="liste_titre">';
442  print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2, array(), 0, 0, 'maxwidth150');
443  print '</td>';
444  }
445  // Predefined group
446  if (!empty($arrayfields['aa.pcg_type']['checked'])) {
447  print '<td class="liste_titre"><input type="text" class="flat width75" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
448  }
449  // Custom groups
450  if (!empty($arrayfields['categories']['checked'])) {
451  print '<td class="liste_titre"></td>';
452  }
453  // Import key
454  if (!empty($arrayfields['aa.import_key']['checked'])) {
455  print '<td class="liste_titre"><input type="text" class="flat width75" name="search_import_key" value="'.$search_import_key.'"></td>';
456  }
457  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
458  if (!empty($arrayfields['aa.reconcilable']['checked'])) {
459  print '<td class="liste_titre">&nbsp;</td>';
460  }
461  }
462  if (!empty($arrayfields['aa.active']['checked'])) {
463  print '<td class="liste_titre">&nbsp;</td>';
464  }
465  print '<td class="liste_titre maxwidthsearch">';
466  $searchpicto = $form->showFilterButtons();
467  print $searchpicto;
468  print '</td>';
469  print '</tr>';
470  print '<tr class="liste_titre">';
471  if (!empty($arrayfields['aa.account_number']['checked'])) {
472  print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
473  }
474  if (!empty($arrayfields['aa.label']['checked'])) {
475  print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
476  }
477  if (!empty($arrayfields['aa.labelshort']['checked'])) {
478  print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
479  }
480  if (!empty($arrayfields['aa.account_parent']['checked'])) {
481  print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
482  }
483  if (!empty($arrayfields['aa.pcg_type']['checked'])) {
484  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);
485  }
486  if (!empty($arrayfields['categories']['checked'])) {
487  print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'], 1);
488  }
489  if (!empty($arrayfields['aa.import_key']['checked'])) {
490  print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'], 1);
491  }
492  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
493  if (!empty($arrayfields['aa.reconcilable']['checked'])) {
494  print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder);
495  }
496  }
497  if (!empty($arrayfields['aa.active']['checked'])) {
498  print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder);
499  }
500  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
501  print "</tr>\n";
502 
503  $i = 0;
504  while ($i < min($num, $limit)) {
505  $obj = $db->fetch_object($resql);
506 
507  $accountstatic->id = $obj->rowid;
508  $accountstatic->label = $obj->label;
509  $accountstatic->account_number = $obj->account_number;
510 
511  print '<tr class="oddeven">';
512 
513  // Account number
514  if (!empty($arrayfields['aa.account_number']['checked'])) {
515  print "<td>";
516  print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1, 0, 'accountcard');
517  print "</td>\n";
518  if (!$i) {
519  $totalarray['nbfield']++;
520  }
521  }
522 
523  // Account label
524  if (!empty($arrayfields['aa.label']['checked'])) {
525  print "<td>";
526  print dol_escape_htmltag($obj->label);
527  print "</td>\n";
528  if (!$i) {
529  $totalarray['nbfield']++;
530  }
531  }
532 
533  // Account label to show (label short)
534  if (!empty($arrayfields['aa.labelshort']['checked'])) {
535  print "<td>";
536  print dol_escape_htmltag($obj->labelshort);
537  print "</td>\n";
538  if (!$i) {
539  $totalarray['nbfield']++;
540  }
541  }
542 
543  // Account parent
544  if (!empty($arrayfields['aa.account_parent']['checked'])) {
545  // 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.
546  // So for orphans, obj->account_parent is set but not obj->rowid2
547  if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
548  print "<td>";
549  print '<!-- obj->account_parent = '.$obj->account_parent.' obj->rowid2 = '.$obj->rowid2.' -->';
550  $accountparent->id = $obj->rowid2;
551  $accountparent->label = $obj->label2;
552  $accountparent->account_number = $obj->account_number2; // Sotre an account number for output
553  print $accountparent->getNomUrl(1);
554  print "</td>\n";
555  if (!$i) {
556  $totalarray['nbfield']++;
557  }
558  } else {
559  print '<td>';
560  if (!empty($obj->account_parent)) {
561  print '<!-- Bad value for obj->account_parent = '.$obj->account_parent.': is a rowid that does not exists -->';
562  }
563  print '</td>';
564  if (!$i) {
565  $totalarray['nbfield']++;
566  }
567  }
568  }
569 
570  // Predefined group (deprecated)
571  if (!empty($arrayfields['aa.pcg_type']['checked'])) {
572  print "<td>";
573  print dol_escape_htmltag($obj->pcg_type);
574  print "</td>\n";
575  if (!$i) {
576  $totalarray['nbfield']++;
577  }
578  }
579  // Custom accounts
580  if (!empty($arrayfields['categories']['checked'])) {
581  print "<td>";
582  // TODO Get all custom groups labels the account is in
583  print dol_escape_htmltag($obj->fk_accounting_category);
584  print "</td>\n";
585  if (!$i) {
586  $totalarray['nbfield']++;
587  }
588  }
589 
590  // Import id
591  if (!empty($arrayfields['aa.import_key']['checked'])) {
592  print "<td>";
593  print dol_escape_htmltag($obj->import_key);
594  print "</td>\n";
595  if (!$i) {
596  $totalarray['nbfield']++;
597  }
598  }
599 
600  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
601  // Activated or not reconciliation on accounting account
602  if (!empty($arrayfields['aa.reconcilable']['checked'])) {
603  print '<td class="center">';
604  if (empty($obj->reconcilable)) {
605  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=1&token='.newToken().'">';
606  print img_picto($langs->trans("Disabled"), 'switch_off');
607  print '</a>';
608  } else {
609  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=1&token='.newToken().'">';
610  print img_picto($langs->trans("Activated"), 'switch_on');
611  print '</a>';
612  }
613  print '</td>';
614  if (!$i) {
615  $totalarray['nbfield']++;
616  }
617  }
618  }
619 
620  // Activated or not
621  if (!empty($arrayfields['aa.active']['checked'])) {
622  print '<td class="center">';
623  if (empty($obj->active)) {
624  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=0&token='.newToken().'">';
625  print img_picto($langs->trans("Disabled"), 'switch_off');
626  print '</a>';
627  } else {
628  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=0&token='.newToken().'">';
629  print img_picto($langs->trans("Activated"), 'switch_on');
630  print '</a>';
631  }
632  print '</td>';
633  if (!$i) {
634  $totalarray['nbfield']++;
635  }
636  }
637 
638  // Action
639  print '<td class="center nowraponall">';
640  if ($user->hasRight('accounting', 'chartofaccount')) {
641  print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
642  print img_edit();
643  print '</a>';
644  print '&nbsp;';
645  print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
646  print img_delete();
647  print '</a>';
648  print '&nbsp;';
649  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
650  $selected = 0;
651  if (in_array($obj->rowid, $arrayofselected)) {
652  $selected = 1;
653  }
654  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
655  }
656  }
657  print '</td>'."\n";
658  if (!$i) {
659  $totalarray['nbfield']++;
660  }
661 
662  print "</tr>\n";
663  $i++;
664  }
665 
666  if ($num == 0) {
667  $colspan = 1;
668  foreach ($arrayfields as $key => $val) {
669  if (!empty($val['checked'])) {
670  $colspan++;
671  }
672  }
673  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
674  }
675 
676  print "</table>";
677  print "</div>";
678  print '</form>';
679 } else {
680  dol_print_error($db);
681 }
682 
683 // End of page
684 llxFooter();
685 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
dol_escape_htmltag
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...
Definition: functions.lib.php:1600
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4692
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:634
dolGetButtonTitle
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.
Definition: functions.lib.php:11263
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
print_barre_liste
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.
Definition: functions.lib.php:5530
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
run_sql
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.
Definition: admin.lib.php:169
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
dolibarr_set_const
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).
Definition: admin.lib.php:638
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5295
natural_search
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...
Definition: functions.lib.php:10024
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1164
ajax_combobox
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:449
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156