list.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/bank/list.php
  24. * \ingroup banque
  25. * \brief Home page of bank module
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  33. if (!empty($conf->accounting->enabled)) {
  34. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  35. }
  36. if (!empty($conf->accounting->enabled)) {
  37. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  38. }
  39. if (!empty($conf->categorie->enabled)) {
  40. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  41. }
  42. // Load translation files required by the page
  43. $langs->loadLangs(array('banks', 'categories', 'accountancy', 'compta'));
  44. $action = GETPOST('action', 'aZ09');
  45. $massaction = GETPOST('massaction', 'alpha');
  46. $show_files = GETPOST('show_files', 'int');
  47. $confirm = GETPOST('confirm', 'alpha');
  48. $toselect = GETPOST('toselect', 'array');
  49. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bankaccountlist'; // To manage different context of search
  50. $search_ref = GETPOST('search_ref', 'alpha');
  51. $search_label = GETPOST('search_label', 'alpha');
  52. $search_number = GETPOST('search_number', 'alpha');
  53. $search_status = GETPOST('search_status') ?GETPOST('search_status', 'alpha') : 'opened'; // 'all' or ''='opened'
  54. $optioncss = GETPOST('optioncss', 'alpha');
  55. if (!empty($conf->categorie->enabled)) {
  56. $search_category_list = GETPOST("search_category_".Categorie::TYPE_ACCOUNT."_list", "array");
  57. }
  58. $socid = 0;
  59. // Security check
  60. if ($user->socid) {
  61. $socid = $user->socid;
  62. }
  63. $allowed = 0;
  64. if (!empty($user->rights->accounting->chartofaccount)) {
  65. $allowed = 1; // Dictionary with list of banks accounting account allowed to manager of chart account
  66. }
  67. if (!$allowed) {
  68. $result = restrictedArea($user, 'banque');
  69. }
  70. $diroutputmassaction = $conf->bank->dir_output.'/temp/massgeneration/'.$user->id;
  71. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  72. $sortfield = GETPOST('sortfield', 'aZ09comma');
  73. $sortorder = GETPOST('sortorder', 'aZ09comma');
  74. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  75. if (empty($page) || $page == -1) {
  76. $page = 0;
  77. } // If $page is not defined, or '' or -1
  78. $offset = $limit * $page;
  79. $pageprev = $page - 1;
  80. $pagenext = $page + 1;
  81. if (!$sortfield) {
  82. $sortfield = 'b.label';
  83. }
  84. if (!$sortorder) {
  85. $sortorder = 'ASC';
  86. }
  87. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  88. $object = new Account($db);
  89. $extrafields = new ExtraFields($db);
  90. $hookmanager->initHooks(array('bankaccountlist'));
  91. // fetch optionals attributes and labels
  92. $extrafields->fetch_name_optionals_label($object->table_element);
  93. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  94. // List of fields to search into when doing a "search in all"
  95. $fieldstosearchall = array(
  96. 'b.ref'=>'Ref',
  97. 'b.label'=>'Label',
  98. );
  99. $checkedtypetiers = 0;
  100. $arrayfields = array(
  101. 'b.ref'=>array('label'=>$langs->trans("BankAccounts"), 'checked'=>1, 'position'=>10),
  102. 'b.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1, 'position'=>12),
  103. 'accountype'=>array('label'=>$langs->trans("Type"), 'checked'=>1, 'position'=>14),
  104. 'b.number'=>array('label'=>$langs->trans("AccountIdShort"), 'checked'=>1, 'position'=>16),
  105. 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>(!empty($conf->accounting->enabled) || !empty($conf->accounting->enabled)), 'position'=>18),
  106. 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>(!empty($conf->accounting->enabled) || !empty($conf->accounting->enabled)), 'position'=>20),
  107. 'toreconcile'=>array('label'=>$langs->trans("TransactionsToConciliate"), 'checked'=>1, 'position'=>50),
  108. 'b.currency_code'=>array('label'=>$langs->trans("Currency"), 'checked'=>0, 'position'=>22),
  109. 'b.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  110. 'b.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  111. 'b.clos'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  112. 'balance'=>array('label'=>$langs->trans("Balance"), 'checked'=>1, 'position'=>1010),
  113. );
  114. // Extra fields
  115. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  116. $object->fields = dol_sort_array($object->fields, 'position');
  117. $arrayfields = dol_sort_array($arrayfields, 'position');
  118. $permissiontoadd = $user->rights->banque->modifier;
  119. $permissiontodelete = $user->rights->banque->configurer;
  120. /*
  121. * Actions
  122. */
  123. if (GETPOST('cancel', 'alpha')) {
  124. $action = 'list';
  125. $massaction = '';
  126. }
  127. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  128. $massaction = '';
  129. }
  130. $parameters = array('socid'=>$socid);
  131. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  132. if ($reshook < 0) {
  133. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  134. }
  135. if (empty($reshook)) {
  136. include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
  137. // Purge search criteria
  138. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  139. $search_ref = '';
  140. $search_label = '';
  141. $search_number = '';
  142. $search_status = '';
  143. }
  144. // Mass actions
  145. $objectclass = 'Account';
  146. $objectlabel = 'FinancialAccount';
  147. $uploaddir = $conf->banque->dir_output;
  148. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  149. }
  150. /*
  151. * View
  152. */
  153. $form = new FormCategory($db);
  154. $title = $langs->trans('BankAccounts');
  155. // Load array of financial accounts (opened by default)
  156. $accounts = array();
  157. $sql = "SELECT b.rowid, b.label, b.courant, b.rappro, b.account_number, b.fk_accountancy_journal, b.currency_code, b.datec as date_creation, b.tms as date_update";
  158. // Add fields from extrafields
  159. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  160. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  161. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  162. }
  163. }
  164. // Add fields from hooks
  165. $parameters = array();
  166. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  167. $sql .= $hookmanager->resPrint;
  168. $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
  169. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  170. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
  171. }
  172. if (!empty($conf->categorie->enabled)) {
  173. $sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_ACCOUNT, "b.rowid");
  174. }
  175. $sql .= " WHERE b.entity IN (".getEntity('bank_account').")";
  176. if ($search_status == 'opened') {
  177. $sql .= " AND clos = 0";
  178. }
  179. if ($search_status == 'closed') {
  180. $sql .= " AND clos = 1";
  181. }
  182. if (!empty($conf->categorie->enabled)) {
  183. $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_ACCOUNT, "b.rowid", $search_category_list);
  184. }
  185. if ($search_ref != '') {
  186. $sql .= natural_search('b.ref', $search_ref);
  187. }
  188. if ($search_label != '') {
  189. $sql .= natural_search('b.label', $search_label);
  190. }
  191. if ($search_number != '') {
  192. $sql .= natural_search('b.number', $search_number);
  193. }
  194. // Add where from extra fields
  195. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  196. // Add where from hooks
  197. $parameters = array();
  198. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  199. $sql .= $hookmanager->resPrint;
  200. $sql .= $db->order($sortfield, $sortorder);
  201. // Count total nb of records
  202. $nbtotalofrecords = '';
  203. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  204. $result = $db->query($sql);
  205. $nbtotalofrecords = $db->num_rows($result);
  206. }
  207. $sql .= $db->plimit($limit + 1, $offset);
  208. $resql = $db->query($sql);
  209. if ($resql) {
  210. $num = $db->num_rows($resql);
  211. $i = 0;
  212. while ($i < $num) {
  213. $objp = $db->fetch_object($resql);
  214. $accounts[$objp->rowid] = $objp->courant;
  215. $i++;
  216. }
  217. $db->free($resql);
  218. } else {
  219. dol_print_error($db);
  220. }
  221. $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
  222. llxHeader('', $title, $help_url);
  223. $arrayofselected = is_array($toselect) ? $toselect : array();
  224. $param = '';
  225. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  226. $param .= '&contextpage='.urlencode($contextpage);
  227. }
  228. if ($limit > 0 && $limit != $conf->liste_limit) {
  229. $param .= '&limit='.urlencode($limit);
  230. }
  231. if ($search_ref != '') {
  232. $param .= '&search_ref='.urlencode($search_ref);
  233. }
  234. if ($search_label != '') {
  235. $param .= '&search_label='.urlencode($search_label);
  236. }
  237. if ($search_number != '') {
  238. $param .= '&search_number='.urlencode($search_number);
  239. }
  240. if ($search_status != '') {
  241. $param .= '&search_status='.urlencode($search_status);
  242. }
  243. if ($show_files) {
  244. $param .= '&show_files='.urlencode($show_files);
  245. }
  246. if ($optioncss != '') {
  247. $param .= '&optioncss='.urlencode($optioncss);
  248. }
  249. // Add $param from extra fields
  250. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  251. // Add $param from hooks
  252. $parameters = array();
  253. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  254. $param .= $hookmanager->resPrint;
  255. // List of mass actions available
  256. $arrayofmassactions = array(
  257. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  258. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  259. );
  260. if ($permissiontodelete) {
  261. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  262. }
  263. if ($user->rights->banque->modifier) {
  264. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  265. }
  266. if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  267. $arrayofmassactions = array();
  268. }
  269. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  270. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  271. if ($optioncss != '') {
  272. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  273. }
  274. print '<input type="hidden" name="token" value="'.newToken().'">';
  275. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  276. print '<input type="hidden" name="action" value="list">';
  277. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  278. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  279. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  280. print '<input type="hidden" name="page" value="'.$page.'">';
  281. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  282. $newcardbutton = dolGetButtonTitle($langs->trans('NewFinancialAccount'), '', 'fa fa-plus-circle', 'card.php?action=create', '', $user->rights->banque->configurer);
  283. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit, 1);
  284. $topicmail = "Information";
  285. //$modelmail="subscription";
  286. $objecttmp = new Account($db);
  287. $trackid = 'bank'.$object->id;
  288. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  289. //if ($sall) {
  290. // foreach ($fieldstosearchall as $key => $val) {
  291. // $fieldstosearchall[$key] = $langs->trans($val);
  292. // }
  293. // print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  294. //}
  295. $moreforfilter = '';
  296. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  297. $moreforfilter .= $form->getFilterBox(Categorie::TYPE_ACCOUNT, $search_category_list);
  298. }
  299. // Bank accounts
  300. $parameters = array();
  301. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  302. if (empty($reshook)) {
  303. $moreforfilter .= $hookmanager->resPrint;
  304. } else {
  305. $moreforfilter = $hookmanager->resPrint;
  306. }
  307. if (!empty($moreforfilter)) {
  308. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  309. print $moreforfilter;
  310. print '</div>';
  311. }
  312. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  313. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  314. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  315. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  316. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  317. // Fields title search
  318. // --------------------------------------------------------------------
  319. print '<tr class="liste_titre">';
  320. // Ref
  321. if (!empty($arrayfields['b.ref']['checked'])) {
  322. print '<td class="liste_titre">';
  323. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  324. print '</td>';
  325. }
  326. // Label
  327. if (!empty($arrayfields['b.label']['checked'])) {
  328. print '<td class="liste_titre">';
  329. print '<input class="flat" size="6" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  330. print '</td>';
  331. }
  332. // Account type
  333. if (!empty($arrayfields['accountype']['checked'])) {
  334. print '<td class="liste_titre">';
  335. print '</td>';
  336. }
  337. // Bank number
  338. if (!empty($arrayfields['b.number']['checked'])) {
  339. print '<td class="liste_titre">';
  340. print '<input class="flat" size="6" type="text" name="search_number" value="'.dol_escape_htmltag($search_number).'">';
  341. print '</td>';
  342. }
  343. // Account number
  344. if (!empty($arrayfields['b.account_number']['checked'])) {
  345. print '<td class="liste_titre">';
  346. print '</td>';
  347. }
  348. // Accountancy journal
  349. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  350. print '<td class="liste_titre">';
  351. print '</td>';
  352. }
  353. // Transactions to reconcile
  354. if (!empty($arrayfields['toreconcile']['checked'])) {
  355. print '<td class="liste_titre">';
  356. print '</td>';
  357. }
  358. // Currency
  359. if (!empty($arrayfields['b.currency_code']['checked'])) {
  360. print '<td class="liste_titre">';
  361. print '</td>';
  362. }
  363. // Extra fields
  364. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  365. // Fields from hook
  366. $parameters = array('arrayfields'=>$arrayfields);
  367. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  368. print $hookmanager->resPrint;
  369. // Date creation
  370. if (!empty($arrayfields['b.datec']['checked'])) {
  371. print '<td class="liste_titre">';
  372. print '</td>';
  373. }
  374. // Date modification
  375. if (!empty($arrayfields['b.tms']['checked'])) {
  376. print '<td class="liste_titre">';
  377. print '</td>';
  378. }
  379. // Status
  380. if (!empty($arrayfields['b.clos']['checked'])) {
  381. print '<td class="liste_titre center">';
  382. $array = array(
  383. 'opened'=>$langs->trans("Opened"),
  384. 'closed'=>$langs->trans("Closed")
  385. );
  386. print $form->selectarray("search_status", $array, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
  387. print '</td>';
  388. }
  389. // Balance
  390. if (!empty($arrayfields['balance']['checked'])) {
  391. print '<td class="liste_titre"></td>';
  392. }
  393. // Action column
  394. print '<td class="liste_titre maxwidthsearch">';
  395. $searchpicto = $form->showFilterButtons();
  396. print $searchpicto;
  397. print '</td>';
  398. print '</tr>'."\n";
  399. // Fields title label
  400. // --------------------------------------------------------------------
  401. print '<tr class="liste_titre">';
  402. if (!empty($arrayfields['b.ref']['checked'])) {
  403. print_liste_field_titre($arrayfields['b.ref']['label'], $_SERVER["PHP_SELF"], 'b.ref', '', $param, '', $sortfield, $sortorder);
  404. }
  405. if (!empty($arrayfields['b.label']['checked'])) {
  406. print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER["PHP_SELF"], 'b.label', '', $param, '', $sortfield, $sortorder);
  407. }
  408. if (!empty($arrayfields['accountype']['checked'])) {
  409. print_liste_field_titre($arrayfields['accountype']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
  410. }
  411. if (!empty($arrayfields['b.number']['checked'])) {
  412. print_liste_field_titre($arrayfields['b.number']['label'], $_SERVER["PHP_SELF"], 'b.number', '', $param, '', $sortfield, $sortorder);
  413. }
  414. if (!empty($arrayfields['b.account_number']['checked'])) {
  415. print_liste_field_titre($arrayfields['b.account_number']['label'], $_SERVER["PHP_SELF"], 'b.account_number', '', $param, '', $sortfield, $sortorder);
  416. }
  417. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  418. print_liste_field_titre($arrayfields['b.fk_accountancy_journal']['label'], $_SERVER["PHP_SELF"], 'b.fk_accountancy_journal', '', $param, '', $sortfield, $sortorder);
  419. }
  420. if (!empty($arrayfields['b.currency_code']['checked'])) {
  421. print_liste_field_titre($arrayfields['b.currency_code']['label'], $_SERVER["PHP_SELF"], 'b.currency_code', '', $param, '', $sortfield, $sortorder, 'center ');
  422. }
  423. if (!empty($arrayfields['toreconcile']['checked'])) {
  424. print_liste_field_titre($arrayfields['toreconcile']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  425. }
  426. // Extra fields
  427. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  428. // Hook fields
  429. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  430. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  431. print $hookmanager->resPrint;
  432. if (!empty($arrayfields['b.datec']['checked'])) {
  433. print_liste_field_titre($arrayfields['b.datec']['label'], $_SERVER["PHP_SELF"], "b.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  434. }
  435. if (!empty($arrayfields['b.tms']['checked'])) {
  436. print_liste_field_titre($arrayfields['b.tms']['label'], $_SERVER["PHP_SELF"], "b.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  437. }
  438. if (!empty($arrayfields['b.clos']['checked'])) {
  439. print_liste_field_titre($arrayfields['b.clos']['label'], $_SERVER["PHP_SELF"], 'b.clos', '', $param, '', $sortfield, $sortorder, 'center ');
  440. }
  441. if (!empty($arrayfields['balance']['checked'])) {
  442. print_liste_field_titre($arrayfields['balance']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  443. }
  444. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  445. print "</tr>\n";
  446. $totalarray = array();
  447. $totalarray['nbfield'] = 0;
  448. $totalarray['val'] = array('balance'=>0);
  449. $total = array();
  450. $found = 0;
  451. $i = 0;
  452. $lastcurrencycode = '';
  453. foreach ($accounts as $key => $type) {
  454. if ($i >= $limit) {
  455. break;
  456. }
  457. $found++;
  458. $result = $objecttmp->fetch($key);
  459. $solde = $objecttmp->solde(1);
  460. if (!empty($lastcurrencycode) && $lastcurrencycode != $objecttmp->currency_code) {
  461. $lastcurrencycode = 'various'; // We found several different currencies
  462. }
  463. if ($lastcurrencycode != 'various') {
  464. $lastcurrencycode = $objecttmp->currency_code;
  465. }
  466. print '<tr class="oddeven">';
  467. // Ref
  468. if (!empty($arrayfields['b.ref']['checked'])) {
  469. print '<td class="nowrap">'.$objecttmp->getNomUrl(1).'</td>';
  470. if (!$i) {
  471. $totalarray['nbfield']++;
  472. }
  473. }
  474. // Label
  475. if (!empty($arrayfields['b.label']['checked'])) {
  476. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objecttmp->label).'">'.dol_escape_htmltag($objecttmp->label).'</td>';
  477. if (!$i) {
  478. $totalarray['nbfield']++;
  479. }
  480. }
  481. // Account type
  482. if (!empty($arrayfields['accountype']['checked'])) {
  483. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objecttmp->type_lib[$objecttmp->type]).'">';
  484. print $objecttmp->type_lib[$objecttmp->type];
  485. print '</td>';
  486. if (!$i) {
  487. $totalarray['nbfield']++;
  488. }
  489. }
  490. // Number
  491. if (!empty($arrayfields['b.number']['checked'])) {
  492. print '<td>'.dol_escape_htmltag($objecttmp->number).'</td>';
  493. if (!$i) {
  494. $totalarray['nbfield']++;
  495. }
  496. }
  497. // Account number
  498. if (!empty($arrayfields['b.account_number']['checked'])) {
  499. print '<td class="tdoverflowmax250">';
  500. if (!empty($conf->accounting->enabled) && !empty($objecttmp->account_number)) {
  501. $accountingaccount = new AccountingAccount($db);
  502. $accountingaccount->fetch('', $objecttmp->account_number, 1);
  503. print '<span title="'.dol_escape_htmltag($accountingaccount->account_number.' - '.$accountingaccount->label).'">';
  504. print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
  505. print '</span>';
  506. } else {
  507. print '<span title="'.dol_escape_htmltag($objecttmp->account_number).'">'.$objecttmp->account_number.'</span>';
  508. }
  509. print '</td>';
  510. if (!$i) {
  511. $totalarray['nbfield']++;
  512. }
  513. }
  514. // Accountancy journal
  515. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  516. print '<td>';
  517. if (!empty($conf->accounting->enabled) && !empty($objecttmp->fk_accountancy_journal)) {
  518. $accountingjournal = new AccountingJournal($db);
  519. $accountingjournal->fetch($objecttmp->fk_accountancy_journal);
  520. print $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  521. } else {
  522. print '';
  523. }
  524. print '</td>';
  525. if (!$i) {
  526. $totalarray['nbfield']++;
  527. }
  528. }
  529. // Currency
  530. if (!empty($arrayfields['b.currency_code']['checked'])) {
  531. print '<td class="center">';
  532. print $objecttmp->currency_code;
  533. print '</td>';
  534. if (!$i) {
  535. $totalarray['nbfield']++;
  536. }
  537. }
  538. // Transactions to reconcile
  539. if (!empty($arrayfields['toreconcile']['checked'])) {
  540. print '<td class="center">';
  541. $conciliate = $objecttmp->canBeConciliated();
  542. if ($conciliate == -2) {
  543. print '<span class="opacitymedium">'.$langs->trans("CashAccount").'</span>';
  544. } elseif ($conciliate == -3) {
  545. print '<span class="opacitymedium">'.$langs->trans("Closed").'</span>';
  546. } elseif (empty($objecttmp->rappro)) {
  547. print '<span class="opacitymedium">'.$langs->trans("ConciliationDisabled").'</span>';
  548. } else {
  549. $result = $objecttmp->load_board($user, $objecttmp->id);
  550. if ($result < 0) {
  551. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  552. } else {
  553. print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&id='.$objecttmp->id.'&search_account='.$objecttmp->id.'&search_conciliated=0&contextpage=banktransactionlist">';
  554. print '<span class="badge badge-info classfortooltip" title="'.dol_htmlentities($langs->trans("TransactionsToConciliate")).'">';
  555. print $result->nbtodo;
  556. print '</span>';
  557. print '</a>';
  558. if ($result->nbtodolate) {
  559. print '<span title="'.dol_htmlentities($langs->trans("Late")).'" class="classfortooltip badge badge-danger marginleftonlyshort">';
  560. print '<i class="fa fa-exclamation-triangle"></i> '.$result->nbtodolate;
  561. print '</span>';
  562. }
  563. }
  564. }
  565. print '</td>';
  566. if (!$i) {
  567. $totalarray['nbfield']++;
  568. }
  569. }
  570. // Extra fields
  571. if (is_array($objecttmp->array_options)) {
  572. $obj = new stdClass();
  573. foreach ($objecttmp->array_options as $k => $v) {
  574. $obj->$k = $v;
  575. }
  576. }
  577. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  578. // Fields from hook
  579. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  580. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objecttmp); // Note that $action and $objecttmpect may have been modified by hook
  581. print $hookmanager->resPrint;
  582. // Date creation
  583. if (!empty($arrayfields['b.datec']['checked'])) {
  584. print '<td class="center">';
  585. print dol_print_date($objecttmp->date_creation, 'dayhour');
  586. print '</td>';
  587. if (!$i) {
  588. $totalarray['nbfield']++;
  589. }
  590. }
  591. // Date modification
  592. if (!empty($arrayfields['b.tms']['checked'])) {
  593. print '<td class="center">';
  594. print dol_print_date($objecttmp->date_update, 'dayhour');
  595. print '</td>';
  596. if (!$i) {
  597. $totalarray['nbfield']++;
  598. }
  599. }
  600. // Status
  601. if (!empty($arrayfields['b.clos']['checked'])) {
  602. print '<td class="center">'.$objecttmp->getLibStatut(5).'</td>';
  603. if (!$i) {
  604. $totalarray['nbfield']++;
  605. }
  606. }
  607. // Balance
  608. if (!empty($arrayfields['balance']['checked'])) {
  609. print '<td class="nowraponall right">';
  610. print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$objecttmp->id.'">';
  611. print '<span class="amount">'.price($solde, 0, $langs, 1, -1, -1, $objecttmp->currency_code).'</span>';
  612. print '</a>';
  613. print '</td>';
  614. if (!$i) {
  615. $totalarray['nbfield']++;
  616. }
  617. if (!$i) {
  618. $totalarray['pos'][$totalarray['nbfield']] = 'balance';
  619. }
  620. $totalarray['val']['balance'] += $solde;
  621. }
  622. // Action column
  623. print '<td class="nowrap center">';
  624. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  625. $selected = 0;
  626. if (in_array($objecttmp->id, $arrayofselected)) {
  627. $selected = 1;
  628. }
  629. print '<input id="cb'.$objecttmp->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$objecttmp->id.'"'.($selected ? ' checked="checked"' : '').'>';
  630. }
  631. print '</td>';
  632. if (!$i) {
  633. $totalarray['nbfield']++;
  634. }
  635. print '</tr>';
  636. if (empty($total[$objecttmp->currency_code])) {
  637. $total[$objecttmp->currency_code] = $solde;
  638. } else {
  639. $total[$objecttmp->currency_code] += $solde;
  640. }
  641. $i++;
  642. }
  643. // If no record found
  644. if (!$found) {
  645. $colspan = 1;
  646. foreach ($arrayfields as $key => $val) {
  647. if (!empty($val['checked'])) {
  648. $colspan++;
  649. }
  650. }
  651. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  652. }
  653. // Show total line
  654. if ($lastcurrencycode != 'various') { // If there is several currency, $lastcurrencycode is set to 'various' before
  655. // Show total line
  656. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  657. }
  658. print '</table>';
  659. print "</div>";
  660. print "</form>";
  661. // End of page
  662. llxFooter();
  663. $db->close();