account.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("compta", "bills", "admin", "accountancy", "salaries"));
  31. $mesg = '';
  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. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search
  38. $search_account = GETPOST('search_account', 'alpha');
  39. $search_label = GETPOST('search_label', 'alpha');
  40. $search_labelshort = GETPOST('search_labelshort', 'alpha');
  41. $search_accountparent = GETPOST('search_accountparent', 'alpha');
  42. $search_pcgtype = GETPOST('search_pcgtype', 'alpha');
  43. $chartofaccounts = GETPOST('chartofaccounts', 'int');
  44. // Security check
  45. if ($user->socid > 0) accessforbidden();
  46. if (!$user->rights->accounting->chartofaccount) accessforbidden();
  47. // Load variable for pagination
  48. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'alpha');
  50. $sortorder = GETPOST('sortorder', 'alpha');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!$sortfield) $sortfield = "aa.account_number";
  57. if (!$sortorder) $sortorder = "ASC";
  58. $arrayfields = array(
  59. 'aa.account_number'=>array('label'=>$langs->trans("AccountNumber"), 'checked'=>1),
  60. 'aa.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
  61. 'aa.labelshort'=>array('label'=>$langs->trans("LabelToShow"), 'checked'=>1),
  62. 'aa.account_parent'=>array('label'=>$langs->trans("Accountparent"), 'checked'=>1),
  63. 'aa.pcg_type'=>array('label'=>$langs->trans("Pcgtype"), 'checked'=>1, 'help'=>'PcgtypeDesc'),
  64. 'aa.reconcilable'=>array('label'=>$langs->trans("Reconcilable"), 'checked'=>1),
  65. 'aa.active'=>array('label'=>$langs->trans("Activated"), 'checked'=>1)
  66. );
  67. if ($conf->global->MAIN_FEATURES_LEVEL < 2) unset($arrayfields['aa.reconcilable']);
  68. $accounting = new AccountingAccount($db);
  69. /*
  70. * Actions
  71. */
  72. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  73. if (!GETPOST('confirmmassaction', 'alpha')) { $massaction = ''; }
  74. $parameters = array();
  75. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. if (empty($reshook))
  78. {
  79. if (!empty($cancel)) $action = '';
  80. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  81. 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
  82. {
  83. $search_account = "";
  84. $search_label = "";
  85. $search_labelshort = "";
  86. $search_accountparent = "";
  87. $search_pcgtype = "";
  88. $search_array_options = array();
  89. }
  90. if ((GETPOST('valid_change_chart', 'alpha') && GETPOST('chartofaccounts', 'int') > 0) // explicit click on button 'Change and load' with js on
  91. || (GETPOST('chartofaccounts', 'int') > 0 && GETPOST('chartofaccounts', 'int') != $conf->global->CHARTOFACCOUNTS)) // a submit of form is done and chartofaccounts combo has been modified
  92. {
  93. if ($chartofaccounts > 0)
  94. {
  95. // Get language code for this $chartofaccounts
  96. $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
  97. $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
  98. $resql = $db->query($sql);
  99. if ($resql)
  100. {
  101. $obj = $db->fetch_object($resql);
  102. $country_code = $obj->code;
  103. }
  104. else dol_print_error($db);
  105. // Try to load sql file
  106. if ($country_code)
  107. {
  108. $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
  109. $offsetforchartofaccount = 0;
  110. // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
  111. // 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.
  112. // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
  113. $tmp = file_get_contents($sqlfile);
  114. if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg))
  115. {
  116. $offsetforchartofaccount += $reg[1];
  117. }
  118. $offsetforchartofaccount += ($conf->entity * 100000000);
  119. $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
  120. if ($result > 0)
  121. {
  122. setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
  123. }
  124. else
  125. {
  126. setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
  127. }
  128. }
  129. if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
  130. $error++;
  131. }
  132. } else {
  133. $error++;
  134. }
  135. }
  136. if ($action == 'disable') {
  137. if ($accounting->fetch($id)) {
  138. $mode = GETPOST('mode', 'int');
  139. $result = $accounting->account_desactivate($id, $mode);
  140. }
  141. $action = 'update';
  142. if ($result < 0) {
  143. setEventMessages($accounting->error, $accounting->errors, 'errors');
  144. }
  145. } elseif ($action == 'enable') {
  146. if ($accounting->fetch($id)) {
  147. $mode = GETPOST('mode', 'int');
  148. $result = $accounting->account_activate($id, $mode);
  149. }
  150. $action = 'update';
  151. if ($result < 0) {
  152. setEventMessages($accounting->error, $accounting->errors, 'errors');
  153. }
  154. }
  155. }
  156. /*
  157. * View
  158. */
  159. $form = new Form($db);
  160. $formaccounting = new FormAccounting($db);
  161. llxHeader('', $langs->trans("ListAccounts"));
  162. if ($action == 'delete') {
  163. $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
  164. print $formconfirm;
  165. }
  166. $pcgver = $conf->global->CHARTOFACCOUNTS;
  167. $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, ";
  168. $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
  169. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
  170. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".$conf->entity;
  171. if ($db->type == 'pgsql') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".$conf->entity;
  172. else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".$conf->entity;
  173. $sql .= " WHERE asy.rowid = ".$pcgver;
  174. //print $sql;
  175. if (strlen(trim($search_account))) {
  176. $lengthpaddingaccount = 0;
  177. if ($conf->global->ACCOUNTING_LENGTH_GACCOUNT || $conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
  178. $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_GACCOUNT, $conf->global->ACCOUNTING_LENGTH_AACCOUNT);
  179. }
  180. $search_account_tmp = $search_account;
  181. $weremovedsomezero = 0;
  182. if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
  183. for ($i = 0; $i < $lengthpaddingaccount; $i++) {
  184. if (preg_match('/0$/', $search_account_tmp)) {
  185. $weremovedsomezero++;
  186. $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
  187. }
  188. }
  189. }
  190. //var_dump($search_account); exit;
  191. if ($search_account_tmp) {
  192. if ($weremovedsomezero) {
  193. $search_account_tmp_clean = $search_account_tmp;
  194. $search_account_clean = $search_account;
  195. $startchar = '%';
  196. if (strpos($search_account_tmp, '^') === 0)
  197. {
  198. $startchar = '';
  199. $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
  200. $search_account_clean = preg_replace('/^\^/', '', $search_account);
  201. }
  202. $sql .= " AND (aa.account_number LIKE '".$startchar.$search_account_tmp_clean."'";
  203. $sql .= " OR aa.account_number LIKE '".$startchar.$search_account_clean."%')";
  204. }
  205. else $sql .= natural_search("aa.account_number", $search_account_tmp);
  206. }
  207. }
  208. if (strlen(trim($search_label))) $sql .= natural_search("aa.label", $search_label);
  209. if (strlen(trim($search_labelshort))) $sql .= natural_search("aa.labelshort", $search_labelshort);
  210. if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
  211. if (strlen(trim($search_pcgtype))) $sql .= natural_search("aa.pcg_type", $search_pcgtype);
  212. $sql .= $db->order($sortfield, $sortorder);
  213. // Count total nb of records
  214. $nbtotalofrecords = '';
  215. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  216. {
  217. $resql = $db->query($sql);
  218. $nbtotalofrecords = $db->num_rows($resql);
  219. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  220. {
  221. $page = 0;
  222. $offset = 0;
  223. }
  224. }
  225. $sql .= $db->plimit($limit + 1, $offset);
  226. dol_syslog('accountancy/admin/account.php:: $sql='.$sql);
  227. $resql = $db->query($sql);
  228. if ($resql)
  229. {
  230. $num = $db->num_rows($resql);
  231. $param = '';
  232. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
  233. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
  234. if ($search_account) $param .= '&search_account='.urlencode($search_account);
  235. if ($search_label) $param .= '&search_label='.urlencode($search_label);
  236. if ($search_labelshort) $param .= '&search_labelshort='.urlencode($search_labelshort);
  237. if ($search_accountparent > 0 || $search_accountparent == '0') $param .= '&search_accountparent='.urlencode($search_accountparent);
  238. if ($search_pcgtype) $param .= '&search_pcgtype='.urlencode($search_pcgtype);
  239. if ($optioncss != '') $param .= '&optioncss='.$optioncss;
  240. if (!empty($conf->use_javascript_ajax))
  241. {
  242. print '<!-- Add javascript to reload page when we click "Change plan" -->
  243. <script type="text/javascript">
  244. $(document).ready(function () {
  245. $("#change_chart").on("click", function (e) {
  246. console.log("chartofaccounts seleted = "+$("#chartofaccounts").val());
  247. // reload page
  248. window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
  249. });
  250. });
  251. </script>';
  252. }
  253. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  254. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  255. print '<input type="hidden" name="token" value="'.newToken().'">';
  256. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  257. print '<input type="hidden" name="action" value="list">';
  258. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  259. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  260. print '<input type="hidden" name="page" value="'.$page.'">';
  261. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  262. $newcardbutton .= dolGetButtonTitle($langs->trans("New"), $langs->trans("Addanaccount"), 'fa fa-plus-circle', './card.php?action=create');
  263. print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit);
  264. // Box to select active chart of account
  265. print $langs->trans("Selectchartofaccounts")." : ";
  266. print '<select class="flat" name="chartofaccounts" id="chartofaccounts">';
  267. $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
  268. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
  269. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
  270. $sql .= " WHERE a.active = 1";
  271. dol_syslog('accountancy/admin/account.php $sql='.$sql);
  272. print $sql;
  273. $resqlchart = $db->query($sql);
  274. if ($resqlchart) {
  275. $numbis = $db->num_rows($resqlchart);
  276. $i = 0;
  277. while ($i < $numbis) {
  278. $obj = $db->fetch_object($resqlchart);
  279. print '<option value="'.$obj->rowid.'"';
  280. print ($pcgver == $obj->rowid) ? ' selected' : '';
  281. print '>'.$obj->pcg_version.' - '.$obj->label.' - ('.$obj->country_code.')</option>';
  282. $i++;
  283. }
  284. }
  285. else dol_print_error($db);
  286. print "</select>";
  287. print ajax_combobox("chartofaccounts");
  288. print '<input type="'.(empty($conf->use_javascript_ajax) ? 'submit' : 'button').'" class="button" name="change_chart" id="change_chart" value="'.dol_escape_htmltag($langs->trans("ChangeAndLoad")).'">';
  289. print '<br>';
  290. print '<br>';
  291. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  292. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  293. $moreforfilter = '';
  294. $massactionbutton = '';
  295. print '<div class="div-table-responsive">';
  296. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  297. // Line for search fields
  298. print '<tr class="liste_titre_filter">';
  299. if (!empty($arrayfields['aa.account_number']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_account" value="'.$search_account.'"></td>';
  300. if (!empty($arrayfields['aa.label']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="'.$search_label.'"></td>';
  301. if (!empty($arrayfields['aa.labelshort']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_labelshort" value="'.$search_labelshort.'"></td>';
  302. if (!empty($arrayfields['aa.account_parent']['checked'])) {
  303. print '<td class="liste_titre">';
  304. print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2);
  305. print '</td>';
  306. }
  307. if (!empty($arrayfields['aa.pcg_type']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
  308. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { if (!empty($arrayfields['aa.reconcilable']['checked'])) print '<td class="liste_titre">&nbsp;</td>'; }
  309. if (!empty($arrayfields['aa.active']['checked'])) print '<td class="liste_titre">&nbsp;</td>';
  310. print '<td class="liste_titre maxwidthsearch">';
  311. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  312. print $searchpicto;
  313. print '</td>';
  314. print '</tr>';
  315. print '<tr class="liste_titre">';
  316. if (!empty($arrayfields['aa.account_number']['checked'])) print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
  317. if (!empty($arrayfields['aa.label']['checked'])) print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
  318. if (!empty($arrayfields['aa.labelshort']['checked'])) print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
  319. if (!empty($arrayfields['aa.account_parent']['checked'])) print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
  320. if (!empty($arrayfields['aa.pcg_type']['checked'])) print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help']);
  321. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { if (!empty($arrayfields['aa.reconcilable']['checked'])) print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder); }
  322. if (!empty($arrayfields['aa.active']['checked'])) print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder);
  323. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  324. print "</tr>\n";
  325. $accountstatic = new AccountingAccount($db);
  326. $accountparent = new AccountingAccount($db);
  327. $totalarray = array();
  328. $i = 0;
  329. while ($i < min($num, $limit))
  330. {
  331. $obj = $db->fetch_object($resql);
  332. $accountstatic->id = $obj->rowid;
  333. $accountstatic->label = $obj->label;
  334. $accountstatic->account_number = $obj->account_number;
  335. print '<tr class="oddeven">';
  336. // Account number
  337. if (!empty($arrayfields['aa.account_number']['checked']))
  338. {
  339. print "<td>";
  340. print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1);
  341. print "</td>\n";
  342. if (!$i) $totalarray['nbfield']++;
  343. }
  344. // Account label
  345. if (!empty($arrayfields['aa.label']['checked']))
  346. {
  347. print "<td>";
  348. print $obj->label;
  349. print "</td>\n";
  350. if (!$i) $totalarray['nbfield']++;
  351. }
  352. // Account label to show (label short)
  353. if (!empty($arrayfields['aa.labelshort']['checked']))
  354. {
  355. print "<td>";
  356. print $obj->labelshort;
  357. print "</td>\n";
  358. if (!$i) $totalarray['nbfield']++;
  359. }
  360. // Account parent
  361. if (!empty($arrayfields['aa.account_parent']['checked']))
  362. {
  363. if (!empty($obj->account_parent))
  364. {
  365. $accountparent->id = $obj->rowid2;
  366. $accountparent->label = $obj->label2;
  367. $accountparent->account_number = $obj->account_number2;
  368. print "<td>";
  369. print $accountparent->getNomUrl(1);
  370. print "</td>\n";
  371. if (!$i) $totalarray['nbfield']++;
  372. }
  373. else
  374. {
  375. print '<td>&nbsp;</td>';
  376. if (!$i) $totalarray['nbfield']++;
  377. }
  378. }
  379. // Chart of accounts type
  380. if (!empty($arrayfields['aa.pcg_type']['checked']))
  381. {
  382. print "<td>";
  383. print $obj->pcg_type;
  384. print "</td>\n";
  385. if (!$i) $totalarray['nbfield']++;
  386. }
  387. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  388. // Activated or not reconciliation on accounting account
  389. if (!empty($arrayfields['aa.reconcilable']['checked'])) {
  390. print '<td class="center">';
  391. if (empty($obj->reconcilable)) {
  392. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=1">';
  393. print img_picto($langs->trans("Disabled"), 'switch_off');
  394. print '</a>';
  395. } else {
  396. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=1">';
  397. print img_picto($langs->trans("Activated"), 'switch_on');
  398. print '</a>';
  399. }
  400. print '</td>';
  401. if (!$i) {
  402. $totalarray['nbfield']++;
  403. }
  404. }
  405. }
  406. // Activated or not
  407. if (!empty($arrayfields['aa.active']['checked']))
  408. {
  409. print '<td class="center">';
  410. if (empty($obj->active)) {
  411. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=0">';
  412. print img_picto($langs->trans("Disabled"), 'switch_off');
  413. print '</a>';
  414. } else {
  415. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=0">';
  416. print img_picto($langs->trans("Activated"), 'switch_on');
  417. print '</a>';
  418. }
  419. print '</td>';
  420. if (!$i) $totalarray['nbfield']++;
  421. }
  422. // Action
  423. print '<td class="center">';
  424. if ($user->rights->accounting->chartofaccount) {
  425. print '<a href="./card.php?action=update&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?chartofaccounts='.$object->id).'">';
  426. print img_edit();
  427. print '</a>';
  428. print '&nbsp;';
  429. print '<a href="./card.php?action=delete&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?chartofaccounts='.$object->id).'">';
  430. print img_delete();
  431. print '</a>';
  432. }
  433. print '</td>'."\n";
  434. if (!$i) $totalarray['nbfield']++;
  435. print "</tr>\n";
  436. $i++;
  437. }
  438. print "</table>";
  439. print "</div>";
  440. print '</form>';
  441. } else {
  442. dol_print_error($db);
  443. }
  444. // End of page
  445. llxFooter();
  446. $db->close();