account.php 26 KB

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