list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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->hasRight('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 .= dolGetButtonTitleSeparator();
  334. $newcardbutton .= dolGetButtonTitle($langs->trans('NewFinancialAccount'), '', 'fa fa-plus-circle', 'card.php?action=create', '', $user->hasRight('banque', 'configurer'));
  335. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bank_account', 0, $newcardbutton, '', $limit, 1);
  336. $topicmail = "Information";
  337. //$modelmail="subscription";
  338. $objecttmp = new Account($db);
  339. $trackid = 'bank'.$object->id;
  340. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  341. //if ($sall) {
  342. // foreach ($fieldstosearchall as $key => $val) {
  343. // $fieldstosearchall[$key] = $langs->trans($val);
  344. // }
  345. // print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  346. //}
  347. $moreforfilter = '';
  348. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  349. $moreforfilter .= $form->getFilterBox(Categorie::TYPE_ACCOUNT, $search_category_list);
  350. }
  351. // Bank accounts
  352. $parameters = array();
  353. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  354. if (empty($reshook)) {
  355. $moreforfilter .= $hookmanager->resPrint;
  356. } else {
  357. $moreforfilter = $hookmanager->resPrint;
  358. }
  359. if (!empty($moreforfilter)) {
  360. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  361. print $moreforfilter;
  362. print '</div>';
  363. }
  364. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  365. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  366. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  367. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  368. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  369. // Fields title search
  370. // --------------------------------------------------------------------
  371. print '<tr class="liste_titre_filter">';
  372. // Action column
  373. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  374. print '<td class="liste_titre maxwidthsearch">';
  375. $searchpicto = $form->showFilterButtons('left');
  376. print $searchpicto;
  377. print '</td>';
  378. }
  379. // Ref
  380. if (!empty($arrayfields['b.ref']['checked'])) {
  381. print '<td class="liste_titre">';
  382. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  383. print '</td>';
  384. }
  385. // Label
  386. if (!empty($arrayfields['b.label']['checked'])) {
  387. print '<td class="liste_titre">';
  388. print '<input class="flat" size="6" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  389. print '</td>';
  390. }
  391. // Account type
  392. if (!empty($arrayfields['accountype']['checked'])) {
  393. print '<td class="liste_titre">';
  394. print '</td>';
  395. }
  396. // Bank number
  397. if (!empty($arrayfields['b.number']['checked'])) {
  398. print '<td class="liste_titre">';
  399. print '<input class="flat" size="6" type="text" name="search_number" value="'.dol_escape_htmltag($search_number).'">';
  400. print '</td>';
  401. }
  402. // Account number
  403. if (!empty($arrayfields['b.account_number']['checked'])) {
  404. print '<td class="liste_titre">';
  405. print '</td>';
  406. }
  407. // Accountancy journal
  408. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  409. print '<td class="liste_titre">';
  410. print '</td>';
  411. }
  412. // Transactions to reconcile
  413. if (!empty($arrayfields['toreconcile']['checked'])) {
  414. print '<td class="liste_titre">';
  415. print '</td>';
  416. }
  417. // Currency
  418. if (!empty($arrayfields['b.currency_code']['checked'])) {
  419. print '<td class="liste_titre">';
  420. print '</td>';
  421. }
  422. // Extra fields
  423. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  424. // Fields from hook
  425. $parameters = array('arrayfields'=>$arrayfields);
  426. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  427. print $hookmanager->resPrint;
  428. // Date creation
  429. if (!empty($arrayfields['b.datec']['checked'])) {
  430. print '<td class="liste_titre">';
  431. print '</td>';
  432. }
  433. // Date modification
  434. if (!empty($arrayfields['b.tms']['checked'])) {
  435. print '<td class="liste_titre">';
  436. print '</td>';
  437. }
  438. // Status
  439. if (!empty($arrayfields['b.clos']['checked'])) {
  440. print '<td class="liste_titre center parentonrightofpage">';
  441. $array = array(
  442. 'opened'=>$langs->trans("Opened"),
  443. 'closed'=>$langs->trans("Closed")
  444. );
  445. print $form->selectarray("search_status", $array, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status minwidth75 maxwidth125 onrightofpage', 1);
  446. print '</td>';
  447. }
  448. // Balance
  449. if (!empty($arrayfields['balance']['checked'])) {
  450. print '<td class="liste_titre"></td>';
  451. }
  452. // Action column
  453. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  454. print '<td class="liste_titre maxwidthsearch">';
  455. $searchpicto = $form->showFilterButtons();
  456. print $searchpicto;
  457. print '</td>';
  458. }
  459. print '</tr>'."\n";
  460. $totalarray = array();
  461. $totalarray['nbfield'] = 0;
  462. // Fields title label
  463. // --------------------------------------------------------------------
  464. print '<tr class="liste_titre">';
  465. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  466. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  467. $totalarray['nbfield']++;
  468. }
  469. if (!empty($arrayfields['b.ref']['checked'])) {
  470. print_liste_field_titre($arrayfields['b.ref']['label'], $_SERVER["PHP_SELF"], 'b.ref', '', $param, '', $sortfield, $sortorder);
  471. $totalarray['nbfield']++;
  472. }
  473. if (!empty($arrayfields['b.label']['checked'])) {
  474. print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER["PHP_SELF"], 'b.label', '', $param, '', $sortfield, $sortorder);
  475. $totalarray['nbfield']++;
  476. }
  477. if (!empty($arrayfields['accountype']['checked'])) {
  478. print_liste_field_titre($arrayfields['accountype']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
  479. $totalarray['nbfield']++;
  480. }
  481. if (!empty($arrayfields['b.number']['checked'])) {
  482. print_liste_field_titre($arrayfields['b.number']['label'], $_SERVER["PHP_SELF"], 'b.number', '', $param, '', $sortfield, $sortorder);
  483. $totalarray['nbfield']++;
  484. }
  485. if (!empty($arrayfields['b.account_number']['checked'])) {
  486. print_liste_field_titre($arrayfields['b.account_number']['label'], $_SERVER["PHP_SELF"], 'b.account_number', '', $param, '', $sortfield, $sortorder);
  487. $totalarray['nbfield']++;
  488. }
  489. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  490. print_liste_field_titre($arrayfields['b.fk_accountancy_journal']['label'], $_SERVER["PHP_SELF"], 'b.fk_accountancy_journal', '', $param, '', $sortfield, $sortorder);
  491. $totalarray['nbfield']++;
  492. }
  493. if (!empty($arrayfields['b.currency_code']['checked'])) {
  494. print_liste_field_titre($arrayfields['b.currency_code']['label'], $_SERVER["PHP_SELF"], 'b.currency_code', '', $param, '', $sortfield, $sortorder, 'center ');
  495. $totalarray['nbfield']++;
  496. }
  497. if (!empty($arrayfields['toreconcile']['checked'])) {
  498. print_liste_field_titre($arrayfields['toreconcile']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  499. $totalarray['nbfield']++;
  500. }
  501. // Extra fields
  502. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  503. // Hook fields
  504. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  505. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  506. print $hookmanager->resPrint;
  507. if (!empty($arrayfields['b.datec']['checked'])) {
  508. print_liste_field_titre($arrayfields['b.datec']['label'], $_SERVER["PHP_SELF"], "b.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  509. $totalarray['nbfield']++;
  510. }
  511. if (!empty($arrayfields['b.tms']['checked'])) {
  512. print_liste_field_titre($arrayfields['b.tms']['label'], $_SERVER["PHP_SELF"], "b.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  513. $totalarray['nbfield']++;
  514. }
  515. if (!empty($arrayfields['b.clos']['checked'])) {
  516. print_liste_field_titre($arrayfields['b.clos']['label'], $_SERVER["PHP_SELF"], 'b.clos', '', $param, '', $sortfield, $sortorder, 'center ');
  517. $totalarray['nbfield']++;
  518. }
  519. if (!empty($arrayfields['balance']['checked'])) {
  520. print_liste_field_titre($arrayfields['balance']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  521. $totalarray['nbfield']++;
  522. }
  523. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  524. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  525. $totalarray['nbfield']++;
  526. }
  527. print "</tr>\n";
  528. $savnbfield = $totalarray['nbfield'];
  529. $totalarray = array();
  530. $totalarray['nbfield'] = 0;
  531. $totalarray['val'] = array('balance'=>0);
  532. $total = array();
  533. $found = 0;
  534. $i = 0;
  535. $lastcurrencycode = '';
  536. $imaxinloop = ($limit ? min($num, $limit) : $num);
  537. foreach ($accounts as $key => $type) {
  538. if ($i >= $limit) {
  539. break;
  540. }
  541. $found++;
  542. $result = $objecttmp->fetch($key);
  543. $solde = $objecttmp->solde(1);
  544. if (!empty($lastcurrencycode) && $lastcurrencycode != $objecttmp->currency_code) {
  545. $lastcurrencycode = 'various'; // We found several different currencies
  546. }
  547. if ($lastcurrencycode != 'various') {
  548. $lastcurrencycode = $objecttmp->currency_code;
  549. }
  550. if ($mode == 'kanban') {
  551. if ($i == 0) {
  552. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  553. print '<div class="box-flex-container kanban">';
  554. }
  555. // Output Kanban
  556. print $objecttmp->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  557. if ($i == ($imaxinloop - 1)) {
  558. print '</div>';
  559. print '</td></tr>';
  560. }
  561. } else {
  562. print '<tr class="oddeven">';
  563. // Action column
  564. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  565. print '<td class="nowrap center">';
  566. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  567. $selected = 0;
  568. if (in_array($objecttmp->id, $arrayofselected)) {
  569. $selected = 1;
  570. }
  571. print '<input id="cb'.$objecttmp->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$objecttmp->id.'"'.($selected ? ' checked="checked"' : '').'>';
  572. }
  573. print '</td>';
  574. }
  575. // Ref
  576. if (!empty($arrayfields['b.ref']['checked'])) {
  577. print '<td class="nowraponall">'.$objecttmp->getNomUrl(1).'</td>';
  578. if (!$i) {
  579. $totalarray['nbfield']++;
  580. }
  581. }
  582. // Label
  583. if (!empty($arrayfields['b.label']['checked'])) {
  584. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objecttmp->label).'">'.dol_escape_htmltag($objecttmp->label).'</td>';
  585. if (!$i) {
  586. $totalarray['nbfield']++;
  587. }
  588. }
  589. // Account type
  590. if (!empty($arrayfields['accountype']['checked'])) {
  591. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($objecttmp->type_lib[$objecttmp->type]).'">';
  592. print $objecttmp->type_lib[$objecttmp->type];
  593. print '</td>';
  594. if (!$i) {
  595. $totalarray['nbfield']++;
  596. }
  597. }
  598. // Number
  599. if (!empty($arrayfields['b.number']['checked'])) {
  600. print '<td>'.dol_escape_htmltag($objecttmp->number).'</td>';
  601. if (!$i) {
  602. $totalarray['nbfield']++;
  603. }
  604. }
  605. // Account number
  606. if (!empty($arrayfields['b.account_number']['checked'])) {
  607. print '<td class="tdoverflowmax250">';
  608. if (isModEnabled('accounting') && !empty($objecttmp->account_number)) {
  609. $accountingaccount = new AccountingAccount($db);
  610. $accountingaccount->fetch('', $objecttmp->account_number, 1);
  611. print '<span title="'.dol_escape_htmltag($accountingaccount->account_number.' - '.$accountingaccount->label).'">';
  612. print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
  613. print '</span>';
  614. } else {
  615. print '<span title="'.dol_escape_htmltag($objecttmp->account_number).'">'.$objecttmp->account_number.'</span>';
  616. }
  617. print '</td>';
  618. if (!$i) {
  619. $totalarray['nbfield']++;
  620. }
  621. }
  622. // Accountancy journal
  623. if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
  624. print '<td class="tdoverflowmax125">';
  625. if (isModEnabled('accounting')) {
  626. if (empty($objecttmp->fk_accountancy_journal)) {
  627. print img_warning($langs->trans("Mandatory"));
  628. } else {
  629. $accountingjournal = new AccountingJournal($db);
  630. $accountingjournal->fetch($objecttmp->fk_accountancy_journal);
  631. print $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  632. }
  633. } else {
  634. print '';
  635. }
  636. print '</td>';
  637. if (!$i) {
  638. $totalarray['nbfield']++;
  639. }
  640. }
  641. // Currency
  642. if (!empty($arrayfields['b.currency_code']['checked'])) {
  643. print '<td class="center nowraponall">';
  644. print $objecttmp->currency_code;
  645. print '</td>';
  646. if (!$i) {
  647. $totalarray['nbfield']++;
  648. }
  649. }
  650. // Transactions to reconcile
  651. if (!empty($arrayfields['toreconcile']['checked'])) {
  652. $conciliate = $objecttmp->canBeConciliated();
  653. $labeltoshow = '';
  654. if ($conciliate == -2) {
  655. $labeltoshow = $langs->trans("CashAccount");
  656. } elseif ($conciliate == -3) {
  657. $labeltoshow = $langs->trans("Closed");
  658. } elseif (empty($objecttmp->rappro)) {
  659. $labeltoshow = $langs->trans("ConciliationDisabled");
  660. }
  661. print '<td class="center tdoverflowmax125"'.($labeltoshow ? ' title="'.dol_escape_htmltag($labeltoshow).'"' : '').'>';
  662. if ($conciliate == -2) {
  663. print '<span class="opacitymedium">'.$langs->trans("CashAccount").'</span>';
  664. } elseif ($conciliate == -3) {
  665. print '<span class="opacitymedium">'.$langs->trans("Closed").'</span>';
  666. } elseif (empty($objecttmp->rappro)) {
  667. print '<span class="opacitymedium">'.$langs->trans("ConciliationDisabled").'</span>';
  668. } else {
  669. $result = $objecttmp->load_board($user, $objecttmp->id);
  670. if (is_numeric($result) && $result < 0) {
  671. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  672. } else {
  673. 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">';
  674. print '<span class="badge badge-info classfortooltip" title="'.dol_htmlentities($langs->trans("TransactionsToConciliate")).'">';
  675. print $result->nbtodo;
  676. print '</span>';
  677. print '</a>';
  678. if ($result->nbtodolate) {
  679. print '<span title="'.dol_htmlentities($langs->trans("Late")).'" class="classfortooltip badge badge-danger marginleftonlyshort">';
  680. print '<i class="fa fa-exclamation-triangle"></i> '.$result->nbtodolate;
  681. print '</span>';
  682. }
  683. }
  684. }
  685. print '</td>';
  686. if (!$i) {
  687. $totalarray['nbfield']++;
  688. }
  689. }
  690. // Extra fields
  691. if (is_array($objecttmp->array_options)) {
  692. $obj = new stdClass();
  693. foreach ($objecttmp->array_options as $k => $v) {
  694. $obj->$k = $v;
  695. }
  696. }
  697. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  698. // Fields from hook
  699. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  700. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objecttmp, $action); // Note that $action and $objecttmpect may have been modified by hook
  701. print $hookmanager->resPrint;
  702. // Date creation
  703. if (!empty($arrayfields['b.datec']['checked'])) {
  704. print '<td class="center nowraponall">';
  705. print dol_print_date($objecttmp->date_creation, 'dayhour');
  706. print '</td>';
  707. if (!$i) {
  708. $totalarray['nbfield']++;
  709. }
  710. }
  711. // Date modification
  712. if (!empty($arrayfields['b.tms']['checked'])) {
  713. print '<td class="center nowraponall">';
  714. print dol_print_date($objecttmp->date_update, 'dayhour');
  715. print '</td>';
  716. if (!$i) {
  717. $totalarray['nbfield']++;
  718. }
  719. }
  720. // Status
  721. if (!empty($arrayfields['b.clos']['checked'])) {
  722. print '<td class="center">'.$objecttmp->getLibStatut(5).'</td>';
  723. if (!$i) {
  724. $totalarray['nbfield']++;
  725. }
  726. }
  727. // Balance
  728. if (!empty($arrayfields['balance']['checked'])) {
  729. print '<td class="nowraponall right">';
  730. print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$objecttmp->id.'">';
  731. print '<span class="amount">'.price(price2num($solde, 'MT'), 0, $langs, 1, -1, -1, $objecttmp->currency_code).'</span>';
  732. print '</a>';
  733. print '</td>';
  734. if (!$i) {
  735. $totalarray['nbfield']++;
  736. }
  737. if (!$i) {
  738. $totalarray['pos'][$totalarray['nbfield']] = 'balance';
  739. }
  740. $totalarray['val']['balance'] += $solde;
  741. }
  742. // Action column
  743. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  744. print '<td class="nowrap center">';
  745. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  746. $selected = 0;
  747. if (in_array($objecttmp->id, $arrayofselected)) {
  748. $selected = 1;
  749. }
  750. print '<input id="cb'.$objecttmp->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$objecttmp->id.'"'.($selected ? ' checked="checked"' : '').'>';
  751. }
  752. print '</td>';
  753. }
  754. if (!$i) {
  755. $totalarray['nbfield']++;
  756. }
  757. print '</tr>';
  758. if (empty($total[$objecttmp->currency_code])) {
  759. $total[$objecttmp->currency_code] = $solde;
  760. } else {
  761. $total[$objecttmp->currency_code] += $solde;
  762. }
  763. }
  764. $i++;
  765. }
  766. // If no record found
  767. if (!$found) {
  768. $colspan = 1;
  769. foreach ($arrayfields as $key => $val) {
  770. if (!empty($val['checked'])) {
  771. $colspan++;
  772. }
  773. }
  774. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  775. }
  776. // Show total line
  777. if ($lastcurrencycode != 'various') { // If there is several currency, $lastcurrencycode is set to 'various' before
  778. // Show total line
  779. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  780. }
  781. print '</table>';
  782. print "</div>";
  783. print "</form>";
  784. // End of page
  785. llxFooter();
  786. $db->close();