account.php 31 KB

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