26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
33 $langs->loadLangs(array(
"compta",
"bills",
"admin",
"accountancy",
"salaries"));
36 $action =
GETPOST(
'action',
'aZ09');
37 $cancel =
GETPOST(
'cancel',
'alpha');
39 $rowid =
GETPOST(
'rowid',
'int');
40 $massaction =
GETPOST(
'massaction',
'aZ09');
41 $optioncss =
GETPOST(
'optioncss',
'alpha');
42 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountingaccountlist';
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 $toselect =
GETPOST(
'toselect',
'array');
50 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
51 $confirm =
GETPOST(
'confirm',
'alpha');
53 $chartofaccounts =
GETPOST(
'chartofaccounts',
'int');
55 $permissiontoadd = !empty($user->rights->accounting->chartofaccount);
56 $permissiontodelete = !empty($user->rights->accounting->chartofaccount);
59 if ($user->socid > 0) {
62 if (empty($user->rights->accounting->chartofaccount)) {
67 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
68 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
69 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
71 if (empty($page) || $page == -1) {
74 $offset = $limit * $page;
75 $pageprev = $page - 1;
76 $pagenext = $page + 1;
78 $sortfield =
"aa.account_number";
85 'aa.account_number'=>array(
'label'=>$langs->trans(
"AccountNumber"),
'checked'=>1),
86 'aa.label'=>array(
'label'=>$langs->trans(
"Label"),
'checked'=>1),
87 'aa.labelshort'=>array(
'label'=>$langs->trans(
"LabelToShow"),
'checked'=>1),
88 'aa.account_parent'=>array(
'label'=>$langs->trans(
"Accountparent"),
'checked'=>1),
89 'aa.pcg_type'=>array(
'label'=>$langs->trans(
"Pcgtype"),
'checked'=>1,
'help'=>
'PcgtypeDesc'),
90 'aa.reconcilable'=>array(
'label'=>$langs->trans(
"Reconcilable"),
'checked'=>1),
91 'aa.active'=>array(
'label'=>$langs->trans(
"Activated"),
'checked'=>1)
94 if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
95 unset($arrayfields[
'aa.reconcilable']);
105 if (
GETPOST(
'cancel',
'alpha')) {
106 $action =
'list'; $massaction =
'';
108 if (!
GETPOST(
'confirmmassaction',
'alpha')) {
112 $parameters = array();
113 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
118 if (empty($reshook)) {
119 if (!empty($cancel)) {
123 $objectclass =
'AccountingAccount';
124 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
125 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
127 if ($action ==
"delete") {
130 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
132 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
133 $search_account =
"";
135 $search_labelshort =
"";
136 $search_accountparent =
"";
137 $search_pcgtype =
"";
138 $search_array_options = array();
140 if ((
GETPOST(
'valid_change_chart',
'alpha') &&
GETPOST(
'chartofaccounts',
'int') > 0)
141 || (
GETPOST(
'chartofaccounts',
'int') > 0 &&
GETPOST(
'chartofaccounts',
'int') != $conf->global->CHARTOFACCOUNTS)) {
142 if ($chartofaccounts > 0 && $permissiontoadd) {
144 $sql =
'SELECT code FROM '.MAIN_DB_PREFIX.
'c_country as c, '.MAIN_DB_PREFIX.
'accounting_system as a';
145 $sql .=
' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
146 $resql = $db->query($sql);
148 $obj = $db->fetch_object(
$resql);
149 $country_code = $obj->code;
156 $sqlfile = DOL_DOCUMENT_ROOT.
'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).
'.sql';
158 $offsetforchartofaccount = 0;
162 $tmp = file_get_contents($sqlfile);
164 if (preg_match(
'/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
165 $offsetforchartofaccount += $reg[1];
167 $offsetforchartofaccount += ($conf->entity * 100000000);
169 $result =
run_sql($sqlfile, 1, $conf->entity, 1,
'',
'default', 32768, 0, $offsetforchartofaccount);
178 if (!
dolibarr_set_const($db,
'CHARTOFACCOUNTS', $chartofaccounts,
'chaine', 0,
'', $conf->entity)) {
186 if ($action ==
'disable' && $permissiontoadd) {
187 if ($accounting->fetch($id)) {
188 $mode =
GETPOST(
'mode',
'int');
189 $result = $accounting->accountDeactivate($id, $mode);
196 } elseif ($action ==
'enable' && $permissiontoadd) {
197 if ($accounting->fetch($id)) {
198 $mode =
GETPOST(
'mode',
'int');
199 $result = $accounting->accountActivate($id, $mode);
216 llxHeader(
'', $langs->trans(
"ListAccounts"));
218 if ($action ==
'delete') {
219 $formconfirm = $html->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$id, $langs->trans(
'DeleteAccount'), $langs->trans(
'ConfirmDeleteAccount'),
'confirm_delete',
'', 0, 1);
223 $pcgver = $conf->global->CHARTOFACCOUNTS;
225 $sql =
"SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent , aa.label, aa.labelshort, aa.reconcilable, aa.active, ";
226 $sql .=
" a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
228 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".$conf->entity;
229 if ($db->type ==
'pgsql') {
230 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".$conf->entity;
232 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".$conf->entity;
234 $sql .=
" WHERE asy.rowid = ".((int) $pcgver);
236 if (strlen(trim($search_account))) {
237 $lengthpaddingaccount = 0;
238 if ($conf->global->ACCOUNTING_LENGTH_GACCOUNT || $conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
239 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_GACCOUNT, $conf->global->ACCOUNTING_LENGTH_AACCOUNT);
241 $search_account_tmp = $search_account;
242 $weremovedsomezero = 0;
243 if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
244 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
245 if (preg_match(
'/0$/', $search_account_tmp)) {
246 $weremovedsomezero++;
247 $search_account_tmp = preg_replace(
'/0$/',
'', $search_account_tmp);
253 if ($search_account_tmp) {
254 if ($weremovedsomezero) {
255 $search_account_tmp_clean = $search_account_tmp;
256 $search_account_clean = $search_account;
258 if (strpos($search_account_tmp,
'^') === 0) {
260 $search_account_tmp_clean = preg_replace(
'/^\^/',
'', $search_account_tmp);
261 $search_account_clean = preg_replace(
'/^\^/',
'', $search_account);
263 $sql .=
" AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean).
"'";
264 $sql .=
" OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean).
"%')";
270 if (strlen(trim($search_label))) {
273 if (strlen(trim($search_labelshort))) {
276 if (strlen(trim($search_accountparent)) && $search_accountparent !=
'-1') {
277 $sql .=
natural_search(
"aa.account_parent", $search_accountparent, 2);
279 if (strlen(trim($search_pcgtype))) {
282 $sql .= $db->order($sortfield, $sortorder);
286 $nbtotalofrecords =
'';
287 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
288 $resql = $db->query($sql);
289 $nbtotalofrecords = $db->num_rows(
$resql);
290 if (($page * $limit) > $nbtotalofrecords) {
297 if ($user->rights->accounting->chartofaccount) {
298 $arrayofmassactions[
'predelete'] =
'<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans(
"Delete");
300 if (in_array($massaction, array(
'presend',
'predelete',
'closed'))) {
301 $arrayofmassactions = array();
304 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
305 $arrayofselected = is_array($toselect) ? $toselect : array();
306 $sql .= $db->plimit($limit + 1, $offset);
308 dol_syslog(
'accountancy/admin/account.php:: $sql='.$sql);
309 $resql = $db->query($sql);
312 $num = $db->num_rows(
$resql);
315 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
316 $param .=
'&contextpage='.urlencode($contextpage);
318 if ($limit > 0 && $limit != $conf->liste_limit) {
319 $param .=
'&limit='.urlencode($limit);
321 if ($search_account) {
322 $param .=
'&search_account='.urlencode($search_account);
325 $param .=
'&search_label='.urlencode($search_label);
327 if ($search_labelshort) {
328 $param .=
'&search_labelshort='.urlencode($search_labelshort);
330 if ($search_accountparent > 0 || $search_accountparent ==
'0') {
331 $param .=
'&search_accountparent='.urlencode($search_accountparent);
333 if ($search_pcgtype) {
334 $param .=
'&search_pcgtype='.urlencode($search_pcgtype);
336 if ($optioncss !=
'') {
337 $param .=
'&optioncss='.urlencode($optioncss);
340 if (!empty($conf->use_javascript_ajax)) {
341 print
'<!-- Add javascript to reload page when we click "Change plan" -->
342 <script type="text/javascript">
343 $(document).ready(function () {
344 $("#change_chart").on("click", function (e) {
345 console.log("chartofaccounts seleted = "+$("#chartofaccounts").val());
347 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
355 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
356 if ($optioncss !=
'') {
357 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
359 print
'<input type="hidden" name="token" value="'.newToken().
'">';
360 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
361 print
'<input type="hidden" name="action" value="list">';
362 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
363 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
364 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
366 $newcardbutton .=
dolGetButtonTitle($langs->trans(
"New"), $langs->trans(
"Addanaccount"),
'fa fa-plus-circle',
'./card.php?action=create');
367 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
368 print_barre_liste($langs->trans(
'ListAccounts'), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'accounting_account', 0, $newcardbutton,
'', $limit, 0, 0, 1);
371 print $langs->trans(
"Selectchartofaccounts").
" : ";
372 print
'<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
373 $sql =
"SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
374 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_system as a";
375 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c ON a.fk_country = c.rowid AND c.active = 1";
376 $sql .=
" WHERE a.active = 1";
377 dol_syslog(
'accountancy/admin/account.php $sql='.$sql);
379 $resqlchart = $db->query($sql);
381 $numbis = $db->num_rows($resqlchart);
383 print
'<option value="-1"> </option>';
384 while ($i < $numbis) {
385 $obj = $db->fetch_object($resqlchart);
387 print
'<option value="'.$obj->rowid.
'"';
388 print ($pcgver == $obj->rowid) ?
' selected' :
'';
389 print
'>'.$obj->pcg_version.
' - '.$obj->label.
' - ('.$obj->country_code.
')</option>';
398 print
'<input type="'.(empty($conf->use_javascript_ajax) ?
'submit' :
'button').
'" class="button button-edit" name="change_chart" id="change_chart" value="'.
dol_escape_htmltag($langs->trans(
"ChangeAndLoad")).
'">';
403 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
404 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
405 $selectedfields .= (count($arrayofmassactions) ?
$form->showCheckAddButtons(
'checkforselect', 1) :
'');
411 $totalarray = array();
412 $totalarray[
'nbfield'] = 0;
414 print
'<div class="div-table-responsive">';
415 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
418 print
'<tr class="liste_titre_filter">';
419 if (!empty($arrayfields[
'aa.account_number'][
'checked'])) {
420 print
'<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="'.$search_account.
'"></td>';
422 if (!empty($arrayfields[
'aa.label'][
'checked'])) {
423 print
'<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$search_label.
'"></td>';
425 if (!empty($arrayfields[
'aa.labelshort'][
'checked'])) {
426 print
'<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.
'"></td>';
428 if (!empty($arrayfields[
'aa.account_parent'][
'checked'])) {
429 print
'<td class="liste_titre">';
430 print $formaccounting->select_account($search_accountparent,
'search_accountparent', 2);
433 if (!empty($arrayfields[
'aa.pcg_type'][
'checked'])) {
434 print
'<td class="liste_titre"><input type="text" class="flat width100" name="search_pcgtype" value="'.$search_pcgtype.
'"></td>';
436 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
437 if (!empty($arrayfields[
'aa.reconcilable'][
'checked'])) {
438 print
'<td class="liste_titre"> </td>';
441 if (!empty($arrayfields[
'aa.active'][
'checked'])) {
442 print
'<td class="liste_titre"> </td>';
444 print
'<td class="liste_titre maxwidthsearch">';
445 $searchpicto =
$form->showFilterButtons();
449 print
'<tr class="liste_titre">';
450 if (!empty($arrayfields[
'aa.account_number'][
'checked'])) {
451 print_liste_field_titre($arrayfields[
'aa.account_number'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.account_number",
"", $param,
'', $sortfield, $sortorder);
453 if (!empty($arrayfields[
'aa.label'][
'checked'])) {
454 print_liste_field_titre($arrayfields[
'aa.label'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.label",
"", $param,
'', $sortfield, $sortorder);
456 if (!empty($arrayfields[
'aa.labelshort'][
'checked'])) {
457 print_liste_field_titre($arrayfields[
'aa.labelshort'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.labelshort",
"", $param,
'', $sortfield, $sortorder);
459 if (!empty($arrayfields[
'aa.account_parent'][
'checked'])) {
460 print_liste_field_titre($arrayfields[
'aa.account_parent'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.account_parent",
"", $param,
'', $sortfield, $sortorder,
'left ');
462 if (!empty($arrayfields[
'aa.pcg_type'][
'checked'])) {
463 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);
465 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
466 if (!empty($arrayfields[
'aa.reconcilable'][
'checked'])) {
467 print_liste_field_titre($arrayfields[
'aa.reconcilable'][
'label'], $_SERVER[
"PHP_SELF"],
'aa.reconcilable',
'', $param,
'', $sortfield, $sortorder);
470 if (!empty($arrayfields[
'aa.active'][
'checked'])) {
471 print_liste_field_titre($arrayfields[
'aa.active'][
'label'], $_SERVER[
"PHP_SELF"],
'aa.active',
'', $param,
'', $sortfield, $sortorder);
473 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
477 while ($i < min($num, $limit)) {
478 $obj = $db->fetch_object(
$resql);
480 $accountstatic->id = $obj->rowid;
481 $accountstatic->label = $obj->label;
482 $accountstatic->account_number = $obj->account_number;
484 print
'<tr class="oddeven">';
487 if (!empty($arrayfields[
'aa.account_number'][
'checked'])) {
489 print $accountstatic->getNomUrl(1, 0, 0,
'', 0, 1, 0,
'accountcard');
492 $totalarray[
'nbfield']++;
497 if (!empty($arrayfields[
'aa.label'][
'checked'])) {
502 $totalarray[
'nbfield']++;
507 if (!empty($arrayfields[
'aa.labelshort'][
'checked'])) {
509 print $obj->labelshort;
512 $totalarray[
'nbfield']++;
517 if (!empty($arrayfields[
'aa.account_parent'][
'checked'])) {
520 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
522 print
'<!-- obj->account_parent = '.$obj->account_parent.
' obj->rowid2 = '.$obj->rowid2.
' -->';
523 $accountparent->id = $obj->rowid2;
524 $accountparent->label = $obj->label2;
525 $accountparent->account_number = $obj->account_number2;
526 print $accountparent->getNomUrl(1);
529 $totalarray[
'nbfield']++;
533 if (!empty($obj->account_parent)) {
534 print
'<!-- Bad value for obj->account_parent = '.$obj->account_parent.
': is a rowid that does not exists -->';
538 $totalarray[
'nbfield']++;
544 if (!empty($arrayfields[
'aa.pcg_type'][
'checked'])) {
546 print $obj->pcg_type;
549 $totalarray[
'nbfield']++;
553 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
555 if (!empty($arrayfields[
'aa.reconcilable'][
'checked'])) {
556 print
'<td class="center">';
557 if (empty($obj->reconcilable)) {
558 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=enable&mode=1&token='.
newToken().
'">';
559 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
562 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=disable&mode=1&token='.
newToken().
'">';
563 print
img_picto($langs->trans(
"Activated"),
'switch_on');
568 $totalarray[
'nbfield']++;
574 if (!empty($arrayfields[
'aa.active'][
'checked'])) {
575 print
'<td class="center">';
576 if (empty($obj->active)) {
577 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=enable&mode=0&token='.
newToken().
'">';
578 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
581 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=disable&mode=0&token='.
newToken().
'">';
582 print
img_picto($langs->trans(
"Activated"),
'switch_on');
587 $totalarray[
'nbfield']++;
592 print
'<td class="center nowraponall">';
593 if ($user->rights->accounting->chartofaccount) {
594 print
'<a class="editfielda" href="./card.php?action=update&token='.newToken().
'&id='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'">';
598 print
'<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().
'&id='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'">';
602 if ($massactionbutton || $massaction) {
604 if (in_array($obj->rowid, $arrayofselected)) {
607 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
612 $totalarray[
'nbfield']++;
621 foreach ($arrayfields as $key => $val) {
622 if (!empty($val[
'checked'])) {
626 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';