list.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. <?php
  2. /* Copyright (C) 2017-2022 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. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  37. // Security check
  38. $socid = GETPOST("socid", "int");
  39. if ($user->socid) {
  40. $socid = $user->socid;
  41. }
  42. $optioncss = GETPOST('optioncss', 'alpha');
  43. $mode = GETPOST('mode', 'alpha');
  44. $massaction = GETPOST('massaction', 'aZ09');
  45. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  46. $search_ref = GETPOST('search_ref', 'int');
  47. $search_user = GETPOST('search_user', 'alpha');
  48. $search_label = GETPOST('search_label', 'alpha');
  49. $search_datep_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  50. $search_datep_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  51. $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'));
  52. $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'));
  53. $search_amount_deb = GETPOST('search_amount_deb', 'alpha');
  54. $search_amount_cred = GETPOST('search_amount_cred', 'alpha');
  55. $search_bank_account = GETPOST('search_account', 'int');
  56. $search_bank_entry = GETPOST('search_bank_entry', 'int');
  57. $search_accountancy_account = GETPOST("search_accountancy_account");
  58. if ($search_accountancy_account == - 1) {
  59. $search_accountancy_account = '';
  60. }
  61. $search_accountancy_subledger = GETPOST("search_accountancy_subledger");
  62. if ($search_accountancy_subledger == - 1) {
  63. $search_accountancy_subledger = '';
  64. }
  65. if (empty($search_datep_start)) {
  66. $search_datep_start = GETPOST("search_datep_start", 'int');
  67. }
  68. if (empty($search_datep_end)) {
  69. $search_datep_end = GETPOST("search_datep_end", 'int');
  70. }
  71. if (empty($search_datev_start)) {
  72. $search_datev_start = GETPOST("search_datev_start", 'int');
  73. }
  74. if (empty($search_datev_end)) {
  75. $search_datev_end = GETPOST("search_datev_end", 'int');
  76. }
  77. $search_type_id = GETPOST('search_type_id', 'int');
  78. $sortfield = GETPOST('sortfield', 'aZ09comma');
  79. $sortorder = GETPOST('sortorder', 'aZ09comma');
  80. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  81. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  82. // If $page is not defined, or '' or -1 or if we click on clear filters
  83. $page = 0;
  84. }
  85. $offset = $limit * $page;
  86. $pageprev = $page - 1;
  87. $pagenext = $page + 1;
  88. if (!$sortfield) {
  89. $sortfield = "v.datep,v.rowid";
  90. }
  91. if (!$sortorder) {
  92. $sortorder = "DESC,DESC";
  93. }
  94. $filtre = GETPOST("filtre", 'alpha');
  95. 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
  96. $search_ref = '';
  97. $search_label = '';
  98. $search_datep_start = '';
  99. $search_datep_end = '';
  100. $search_datev_start = '';
  101. $search_datev_end = '';
  102. $search_amount_deb = '';
  103. $search_amount_cred = '';
  104. $search_bank_account = '';
  105. $search_bank_entry = '';
  106. $search_accountancy_account = '';
  107. $search_accountancy_subledger = '';
  108. $search_type_id = '';
  109. }
  110. $search_all = GETPOSTISSET("search_all") ? trim(GETPOST("search_all", 'alpha')) : trim(GETPOST('sall'));
  111. /*
  112. * TODO: fill array "$fields" in "/compta/bank/class/paymentvarious.class.php" and use
  113. *
  114. *
  115. * $object = new PaymentVarious($db);
  116. *
  117. * $search = array();
  118. * foreach ($object->fields as $key => $val)
  119. * {
  120. * if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  121. * }
  122. * $fieldstosearchall = array();
  123. * foreach ($object->fields as $key => $val)
  124. * {
  125. * if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  126. * }
  127. *
  128. */
  129. // List of fields to search into when doing a "search in all"
  130. $fieldstosearchall = array(
  131. 'v.rowid'=>"Ref",
  132. 'v.label'=>"Label",
  133. 'v.datep'=>"DatePayment",
  134. 'v.datev'=>"DateValue",
  135. 'v.amount'=>$langs->trans("Debit").", ".$langs->trans("Credit"),
  136. );
  137. // Definition of fields for lists
  138. $arrayfields = array(
  139. 'ref' =>array('label'=>"Ref", 'checked'=>1, 'position'=>100),
  140. 'label' =>array('label'=>"Label", 'checked'=>1, 'position'=>110),
  141. 'datep' =>array('label'=>"DatePayment", 'checked'=>1, 'position'=>120),
  142. 'datev' =>array('label'=>"DateValue", 'checked'=>-1, 'position'=>130),
  143. 'type' =>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>140),
  144. 'project' =>array('label'=>"Project", 'checked'=>1, 'position'=>200, "enabled"=>isModEnabled('project')),
  145. 'bank' =>array('label'=>"BankAccount", 'checked'=>1, 'position'=>300, "enabled"=>isModEnabled("banque")),
  146. 'entry' =>array('label'=>"BankTransactionLine", 'checked'=>1, 'position'=>310, "enabled"=>isModEnabled("banque")),
  147. 'account' =>array('label'=>"AccountAccountingShort", 'checked'=>1, 'position'=>400, "enabled"=>isModEnabled('accounting')),
  148. 'subledger' =>array('label'=>"SubledgerAccount", 'checked'=>1, 'position'=>410, "enabled"=>isModEnabled('accounting')),
  149. 'debit' =>array('label'=>"Debit", 'checked'=>1, 'position'=>500),
  150. 'credit' =>array('label'=>"Credit", 'checked'=>1, 'position'=>510),
  151. );
  152. $arrayfields = dol_sort_array($arrayfields, 'position');
  153. $object = new PaymentVarious($db);
  154. $result = restrictedArea($user, 'banque', '', '', '');
  155. /*
  156. * Actions
  157. */
  158. if (GETPOST('cancel', 'alpha')) {
  159. $action = 'list';
  160. $massaction = '';
  161. }
  162. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  163. $massaction = '';
  164. }
  165. $parameters = array();
  166. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  167. if ($reshook < 0) {
  168. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  169. }
  170. if (empty($reshook)) {
  171. // Selection of new fields
  172. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  173. // Purge search criteria
  174. 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
  175. foreach ($object->fields as $key => $val) {
  176. $search[$key] = '';
  177. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  178. $search[$key.'_dtstart'] = '';
  179. $search[$key.'_dtend'] = '';
  180. }
  181. }
  182. $toselect = array();
  183. $search_array_options = array();
  184. }
  185. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  186. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  187. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  188. }
  189. }
  190. /*
  191. * View
  192. */
  193. $form = new Form($db);
  194. if ($arrayfields['account']['checked'] || $arrayfields['subledger']['checked']) {
  195. $formaccounting = new FormAccounting($db);
  196. }
  197. if ($arrayfields['bank']['checked'] && isModEnabled('accounting')) {
  198. $accountingjournal = new AccountingJournal($db);
  199. }
  200. if ($arrayfields['ref']['checked']) {
  201. $variousstatic = new PaymentVarious($db);
  202. }
  203. if ($arrayfields['bank']['checked']) {
  204. $accountstatic = new Account($db);
  205. }
  206. if ($arrayfields['project']['checked']) {
  207. $proj = new Project($db);
  208. }
  209. if ($arrayfields['entry']['checked']) {
  210. $bankline = new AccountLine($db);
  211. }
  212. if ($arrayfields['account']['checked']) {
  213. $accountingaccount = new AccountingAccount($db);
  214. }
  215. $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,";
  216. $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,";
  217. $sql .= " pst.code as payment_code";
  218. $sqlfields = $sql; // $sql fields to remove for count total
  219. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  220. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
  221. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  222. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  223. $sql .= " WHERE v.entity IN (".getEntity('payment_various').")";
  224. // Search criteria
  225. if ($search_ref) {
  226. $sql .= " AND v.rowid = ".((int) $search_ref);
  227. }
  228. if ($search_label) {
  229. $sql .= natural_search(array('v.label'), $search_label);
  230. }
  231. if ($search_datep_start) {
  232. $sql .= " AND v.datep >= '".$db->idate($search_datep_start)."'";
  233. }
  234. if ($search_datep_end) {
  235. $sql .= " AND v.datep <= '".$db->idate($search_datep_end)."'";
  236. }
  237. if ($search_datev_start) {
  238. $sql .= " AND v.datev >= '".$db->idate($search_datev_start)."'";
  239. }
  240. if ($search_datev_end) {
  241. $sql .= " AND v.datev <= '".$db->idate($search_datev_end)."'";
  242. }
  243. if ($search_amount_deb) {
  244. $sql .= natural_search("v.amount", $search_amount_deb, 1);
  245. }
  246. if ($search_amount_cred) {
  247. $sql .= natural_search("v.amount", $search_amount_cred, 1);
  248. }
  249. if ($search_bank_account > 0) {
  250. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  251. }
  252. if ($search_bank_entry > 0) {
  253. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  254. }
  255. if ($search_accountancy_account > 0) {
  256. $sql .= " AND v.accountancy_code = ".((int) $search_accountancy_account);
  257. }
  258. if ($search_accountancy_subledger > 0) {
  259. $sql .= " AND v.subledger_account = ".((int) $search_accountancy_subledger);
  260. }
  261. if ($search_type_id > 0) {
  262. $sql .= " AND v.fk_typepayment=".((int) $search_type_id);
  263. }
  264. if ($search_all) {
  265. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  266. }
  267. // Count total nb of records
  268. $nbtotalofrecords = '';
  269. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  270. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  271. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  272. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  273. $resql = $db->query($sqlforcount);
  274. if ($resql) {
  275. $objforcount = $db->fetch_object($resql);
  276. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  277. } else {
  278. dol_print_error($db);
  279. }
  280. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than paging size (filtering), goto and load page 0
  281. $page = 0;
  282. $offset = 0;
  283. }
  284. $db->free($resql);
  285. }
  286. // Complete request and execute it with limit
  287. $sql .= $db->order($sortfield, $sortorder);
  288. if ($limit) {
  289. $sql .= $db->plimit($limit + 1, $offset);
  290. }
  291. $resql = $db->query($sql);
  292. if (!$resql) {
  293. dol_print_error($db);
  294. exit;
  295. }
  296. $num = $db->num_rows($resql);
  297. // Direct jump if only one record found
  298. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  299. $obj = $db->fetch_object($resql);
  300. $id = $obj->rowid;
  301. header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$id);
  302. exit;
  303. }
  304. // must be place behind the last "header(...)" call
  305. llxHeader('', $langs->trans("VariousPayments"));
  306. $i = 0;
  307. $total = 0;
  308. $param = '';
  309. if (!empty($mode)) {
  310. $param .= '&mode='.urlencode($mode);
  311. }
  312. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  313. $param .= '&contextpage='.urlencode($contextpage);
  314. }
  315. if ($limit > 0 && $limit != $conf->liste_limit) {
  316. $param .= '&limit='.((int) $limit);
  317. }
  318. if ($search_ref) {
  319. $param .= '&search_ref='.urlencode($search_ref);
  320. }
  321. if ($search_label) {
  322. $param .= '&search_label='.urlencode($search_label);
  323. }
  324. if ($search_datep_start) {
  325. $param .= '&search_datep_start='.urlencode($search_datep_start);
  326. }
  327. if ($search_datep_end) {
  328. $param .= '&search_datep_end='.urlencode($search_datep_end);
  329. }
  330. if ($search_datev_start) {
  331. $param .= '&search_datev_start='.urlencode($search_datev_start);
  332. }
  333. if ($search_datev_end) {
  334. $param .= '&search_datev_end='.urlencode($search_datev_end);
  335. }
  336. if ($search_type_id > 0) {
  337. $param .= '&search_type_id='.urlencode($search_type_id);
  338. }
  339. if ($search_amount_deb) {
  340. $param .= '&search_amount_deb='.urlencode($search_amount_deb);
  341. }
  342. if ($search_amount_cred) {
  343. $param .= '&search_amount_cred='.urlencode($search_amount_cred);
  344. }
  345. if ($search_bank_account > 0) {
  346. $param .= '&search_account='.urlencode($search_bank_account);
  347. }
  348. if ($search_accountancy_account > 0) {
  349. $param .= '&search_accountancy_account='.urlencode($search_accountancy_account);
  350. }
  351. if ($search_accountancy_subledger > 0) {
  352. $param .= '&search_accountancy_subledger='.urlencode($search_accountancy_subledger);
  353. }
  354. if ($optioncss != '') {
  355. $param .= '&optioncss='.urlencode($optioncss);
  356. }
  357. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create';
  358. if (!empty($socid)) {
  359. $url .= '&socid='.urlencode($socid);
  360. }
  361. $newcardbutton = '';
  362. $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'));
  363. $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'));
  364. $newcardbutton .= dolGetButtonTitle($langs->trans('MenuNewVariousPayment'), '', 'fa fa-plus-circle', $url, '', $user->rights->banque->modifier);
  365. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  366. if ($optioncss != '') {
  367. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  368. }
  369. print '<input type="hidden" name="token" value="'.newToken().'">';
  370. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  371. print '<input type="hidden" name="action" value="list">';
  372. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  373. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  374. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  375. print '<input type="hidden" name="mode" value="'.$mode.'">';
  376. print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
  377. if ($search_all) {
  378. foreach ($fieldstosearchall as $key => $val) {
  379. $fieldstosearchall[$key] = $langs->trans($val);
  380. }
  381. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  382. }
  383. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  384. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  385. $moreforfilter= '';
  386. print '<div class="div-table-responsive">';
  387. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  388. print '<tr class="liste_titre">';
  389. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  390. print '<td class="liste_titre maxwidthsearch">';
  391. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  392. print $searchpicto;
  393. print '</td>';
  394. }
  395. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  396. print '<td class="liste_titre">';
  397. print '</td>';
  398. }
  399. // Ref
  400. if ($arrayfields['ref']['checked']) {
  401. print '<td class="liste_titre left">';
  402. print '<input class="flat" type="text" size="3" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  403. print '</td>';
  404. }
  405. // Label
  406. if ($arrayfields['label']['checked']) {
  407. print '<td class="liste_titre">';
  408. print '<input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  409. print '</td>';
  410. }
  411. // Payment date
  412. if ($arrayfields['datep']['checked']) {
  413. print '<td class="liste_titre center">';
  414. print '<div class="nowrap">';
  415. print $form->selectDate($search_datep_start ? $search_datep_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  416. print '</div>';
  417. print '<div class="nowrap">';
  418. print $form->selectDate($search_datep_end ? $search_datep_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  419. print '</div>';
  420. print '</td>';
  421. }
  422. // Value date
  423. if ($arrayfields['datev']['checked']) {
  424. print '<td class="liste_titre center">';
  425. print '<div class="nowrap">';
  426. print $form->selectDate($search_datev_start ? $search_datev_start : -1, 'search_date_value_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  427. print '</div>';
  428. print '<div class="nowrap">';
  429. print $form->selectDate($search_datev_end ? $search_datev_end : -1, 'search_date_value_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  430. print '</div>';
  431. print '</td>';
  432. }
  433. // Payment type
  434. if ($arrayfields['type']['checked']) {
  435. print '<td class="liste_titre center">';
  436. print $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16, 1, 'maxwidth100', 1);
  437. print '</td>';
  438. }
  439. // Project
  440. if ($arrayfields['project']['checked']) {
  441. print '<td class="liste_titre">';
  442. // TODO
  443. print '</td>';
  444. }
  445. // Bank account
  446. if ($arrayfields['bank']['checked']) {
  447. print '<td class="liste_titre">';
  448. $form->select_comptes($search_bank_account, 'search_account', 0, '', 1, '', 0, 'maxwidth100');
  449. print '</td>';
  450. }
  451. // Bank entry
  452. if ($arrayfields['entry']['checked']) {
  453. print '<td class="liste_titre left">';
  454. print '<input name="search_bank_entry" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_bank_entry).'">';
  455. print '</td>';
  456. }
  457. // Accounting account
  458. if (!empty($arrayfields['account']['checked'])) {
  459. print '<td class="liste_titre">';
  460. print '<div class="nowrap">';
  461. print $formaccounting->select_account($search_accountancy_account, 'search_accountancy_account', 1, array(), 1, 1, 'maxwidth200');
  462. print '</div>';
  463. print '</td>';
  464. }
  465. // Subledger account
  466. if (!empty($arrayfields['subledger']['checked'])) {
  467. print '<td class="liste_titre">';
  468. print '<div class="nowrap">';
  469. print $formaccounting->select_auxaccount($search_accountancy_subledger, 'search_accountancy_subledger', 1, 'maxwidth200');
  470. print '</div>';
  471. print '</td>';
  472. }
  473. // Debit
  474. if (!empty($arrayfields['debit']['checked'])) {
  475. print '<td class="liste_titre right">';
  476. print '<input name="search_amount_deb" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_amount_deb).'">';
  477. print '</td>';
  478. }
  479. // Credit
  480. if ($arrayfields['credit']['checked']) {
  481. print '<td class="liste_titre right">';
  482. print '<input name="search_amount_cred" class="flat maxwidth50" type="text" size="8" value="'.dol_escape_htmltag($search_amount_cred).'">';
  483. print '</td>';
  484. }
  485. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  486. print '<td class="liste_titre maxwidthsearch">';
  487. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  488. print $searchpicto;
  489. print '</td>';
  490. }
  491. print '</tr>';
  492. print '<tr class="liste_titre">';
  493. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  494. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  495. }
  496. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  497. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  498. }
  499. if ($arrayfields['ref']['checked']) {
  500. print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], 'v.rowid', '', $param, '', $sortfield, $sortorder);
  501. }
  502. if ($arrayfields['label']['checked']) {
  503. print_liste_field_titre($arrayfields['label']['label'], $_SERVER["PHP_SELF"], 'v.label', '', $param, '', $sortfield, $sortorder);
  504. }
  505. if ($arrayfields['datep']['checked']) {
  506. print_liste_field_titre($arrayfields['datep']['label'], $_SERVER["PHP_SELF"], 'v.datep,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  507. }
  508. if ($arrayfields['datev']['checked']) {
  509. print_liste_field_titre($arrayfields['datev']['label'], $_SERVER["PHP_SELF"], 'v.datev,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  510. }
  511. if ($arrayfields['type']['checked']) {
  512. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], 'type', '', $param, '', $sortfield, $sortorder, 'center ');
  513. }
  514. if ($arrayfields['project']['checked']) {
  515. print_liste_field_titre($arrayfields['project']['label'], $_SERVER["PHP_SELF"], 'fk_project', '', $param, '', $sortfield, $sortorder);
  516. }
  517. if ($arrayfields['bank']['checked']) {
  518. print_liste_field_titre($arrayfields['bank']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  519. }
  520. if ($arrayfields['entry']['checked']) {
  521. print_liste_field_titre($arrayfields['entry']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  522. }
  523. if (!empty($arrayfields['account']['checked'])) {
  524. print_liste_field_titre($arrayfields['account']['label'], $_SERVER["PHP_SELF"], 'v.accountancy_code', '', $param, '', $sortfield, $sortorder, 'left ');
  525. }
  526. if (!empty($arrayfields['subledger']['checked'])) {
  527. print_liste_field_titre($arrayfields['subledger']['label'], $_SERVER["PHP_SELF"], 'v.subledger_account', '', $param, '', $sortfield, $sortorder, 'left ');
  528. }
  529. if ($arrayfields['debit']['checked']) {
  530. print_liste_field_titre($arrayfields['debit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  531. }
  532. if ($arrayfields['credit']['checked']) {
  533. print_liste_field_titre($arrayfields['credit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  534. }
  535. // Fields from hook
  536. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  537. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  538. print $hookmanager->resPrint;
  539. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  540. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  541. }
  542. print '</tr>';
  543. $totalarray = array();
  544. $totalarray['nbfield'] = 0;
  545. $totalarray['val']['total_cred'] = 0;
  546. $totalarray['val']['total_deb'] = 0;
  547. $imaxinloop = ($limit ? min($num, $limit) : $num);
  548. while ($i < $imaxinloop) {
  549. $obj = $db->fetch_object($resql);
  550. $variousstatic->id = $obj->rowid;
  551. $variousstatic->ref = $obj->rowid;
  552. $variousstatic->label = $obj->label;
  553. $variousstatic->datep = $obj->datep;
  554. $variousstatic->type_payment = $obj->payment_code;
  555. $bankline->fetch($obj->fk_bank);
  556. $variousstatic->fk_bank = $bankline->getNomUrl(1);
  557. $variousstatic->amount = $obj->amount;
  558. $accountingaccount->fetch('', $obj->accountancy_code, 1);
  559. $variousstatic->accountancy_code = $accountingaccount->getNomUrl(0, 0, 1, $obj->accountingaccount, 1);
  560. if ($mode == 'kanban') {
  561. if ($i == 0) {
  562. print '<tr><td colspan="12">';
  563. print '<div class="box-flex-container kanban">';
  564. }
  565. // Output Kanban
  566. print $variousstatic->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  567. if ($i == ($imaxinloop) - 1) {
  568. print '</div>';
  569. print '</td></tr>';
  570. }
  571. } else {
  572. // Show here line of result
  573. $j = 0;
  574. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  575. // Action column
  576. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  577. print '<td></td>';
  578. if (!$i) {
  579. $totalarray['nbfield']++;
  580. }
  581. }
  582. // No
  583. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  584. print '<td>'.(($offset * $limit) + $i).'</td>';
  585. }
  586. // Ref
  587. if ($arrayfields['ref']['checked']) {
  588. print '<td>'.$variousstatic->getNomUrl(1)."</td>";
  589. if (!$i) {
  590. $totalarray['nbfield']++;
  591. }
  592. }
  593. // Label payment
  594. if ($arrayfields['label']['checked']) {
  595. print '<td class="tdoverflowmax150" title="'.$variousstatic->label.'">'.$variousstatic->label."</td>";
  596. if (!$i) {
  597. $totalarray['nbfield']++;
  598. }
  599. }
  600. // Date payment
  601. if ($arrayfields['datep']['checked']) {
  602. print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>";
  603. if (!$i) {
  604. $totalarray['nbfield']++;
  605. }
  606. }
  607. // Date value
  608. if ($arrayfields['datev']['checked']) {
  609. print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day')."</td>";
  610. if (!$i) {
  611. $totalarray['nbfield']++;
  612. }
  613. }
  614. // Type
  615. if ($arrayfields['type']['checked']) {
  616. print '<td class="center">';
  617. if ($obj->payment_code) {
  618. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  619. print ' ';
  620. }
  621. print $obj->num_payment;
  622. print '</td>';
  623. if (!$i) {
  624. $totalarray['nbfield']++;
  625. }
  626. }
  627. // Project
  628. if ($arrayfields['project']['checked']) {
  629. print '<td class="nowraponall">';
  630. if ($obj->fk_project > 0) {
  631. $proj->fetch($obj->fk_project);
  632. print $proj->getNomUrl(1);
  633. }
  634. print '</td>';
  635. if (!$i) {
  636. $totalarray['nbfield']++;
  637. }
  638. }
  639. // Bank account
  640. if ($arrayfields['bank']['checked']) {
  641. print '<td class="nowraponall">';
  642. if ($obj->bid > 0) {
  643. $accountstatic->id = $obj->bid;
  644. $accountstatic->ref = $obj->bref;
  645. $accountstatic->number = $obj->bnumber;
  646. if (isModEnabled('accounting')) {
  647. $accountstatic->account_number = $obj->bank_account_number;
  648. $accountingjournal->fetch($obj->accountancy_journal);
  649. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  650. }
  651. $accountstatic->label = $obj->blabel;
  652. print $accountstatic->getNomUrl(1);
  653. } else {
  654. print '&nbsp;';
  655. }
  656. print '</td>';
  657. if (!$i) {
  658. $totalarray['nbfield']++;
  659. }
  660. }
  661. // Bank entry
  662. if ($arrayfields['entry']['checked']) {
  663. $bankline->fetch($obj->fk_bank);
  664. print '<td>'.$bankline->getNomUrl(1).'</td>';
  665. if (!$i) {
  666. $totalarray['nbfield']++;
  667. }
  668. }
  669. // Accounting account
  670. if (!empty($arrayfields['account']['checked'])) {
  671. $accountingaccount->fetch('', $obj->accountancy_code, 1);
  672. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->accountancy_code.' '.$accountingaccount->label).'">'.$accountingaccount->getNomUrl(0, 1, 1, '', 1).'</td>';
  673. if (!$i) {
  674. $totalarray['nbfield']++;
  675. }
  676. }
  677. // Accounting subledger account
  678. if (!empty($arrayfields['subledger']['checked'])) {
  679. print '<td class="tdoverflowmax150">'.length_accounta($obj->subledger_account).'</td>';
  680. if (!$i) {
  681. $totalarray['nbfield']++;
  682. }
  683. }
  684. // Debit
  685. if ($arrayfields['debit']['checked']) {
  686. print '<td class="nowrap right">';
  687. if ($obj->sens == 0) {
  688. print '<span class="amount">'.price($obj->amount).'</span>';
  689. $totalarray['val']['total_deb'] += $obj->amount;
  690. }
  691. if (!$i) {
  692. $totalarray['nbfield']++;
  693. }
  694. if (!$i) {
  695. $totalarray['pos'][$totalarray['nbfield']] = 'total_deb';
  696. }
  697. print '</td>';
  698. }
  699. // Credit
  700. if ($arrayfields['credit']['checked']) {
  701. print '<td class="nowrap right">';
  702. if ($obj->sens == 1) {
  703. print '<span class="amount">'.price($obj->amount).'</span>';
  704. $totalarray['val']['total_cred'] += $obj->amount;
  705. }
  706. if (!$i) {
  707. $totalarray['nbfield']++;
  708. }
  709. if (!$i) {
  710. $totalarray['pos'][$totalarray['nbfield']] = 'total_cred';
  711. }
  712. print '</td>';
  713. }
  714. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  715. print '<td></td>';
  716. if (!$i) {
  717. $totalarray['nbfield']++;
  718. }
  719. }
  720. print '</tr>'."\n";
  721. }
  722. $i++;
  723. }
  724. // Show total line
  725. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  726. // If no record found
  727. if ($num == 0) {
  728. $colspan = 1;
  729. foreach ($arrayfields as $key => $val) {
  730. if (!empty($val['checked'])) {
  731. $colspan++;
  732. }
  733. }
  734. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  735. }
  736. $db->free($resql);
  737. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  738. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  739. print $hookmanager->resPrint;
  740. print '</table>'."\n";
  741. print '</div>'."\n";
  742. print '</form>'."\n";
  743. // End of page
  744. llxFooter();
  745. $db->close();