list.php 31 KB

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