list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. <?php
  2. /* Copyright (C) 2017-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  5. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/bank/various_payment/list.php
  22. * \ingroup bank
  23. * \brief List of various payments
  24. */
  25. // Load Dolibarr environment
  26. require '../../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("compta", "banks", "bills", "accountancy"));
  36. $optioncss = GETPOST('optioncss', 'alpha');
  37. $mode = GETPOST('mode', 'alpha');
  38. $massaction = GETPOST('massaction', 'aZ09');
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $search_ref = GETPOST('search_ref', 'int');
  42. $search_user = GETPOST('search_user', 'alpha');
  43. $search_label = GETPOST('search_label', 'alpha');
  44. $search_datep_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  45. $search_datep_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  46. $search_datev_start = dol_mktime(0, 0, 0, GETPOST('search_date_value_startmonth', 'int'), GETPOST('search_date_value_startday', 'int'), GETPOST('search_date_value_startyear', 'int'));
  47. $search_datev_end = dol_mktime(23, 59, 59, GETPOST('search_date_value_endmonth', 'int'), GETPOST('search_date_value_endday', 'int'), GETPOST('search_date_value_endyear', 'int'));
  48. $search_amount_deb = GETPOST('search_amount_deb', 'alpha');
  49. $search_amount_cred = GETPOST('search_amount_cred', 'alpha');
  50. $search_bank_account = GETPOST('search_account', 'int');
  51. $search_bank_entry = GETPOST('search_bank_entry', 'int');
  52. $search_accountancy_account = GETPOST("search_accountancy_account");
  53. if ($search_accountancy_account == - 1) {
  54. $search_accountancy_account = '';
  55. }
  56. $search_accountancy_subledger = GETPOST("search_accountancy_subledger");
  57. if ($search_accountancy_subledger == - 1) {
  58. $search_accountancy_subledger = '';
  59. }
  60. if (empty($search_datep_start)) {
  61. $search_datep_start = GETPOST("search_datep_start", 'int');
  62. }
  63. if (empty($search_datep_end)) {
  64. $search_datep_end = GETPOST("search_datep_end", 'int');
  65. }
  66. if (empty($search_datev_start)) {
  67. $search_datev_start = GETPOST("search_datev_start", 'int');
  68. }
  69. if (empty($search_datev_end)) {
  70. $search_datev_end = GETPOST("search_datev_end", 'int');
  71. }
  72. $search_type_id = GETPOST('search_type_id', 'int');
  73. $sortfield = GETPOST('sortfield', 'aZ09comma');
  74. $sortorder = GETPOST('sortorder', 'aZ09comma');
  75. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  76. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  77. // If $page is not defined, or '' or -1 or if we click on clear filters
  78. $page = 0;
  79. }
  80. $offset = $limit * $page;
  81. $pageprev = $page - 1;
  82. $pagenext = $page + 1;
  83. // Initialize technical objects
  84. $object = new PaymentVarious($db);
  85. $extrafields = new ExtraFields($db);
  86. //$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  87. $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
  88. // Fetch optionals attributes and labels
  89. $extrafields->fetch_name_optionals_label($object->table_element);
  90. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  91. // Default sort order (if not yet defined by previous GETPOST)
  92. if (!$sortfield) {
  93. $sortfield = "v.datep,v.rowid";
  94. }
  95. if (!$sortorder) {
  96. $sortorder = "DESC,DESC";
  97. }
  98. $filtre = GETPOST("filtre", 'alpha');
  99. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
  100. $search_ref = '';
  101. $search_label = '';
  102. $search_datep_start = '';
  103. $search_datep_end = '';
  104. $search_datev_start = '';
  105. $search_datev_end = '';
  106. $search_amount_deb = '';
  107. $search_amount_cred = '';
  108. $search_bank_account = '';
  109. $search_bank_entry = '';
  110. $search_accountancy_account = '';
  111. $search_accountancy_subledger = '';
  112. $search_type_id = '';
  113. }
  114. $search_all = GETPOSTISSET("search_all") ? trim(GETPOST("search_all", 'alpha')) : trim(GETPOST('sall'));
  115. /*
  116. * TODO: fill array "$fields" in "/compta/bank/class/paymentvarious.class.php" and use
  117. *
  118. *
  119. * $object = new PaymentVarious($db);
  120. *
  121. * $search = array();
  122. * foreach ($object->fields as $key => $val)
  123. * {
  124. * if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  125. * }
  126. * $fieldstosearchall = array();
  127. * foreach ($object->fields as $key => $val)
  128. * {
  129. * if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  130. * }
  131. *
  132. */
  133. // List of fields to search into when doing a "search in all"
  134. $fieldstosearchall = array(
  135. 'v.rowid'=>"Ref",
  136. 'v.label'=>"Label",
  137. 'v.datep'=>"DatePayment",
  138. 'v.datev'=>"DateValue",
  139. 'v.amount'=>$langs->trans("Debit").", ".$langs->trans("Credit"),
  140. );
  141. // Definition of fields for lists
  142. $arrayfields = array(
  143. 'ref' =>array('label'=>"Ref", 'checked'=>1, 'position'=>100),
  144. 'label' =>array('label'=>"Label", 'checked'=>1, 'position'=>110),
  145. 'datep' =>array('label'=>"DatePayment", 'checked'=>1, 'position'=>120),
  146. 'datev' =>array('label'=>"DateValue", 'checked'=>-1, 'position'=>130),
  147. 'type' =>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>140),
  148. 'project' =>array('label'=>"Project", 'checked'=>1, 'position'=>200, "enabled"=>isModEnabled('project')),
  149. 'bank' =>array('label'=>"BankAccount", 'checked'=>1, 'position'=>300, "enabled"=>isModEnabled("banque")),
  150. 'entry' =>array('label'=>"BankTransactionLine", 'checked'=>1, 'position'=>310, "enabled"=>isModEnabled("banque")),
  151. 'account' =>array('label'=>"AccountAccountingShort", 'checked'=>1, 'position'=>400, "enabled"=>isModEnabled('accounting')),
  152. 'subledger' =>array('label'=>"SubledgerAccount", 'checked'=>1, 'position'=>410, "enabled"=>isModEnabled('accounting')),
  153. 'debit' =>array('label'=>"Debit", 'checked'=>1, 'position'=>500),
  154. 'credit' =>array('label'=>"Credit", 'checked'=>1, 'position'=>510),
  155. );
  156. $arrayfields = dol_sort_array($arrayfields, 'position');
  157. // Security check
  158. $socid = GETPOST("socid", "int");
  159. if ($user->socid) {
  160. $socid = $user->socid;
  161. }
  162. $result = restrictedArea($user, 'banque', '', '', '');
  163. /*
  164. * Actions
  165. */
  166. if (GETPOST('cancel', 'alpha')) {
  167. $action = 'list';
  168. $massaction = '';
  169. }
  170. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  171. $massaction = '';
  172. }
  173. $parameters = array();
  174. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  175. if ($reshook < 0) {
  176. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  177. }
  178. if (empty($reshook)) {
  179. // Selection of new fields
  180. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  181. // Purge search criteria
  182. 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
  183. foreach ($object->fields as $key => $val) {
  184. $search[$key] = '';
  185. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  186. $search[$key.'_dtstart'] = '';
  187. $search[$key.'_dtend'] = '';
  188. }
  189. }
  190. $toselect = array();
  191. $search_array_options = array();
  192. }
  193. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  194. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  195. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  196. }
  197. }
  198. /*
  199. * View
  200. */
  201. $form = new Form($db);
  202. if ($arrayfields['account']['checked'] || $arrayfields['subledger']['checked']) {
  203. $formaccounting = new FormAccounting($db);
  204. }
  205. if ($arrayfields['bank']['checked'] && isModEnabled('accounting')) {
  206. $accountingjournal = new AccountingJournal($db);
  207. }
  208. if ($arrayfields['ref']['checked']) {
  209. $variousstatic = new PaymentVarious($db);
  210. }
  211. if ($arrayfields['bank']['checked']) {
  212. $accountstatic = new Account($db);
  213. }
  214. if ($arrayfields['project']['checked']) {
  215. $proj = new Project($db);
  216. }
  217. if ($arrayfields['entry']['checked']) {
  218. $bankline = new AccountLine($db);
  219. }
  220. if ($arrayfields['account']['checked']) {
  221. $accountingaccount = new AccountingAccount($db);
  222. }
  223. $title = $langs->trans("VariousPayments");
  224. //$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  225. $help_url = '';
  226. // Build and execute select
  227. // --------------------------------------------------------------------
  228. $sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
  229. $sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
  230. $sql .= " pst.code as payment_code";
  231. $sqlfields = $sql; // $sql fields to remove for count total
  232. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  233. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
  234. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  235. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  236. $sql .= " WHERE v.entity IN (".getEntity('payment_various').")";
  237. // Search criteria
  238. if ($search_ref) {
  239. $sql .= " AND v.rowid = ".((int) $search_ref);
  240. }
  241. if ($search_label) {
  242. $sql .= natural_search(array('v.label'), $search_label);
  243. }
  244. if ($search_datep_start) {
  245. $sql .= " AND v.datep >= '".$db->idate($search_datep_start)."'";
  246. }
  247. if ($search_datep_end) {
  248. $sql .= " AND v.datep <= '".$db->idate($search_datep_end)."'";
  249. }
  250. if ($search_datev_start) {
  251. $sql .= " AND v.datev >= '".$db->idate($search_datev_start)."'";
  252. }
  253. if ($search_datev_end) {
  254. $sql .= " AND v.datev <= '".$db->idate($search_datev_end)."'";
  255. }
  256. if ($search_amount_deb) {
  257. $sql .= natural_search("v.amount", $search_amount_deb, 1);
  258. }
  259. if ($search_amount_cred) {
  260. $sql .= natural_search("v.amount", $search_amount_cred, 1);
  261. }
  262. if ($search_bank_account > 0) {
  263. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  264. }
  265. if ($search_bank_entry > 0) {
  266. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  267. }
  268. if ($search_accountancy_account > 0) {
  269. $sql .= " AND v.accountancy_code = ".((int) $search_accountancy_account);
  270. }
  271. if ($search_accountancy_subledger > 0) {
  272. $sql .= " AND v.subledger_account = ".((int) $search_accountancy_subledger);
  273. }
  274. if ($search_type_id > 0) {
  275. $sql .= " AND v.fk_typepayment=".((int) $search_type_id);
  276. }
  277. if ($search_all) {
  278. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  279. }
  280. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  281. // Add where from extra fields
  282. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  283. // Add where from hooks
  284. $parameters = array();
  285. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  286. $sql .= $hookmanager->resPrint;
  287. // Count total nb of records
  288. $nbtotalofrecords = '';
  289. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  290. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  291. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  292. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  293. $resql = $db->query($sqlforcount);
  294. if ($resql) {
  295. $objforcount = $db->fetch_object($resql);
  296. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  297. } else {
  298. dol_print_error($db);
  299. }
  300. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  301. $page = 0;
  302. $offset = 0;
  303. }
  304. $db->free($resql);
  305. }
  306. // Complete request and execute it with limit
  307. $sql .= $db->order($sortfield, $sortorder);
  308. if ($limit) {
  309. $sql .= $db->plimit($limit + 1, $offset);
  310. }
  311. $resql = $db->query($sql);
  312. if (!$resql) {
  313. dol_print_error($db);
  314. exit;
  315. }
  316. $num = $db->num_rows($resql);
  317. // Direct jump if only one record found
  318. if ($num == 1 && !getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  319. $obj = $db->fetch_object($resql);
  320. $id = $obj->rowid;
  321. header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$id);
  322. exit;
  323. }
  324. // Output page
  325. // --------------------------------------------------------------------
  326. llxHeader('', $title, $help_url);
  327. $arrayofselected = is_array($toselect) ? $toselect : array();
  328. $param = '';
  329. if (!empty($mode)) {
  330. $param .= '&mode='.urlencode($mode);
  331. }
  332. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  333. $param .= '&contextpage='.urlencode($contextpage);
  334. }
  335. if ($limit > 0 && $limit != $conf->liste_limit) {
  336. $param .= '&limit='.((int) $limit);
  337. }
  338. if ($optioncss != '') {
  339. $param .= '&optioncss='.urlencode($optioncss);
  340. }
  341. if ($search_ref) {
  342. $param .= '&search_ref='.urlencode($search_ref);
  343. }
  344. if ($search_label) {
  345. $param .= '&search_label='.urlencode($search_label);
  346. }
  347. if ($search_datep_start) {
  348. $param .= '&search_datep_start='.urlencode($search_datep_start);
  349. }
  350. if ($search_datep_end) {
  351. $param .= '&search_datep_end='.urlencode($search_datep_end);
  352. }
  353. if ($search_datev_start) {
  354. $param .= '&search_datev_start='.urlencode($search_datev_start);
  355. }
  356. if ($search_datev_end) {
  357. $param .= '&search_datev_end='.urlencode($search_datev_end);
  358. }
  359. if ($search_type_id > 0) {
  360. $param .= '&search_type_id='.urlencode($search_type_id);
  361. }
  362. if ($search_amount_deb) {
  363. $param .= '&search_amount_deb='.urlencode($search_amount_deb);
  364. }
  365. if ($search_amount_cred) {
  366. $param .= '&search_amount_cred='.urlencode($search_amount_cred);
  367. }
  368. if ($search_bank_account > 0) {
  369. $param .= '&search_account='.urlencode($search_bank_account);
  370. }
  371. if ($search_accountancy_account > 0) {
  372. $param .= '&search_accountancy_account='.urlencode($search_accountancy_account);
  373. }
  374. if ($search_accountancy_subledger > 0) {
  375. $param .= '&search_accountancy_subledger='.urlencode($search_accountancy_subledger);
  376. }
  377. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create';
  378. if (!empty($socid)) {
  379. $url .= '&socid='.urlencode($socid);
  380. }
  381. // List of mass actions available
  382. $arrayofmassactions = array();
  383. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  384. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  385. if ($optioncss != '') {
  386. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  387. }
  388. print '<input type="hidden" name="token" value="'.newToken().'">';
  389. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  390. print '<input type="hidden" name="action" value="list">';
  391. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  392. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  393. print '<input type="hidden" name="page" value="'.$page.'">';
  394. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  395. print '<input type="hidden" name="page_y" value="">';
  396. print '<input type="hidden" name="mode" value="'.$mode.'">';
  397. $newcardbutton = '';
  398. $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'));
  399. $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'));
  400. $newcardbutton .= dolGetButtonTitleSeparator();
  401. $newcardbutton .= dolGetButtonTitle($langs->trans('MenuNewVariousPayment'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('banque', 'modifier'));
  402. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
  403. if ($search_all) {
  404. $setupstring = '';
  405. foreach ($fieldstosearchall as $key => $val) {
  406. $fieldstosearchall[$key] = $langs->trans($val);
  407. $setupstring .= $key."=".$val.";";
  408. }
  409. print '<!-- Search done like if VARIOUSPAYMENT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  410. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  411. }
  412. $arrayofmassactions = array();
  413. $moreforfilter= '';
  414. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  415. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  416. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  417. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  418. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  419. // Fields title search
  420. // --------------------------------------------------------------------
  421. print '<tr class="liste_titre_filter">';
  422. // Action column
  423. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  424. print '<td class="liste_titre center maxwidthsearch">';
  425. $searchpicto = $form->showFilterButtons('left');
  426. print $searchpicto;
  427. print '</td>';
  428. }
  429. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  430. print '<td class="liste_titre">';
  431. print '</td>';
  432. }
  433. // Ref
  434. if ($arrayfields['ref']['checked']) {
  435. print '<td class="liste_titre left">';
  436. print '<input class="flat" type="text" size="3" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  437. print '</td>';
  438. }
  439. // Label
  440. if ($arrayfields['label']['checked']) {
  441. print '<td class="liste_titre">';
  442. print '<input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  443. print '</td>';
  444. }
  445. // Payment date
  446. if ($arrayfields['datep']['checked']) {
  447. print '<td class="liste_titre center">';
  448. print '<div class="nowrapfordate">';
  449. print $form->selectDate($search_datep_start ? $search_datep_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  450. print '</div>';
  451. print '<div class="nowrapfordate">';
  452. print $form->selectDate($search_datep_end ? $search_datep_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  453. print '</div>';
  454. print '</td>';
  455. }
  456. // Value date
  457. if ($arrayfields['datev']['checked']) {
  458. print '<td class="liste_titre center">';
  459. print '<div class="nowrapfordate">';
  460. print $form->selectDate($search_datev_start ? $search_datev_start : -1, 'search_date_value_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  461. print '</div>';
  462. print '<div class="nowrapfordate">';
  463. print $form->selectDate($search_datev_end ? $search_datev_end : -1, 'search_date_value_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  464. print '</div>';
  465. print '</td>';
  466. }
  467. // Payment type
  468. if ($arrayfields['type']['checked']) {
  469. print '<td class="liste_titre center">';
  470. print $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16, 1, 'maxwidth100', 1);
  471. print '</td>';
  472. }
  473. // Project
  474. if ($arrayfields['project']['checked']) {
  475. print '<td class="liste_titre">';
  476. // TODO
  477. print '</td>';
  478. }
  479. // Bank account
  480. if ($arrayfields['bank']['checked']) {
  481. print '<td class="liste_titre">';
  482. $form->select_comptes($search_bank_account, 'search_account', 0, '', 1, '', 0, 'maxwidth100');
  483. print '</td>';
  484. }
  485. // Bank entry
  486. if ($arrayfields['entry']['checked']) {
  487. print '<td class="liste_titre left">';
  488. print '<input name="search_bank_entry" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_bank_entry).'">';
  489. print '</td>';
  490. }
  491. // Accounting account
  492. if (!empty($arrayfields['account']['checked'])) {
  493. print '<td class="liste_titre">';
  494. print '<div class="nowrap">';
  495. print $formaccounting->select_account($search_accountancy_account, 'search_accountancy_account', 1, array(), 1, 1, 'maxwidth200');
  496. print '</div>';
  497. print '</td>';
  498. }
  499. // Subledger account
  500. if (!empty($arrayfields['subledger']['checked'])) {
  501. print '<td class="liste_titre">';
  502. print '<div class="nowrap">';
  503. print $formaccounting->select_auxaccount($search_accountancy_subledger, 'search_accountancy_subledger', 1, 'maxwidth200');
  504. print '</div>';
  505. print '</td>';
  506. }
  507. // Debit
  508. if (!empty($arrayfields['debit']['checked'])) {
  509. print '<td class="liste_titre right">';
  510. print '<input name="search_amount_deb" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_amount_deb).'">';
  511. print '</td>';
  512. }
  513. // Credit
  514. if ($arrayfields['credit']['checked']) {
  515. print '<td class="liste_titre right">';
  516. print '<input name="search_amount_cred" class="flat maxwidth50" type="text" size="8" value="'.dol_escape_htmltag($search_amount_cred).'">';
  517. print '</td>';
  518. }
  519. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  520. print '<td class="liste_titre center maxwidthsearch">';
  521. $searchpicto = $form->showFilterButtons();
  522. print $searchpicto;
  523. print '</td>';
  524. }
  525. print '</tr>'."\n";
  526. $totalarray = array();
  527. $totalarray['nbfield'] = 0;
  528. // Fields title label
  529. // --------------------------------------------------------------------
  530. print '<tr class="liste_titre">';
  531. // Action column
  532. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  533. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  534. $totalarray['nbfield']++;
  535. }
  536. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  537. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  538. $totalarray['nbfield']++;
  539. }
  540. if ($arrayfields['ref']['checked']) {
  541. print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], 'v.rowid', '', $param, '', $sortfield, $sortorder);
  542. $totalarray['nbfield']++;
  543. }
  544. if ($arrayfields['label']['checked']) {
  545. print_liste_field_titre($arrayfields['label']['label'], $_SERVER["PHP_SELF"], 'v.label', '', $param, '', $sortfield, $sortorder);
  546. $totalarray['nbfield']++;
  547. }
  548. if ($arrayfields['datep']['checked']) {
  549. print_liste_field_titre($arrayfields['datep']['label'], $_SERVER["PHP_SELF"], 'v.datep,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  550. $totalarray['nbfield']++;
  551. }
  552. if ($arrayfields['datev']['checked']) {
  553. print_liste_field_titre($arrayfields['datev']['label'], $_SERVER["PHP_SELF"], 'v.datev,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  554. $totalarray['nbfield']++;
  555. }
  556. if ($arrayfields['type']['checked']) {
  557. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], 'type', '', $param, '', $sortfield, $sortorder, 'center ');
  558. $totalarray['nbfield']++;
  559. }
  560. if ($arrayfields['project']['checked']) {
  561. print_liste_field_titre($arrayfields['project']['label'], $_SERVER["PHP_SELF"], 'fk_project', '', $param, '', $sortfield, $sortorder);
  562. $totalarray['nbfield']++;
  563. }
  564. if ($arrayfields['bank']['checked']) {
  565. print_liste_field_titre($arrayfields['bank']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  566. $totalarray['nbfield']++;
  567. }
  568. if ($arrayfields['entry']['checked']) {
  569. print_liste_field_titre($arrayfields['entry']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  570. $totalarray['nbfield']++;
  571. }
  572. if (!empty($arrayfields['account']['checked'])) {
  573. print_liste_field_titre($arrayfields['account']['label'], $_SERVER["PHP_SELF"], 'v.accountancy_code', '', $param, '', $sortfield, $sortorder, 'left ');
  574. $totalarray['nbfield']++;
  575. }
  576. if (!empty($arrayfields['subledger']['checked'])) {
  577. print_liste_field_titre($arrayfields['subledger']['label'], $_SERVER["PHP_SELF"], 'v.subledger_account', '', $param, '', $sortfield, $sortorder, 'left ');
  578. $totalarray['nbfield']++;
  579. }
  580. if ($arrayfields['debit']['checked']) {
  581. print_liste_field_titre($arrayfields['debit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  582. $totalarray['nbfield']++;
  583. }
  584. if ($arrayfields['credit']['checked']) {
  585. print_liste_field_titre($arrayfields['credit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  586. $totalarray['nbfield']++;
  587. }
  588. // Extra fields
  589. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  590. // Hook fields
  591. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  592. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  593. print $hookmanager->resPrint;
  594. // Action column
  595. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  596. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  597. $totalarray['nbfield']++;
  598. }
  599. print '</tr>'."\n";
  600. // Loop on record
  601. // --------------------------------------------------------------------
  602. $i = 0;
  603. $savnbfield = $totalarray['nbfield'];
  604. $totalarray = array();
  605. $totalarray['nbfield'] = 0;
  606. $totalarray['val']['total_cred'] = 0;
  607. $totalarray['val']['total_deb'] = 0;
  608. $imaxinloop = ($limit ? min($num, $limit) : $num);
  609. while ($i < $imaxinloop) {
  610. $obj = $db->fetch_object($resql);
  611. if (empty($obj)) {
  612. break; // Should not happen
  613. }
  614. $variousstatic->id = $obj->rowid;
  615. $variousstatic->ref = $obj->rowid;
  616. $variousstatic->label = $obj->label;
  617. $variousstatic->datep = $obj->datep;
  618. $variousstatic->type_payment = $obj->payment_code;
  619. $bankline->fetch($obj->fk_bank);
  620. $variousstatic->fk_bank = $bankline->getNomUrl(1);
  621. $variousstatic->amount = $obj->amount;
  622. $accountingaccount->fetch('', $obj->accountancy_code, 1);
  623. $variousstatic->accountancy_code = $accountingaccount->getNomUrl(0, 0, 1, $obj->accountingaccount, 1);
  624. if ($mode == 'kanban') {
  625. if ($i == 0) {
  626. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  627. print '<div class="box-flex-container kanban">';
  628. }
  629. // Output Kanban
  630. print $variousstatic->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  631. if ($i == ($imaxinloop) - 1) {
  632. print '</div>';
  633. print '</td></tr>';
  634. }
  635. } else {
  636. // Show here line of result
  637. $j = 0;
  638. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  639. // Action column
  640. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  641. print '<td></td>';
  642. if (!$i) {
  643. $totalarray['nbfield']++;
  644. }
  645. }
  646. // No
  647. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  648. print '<td>'.(($offset * $limit) + $i).'</td>';
  649. }
  650. // Ref
  651. if ($arrayfields['ref']['checked']) {
  652. print '<td>'.$variousstatic->getNomUrl(1)."</td>";
  653. if (!$i) {
  654. $totalarray['nbfield']++;
  655. }
  656. }
  657. // Label payment
  658. if ($arrayfields['label']['checked']) {
  659. print '<td class="tdoverflowmax150" title="'.$variousstatic->label.'">'.$variousstatic->label."</td>";
  660. if (!$i) {
  661. $totalarray['nbfield']++;
  662. }
  663. }
  664. // Date payment
  665. if ($arrayfields['datep']['checked']) {
  666. print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>";
  667. if (!$i) {
  668. $totalarray['nbfield']++;
  669. }
  670. }
  671. // Date value
  672. if ($arrayfields['datev']['checked']) {
  673. print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day')."</td>";
  674. if (!$i) {
  675. $totalarray['nbfield']++;
  676. }
  677. }
  678. // Type
  679. if ($arrayfields['type']['checked']) {
  680. print '<td class="center">';
  681. if ($obj->payment_code) {
  682. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  683. print ' ';
  684. }
  685. print $obj->num_payment;
  686. print '</td>';
  687. if (!$i) {
  688. $totalarray['nbfield']++;
  689. }
  690. }
  691. // Project
  692. if ($arrayfields['project']['checked']) {
  693. print '<td class="nowraponall">';
  694. if ($obj->fk_project > 0) {
  695. $proj->fetch($obj->fk_project);
  696. print $proj->getNomUrl(1);
  697. }
  698. print '</td>';
  699. if (!$i) {
  700. $totalarray['nbfield']++;
  701. }
  702. }
  703. // Bank account
  704. if ($arrayfields['bank']['checked']) {
  705. print '<td class="nowraponall">';
  706. if ($obj->bid > 0) {
  707. $accountstatic->id = $obj->bid;
  708. $accountstatic->ref = $obj->bref;
  709. $accountstatic->number = $obj->bnumber;
  710. if (isModEnabled('accounting')) {
  711. $accountstatic->account_number = $obj->bank_account_number;
  712. $accountingjournal->fetch($obj->accountancy_journal);
  713. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  714. }
  715. $accountstatic->label = $obj->blabel;
  716. print $accountstatic->getNomUrl(1);
  717. } else {
  718. print '&nbsp;';
  719. }
  720. print '</td>';
  721. if (!$i) {
  722. $totalarray['nbfield']++;
  723. }
  724. }
  725. // Bank entry
  726. if ($arrayfields['entry']['checked']) {
  727. $bankline->fetch($obj->fk_bank);
  728. print '<td>'.$bankline->getNomUrl(1).'</td>';
  729. if (!$i) {
  730. $totalarray['nbfield']++;
  731. }
  732. }
  733. // Accounting account
  734. if (!empty($arrayfields['account']['checked'])) {
  735. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  736. $result = $accountingaccount->fetch('', $obj->accountancy_code, 1);
  737. if ($result > 0) {
  738. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->accountancy_code.' '.$accountingaccount->label).'">'.$accountingaccount->getNomUrl(0, 1, 1, '', 1).'</td>';
  739. } else {
  740. print '<td></td>';
  741. }
  742. if (!$i) {
  743. $totalarray['nbfield']++;
  744. }
  745. }
  746. // Accounting subledger account
  747. if (!empty($arrayfields['subledger']['checked'])) {
  748. print '<td class="tdoverflowmax150">'.length_accounta($obj->subledger_account).'</td>';
  749. if (!$i) {
  750. $totalarray['nbfield']++;
  751. }
  752. }
  753. // Debit
  754. if ($arrayfields['debit']['checked']) {
  755. print '<td class="nowrap right">';
  756. if ($obj->sens == 0) {
  757. print '<span class="amount">'.price($obj->amount).'</span>';
  758. $totalarray['val']['total_deb'] += $obj->amount;
  759. }
  760. if (!$i) {
  761. $totalarray['nbfield']++;
  762. }
  763. if (!$i) {
  764. $totalarray['pos'][$totalarray['nbfield']] = 'total_deb';
  765. }
  766. print '</td>';
  767. }
  768. // Credit
  769. if ($arrayfields['credit']['checked']) {
  770. print '<td class="nowrap right">';
  771. if ($obj->sens == 1) {
  772. print '<span class="amount">'.price($obj->amount).'</span>';
  773. $totalarray['val']['total_cred'] += $obj->amount;
  774. }
  775. if (!$i) {
  776. $totalarray['nbfield']++;
  777. }
  778. if (!$i) {
  779. $totalarray['pos'][$totalarray['nbfield']] = 'total_cred';
  780. }
  781. print '</td>';
  782. }
  783. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  784. print '<td></td>';
  785. if (!$i) {
  786. $totalarray['nbfield']++;
  787. }
  788. }
  789. print '</tr>'."\n";
  790. }
  791. $i++;
  792. }
  793. // Show total line
  794. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  795. // If no record found
  796. if ($num == 0) {
  797. $colspan = 1;
  798. foreach ($arrayfields as $key => $val) {
  799. if (!empty($val['checked'])) {
  800. $colspan++;
  801. }
  802. }
  803. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  804. }
  805. $db->free($resql);
  806. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  807. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  808. print $hookmanager->resPrint;
  809. print '</table>'."\n";
  810. print '</div>'."\n";
  811. print '</form>'."\n";
  812. // End of page
  813. llxFooter();
  814. $db->close();