list.php 34 KB

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