list.php 32 KB

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