list.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2017-2023 Alexandre Spangaro <aspangaro@easya.solutions>
  9. * Copyright (C) 2018-2021 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  11. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/compta/paiement/list.php
  28. * \ingroup compta
  29. * \brief Payment page for customer invoices
  30. */
  31. // Load Dolibarr environment
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('bills', 'banks', 'compta', 'companies'));
  40. $action = GETPOST('action', 'alpha');
  41. $massaction = GETPOST('massaction', 'alpha');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. $optioncss = GETPOST('optioncss', 'alpha');
  44. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'paymentlist';
  45. $facid = GETPOST('facid', 'int');
  46. $socid = GETPOST('socid', 'int');
  47. $userid = GETPOST('userid', 'int');
  48. $search_ref = GETPOST("search_ref", "alpha");
  49. $search_date_startday = GETPOST('search_date_startday', 'int');
  50. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  51. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  52. $search_date_endday = GETPOST('search_date_endday', 'int');
  53. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  54. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  55. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  56. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  57. $search_company = GETPOST("search_company", 'alpha');
  58. $search_paymenttype = GETPOST("search_paymenttype");
  59. $search_account = GETPOST("search_account", "int");
  60. $search_payment_num = GETPOST('search_payment_num', 'alpha');
  61. $search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x"
  62. $search_status = GETPOST('search_status', 'intcomma');
  63. $search_sale = GETPOST('search_sale', 'int');
  64. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  65. $sortfield = GETPOST('sortfield', 'aZ09comma');
  66. $sortorder = GETPOST('sortorder', 'aZ09comma');
  67. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  68. if (empty($page) || $page == -1) {
  69. $page = 0; // If $page is not defined, or '' or -1
  70. }
  71. $offset = $limit * $page;
  72. $pageprev = $page - 1;
  73. $pagenext = $page + 1;
  74. if (!$sortorder) {
  75. $sortorder = "DESC";
  76. }
  77. if (!$sortfield) {
  78. $sortfield = "p.ref";
  79. }
  80. $search_all = trim(GETPOSTISSET("search_all") ? GETPOST("search_all", 'alpha') : GETPOST('sall'));
  81. // List of fields to search into when doing a "search in all"
  82. $fieldstosearchall = array(
  83. 'p.ref'=>"RefPayment",
  84. 's.nom'=>"ThirdParty",
  85. 'p.num_paiement'=>"Numero",
  86. 'p.amount'=>"Amount",
  87. );
  88. $arrayfields = array(
  89. 'p.ref' => array('label'=>"RefPayment", 'checked'=>1, 'position'=>10),
  90. 'p.datep' => array('label'=>"Date", 'checked'=>1, 'position'=>20),
  91. 's.nom' => array('label'=>"ThirdParty", 'checked'=>1, 'position'=>30),
  92. 'c.libelle' => array('label'=>"Type", 'checked'=>1, 'position'=>40),
  93. 'transaction' => array('label'=>"BankTransactionLine", 'checked'=>1, 'position'=>50, 'enabled'=>(isModEnabled("banque"))),
  94. 'ba.label' => array('label'=>"Account", 'checked'=>1, 'position'=>60, 'enabled'=>(isModEnabled("banque"))),
  95. 'p.num_paiement' => array('label'=>"Numero", 'checked'=>1, 'position'=>70, 'tooltip'=>"ChequeOrTransferNumber"),
  96. 'p.amount' => array('label'=>"Amount", 'checked'=>1, 'position'=>80),
  97. 'p.statut' => array('label'=>"Status", 'checked'=>1, 'position'=>90, 'enabled'=>(getDolGlobalString('BILL_ADD_PAYMENT_VALIDATION'))),
  98. );
  99. $arrayfields = dol_sort_array($arrayfields, 'position');
  100. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  101. $hookmanager->initHooks(array('paymentlist'));
  102. $object = new Paiement($db);
  103. if (!$user->hasRight('societe', 'client', 'voir')) {
  104. $search_sale = $user->id;
  105. }
  106. // Security check
  107. if ($user->socid) {
  108. $socid = $user->socid;
  109. }
  110. $result = restrictedArea($user, 'facture', $facid, '');
  111. /*
  112. * Actions
  113. */
  114. $parameters = array('socid'=>$socid);
  115. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  116. if ($reshook < 0) {
  117. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  118. }
  119. if (empty($reshook)) {
  120. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  121. // All tests are required to be compatible with all browsers
  122. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  123. $search_ref = '';
  124. $search_date_startday = '';
  125. $search_date_startmonth = '';
  126. $search_date_startyear = '';
  127. $search_date_endday = '';
  128. $search_date_endmonth = '';
  129. $search_date_endyear = '';
  130. $search_date_start = '';
  131. $search_date_end = '';
  132. $search_account = '';
  133. $search_amount = '';
  134. $search_paymenttype = '';
  135. $search_payment_num = '';
  136. $search_company = '';
  137. $search_status = '';
  138. $option = '';
  139. $toselect = array();
  140. $search_array_options = array();
  141. }
  142. }
  143. /*
  144. * View
  145. */
  146. $form = new Form($db);
  147. $formother = new FormOther($db);
  148. $accountstatic = new Account($db);
  149. $companystatic = new Societe($db);
  150. $bankline = new AccountLine($db);
  151. llxHeader('', $langs->trans('ListPayment'));
  152. if (GETPOST("orphelins", "alpha")) {
  153. // Payments not linked to an invoice. Should not happend. For debug only.
  154. $sql = "SELECT p.rowid, p.ref, p.datep, p.amount, p.statut, p.num_paiement as num_payment,";
  155. $sql .= " c.code as paiement_code";
  156. $sqlfields = $sql; // $sql fields to remove for count total
  157. // Add fields from hooks
  158. $parameters = array();
  159. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  160. $sql .= $hookmanager->resPrint;
  161. $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
  162. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  163. $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
  164. $sql .= " AND pf.fk_facture IS NULL";
  165. // Add where from hooks
  166. $parameters = array();
  167. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  168. $sql .= $hookmanager->resPrint;
  169. } else {
  170. $sql = "SELECT p.rowid, p.ref, p.datep, p.fk_bank, p.statut, p.num_paiement as num_payment, p.amount";
  171. $sql .= ", c.code as paiement_code";
  172. $sql .= ", ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.fk_accountancy_journal as accountancy_journal";
  173. $sql .= ", s.rowid as socid, s.nom as name, s.email";
  174. // We need an aggregate because we added a left join to get the thirdparty. In real world, it should be the same thirdparty if payment is same (but not in database structure)
  175. // so SUM(pf.amount) should be equal to p.amount but if we filter on $socid, it may differ
  176. $sql .= ", SUM(pf.amount) as totalamount, COUNT(f.rowid) as nbinvoices";
  177. // Add fields from hooks
  178. $parameters = array();
  179. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  180. $sql .= $hookmanager->resPrint;
  181. $sqlfields = $sql; // $sql fields to remove for count total
  182. $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
  183. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
  184. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
  185. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  186. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
  187. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
  188. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
  189. $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
  190. if ($socid > 0) {
  191. $sql .= " AND EXISTS (SELECT f.fk_soc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf";
  192. $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = ".((int) $socid).")";
  193. }
  194. if ($userid) {
  195. if ($userid == -1) {
  196. $sql .= " AND p.fk_user_creat IS NULL";
  197. } else {
  198. $sql .= " AND p.fk_user_creat = ".((int) $userid);
  199. }
  200. }
  201. // Search criteria
  202. if ($search_ref) {
  203. $sql .= natural_search('p.ref', $search_ref);
  204. }
  205. if ($search_date_start) {
  206. $sql .= " AND p.datep >= '" . $db->idate($search_date_start) . "'";
  207. }
  208. if ($search_date_end) {
  209. $sql .= " AND p.datep <= '" . $db->idate($search_date_end) . "'";
  210. }
  211. if ($search_account > 0) {
  212. $sql .= " AND b.fk_account=".((int) $search_account);
  213. }
  214. if ($search_paymenttype != '') {
  215. $sql .= " AND c.code='".$db->escape($search_paymenttype)."'";
  216. }
  217. if ($search_payment_num != '') {
  218. $sql .= natural_search('p.num_paiement', $search_payment_num);
  219. }
  220. if ($search_amount) {
  221. $sql .= " AND (".natural_search('p.amount', $search_amount, 1, 1);
  222. $sql .= " OR ";
  223. $sql .= natural_search('pf.amount', $search_amount, 1, 1);
  224. $sql .= ")";
  225. }
  226. if ($search_company) {
  227. $sql .= natural_search('s.nom', $search_company);
  228. }
  229. // Search on sale representative
  230. if ($search_sale && $search_sale != '-1') {
  231. if ($search_sale == -2) {
  232. $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)";
  233. } elseif ($search_sale > 0) {
  234. $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
  235. }
  236. }
  237. if ($search_all) {
  238. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  239. }
  240. // Add where from hooks
  241. $parameters = array();
  242. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  243. $sql .= $hookmanager->resPrint;
  244. $sql .= " GROUP BY p.rowid, p.ref, p.datep, p.fk_bank, p.statut, p.num_paiement, p.amount";
  245. $sql .= ", c.code";
  246. $sql .= ", ba.rowid, ba.ref, ba.label, ba.number, ba.account_number, ba.fk_accountancy_journal";
  247. $sql .= ", s.rowid, s.nom, s.email";
  248. }
  249. // Count total nb of records
  250. $nbtotalofrecords = '';
  251. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  252. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  253. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(DISTINCT p.rowid) as nbtotalofrecords', $sql);
  254. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  255. $resql = $db->query($sqlforcount);
  256. if ($resql) {
  257. $objforcount = $db->fetch_object($resql);
  258. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  259. } else {
  260. dol_print_error($db);
  261. }
  262. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  263. $page = 0;
  264. $offset = 0;
  265. }
  266. $db->free($resql);
  267. }
  268. // Complete request and execute it with limit
  269. $sql .= $db->order($sortfield, $sortorder);
  270. if ($limit) {
  271. $sql .= $db->plimit($limit + 1, $offset);
  272. }
  273. //print $sql;
  274. $resql = $db->query($sql);
  275. if (!$resql) {
  276. dol_print_error($db);
  277. llxFooter();
  278. $db->close();
  279. exit;
  280. }
  281. $num = $db->num_rows($resql);
  282. $param = '';
  283. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  284. $param .= '&contextpage='.urlencode($contextpage);
  285. }
  286. if ($limit > 0 && $limit != $conf->liste_limit) {
  287. $param .= '&limit='.((int) $limit);
  288. }
  289. if (GETPOST("orphelins")) {
  290. $param .= '&orphelins=1';
  291. }
  292. if ($search_ref) {
  293. $param .= '&search_ref='.urlencode($search_ref);
  294. }
  295. if ($search_date_startday) {
  296. $param .= '&search_date_startday='.urlencode($search_date_startday);
  297. }
  298. if ($search_date_startmonth) {
  299. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  300. }
  301. if ($search_date_startyear) {
  302. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  303. }
  304. if ($search_date_endday) {
  305. $param .= '&search_date_endday='.urlencode($search_date_endday);
  306. }
  307. if ($search_date_endmonth) {
  308. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  309. }
  310. if ($search_date_endyear) {
  311. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  312. }
  313. if ($search_company) {
  314. $param .= '&search_company='.urlencode($search_company);
  315. }
  316. if ($search_amount != '') {
  317. $param .= '&search_amount='.urlencode($search_amount);
  318. }
  319. if ($search_paymenttype) {
  320. $param .= '&search_paymenttype='.urlencode($search_paymenttype);
  321. }
  322. if ($search_account) {
  323. $param .= '&search_account='.urlencode($search_account);
  324. }
  325. if ($search_payment_num) {
  326. $param .= '&search_payment_num='.urlencode($search_payment_num);
  327. }
  328. if ($optioncss != '') {
  329. $param .= '&optioncss='.urlencode($optioncss);
  330. }
  331. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  332. if ($optioncss != '') {
  333. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  334. }
  335. print '<input type="hidden" name="token" value="'.newToken().'">';
  336. print '<input type="hidden" name="action" value="list">';
  337. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  338. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  339. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  340. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  341. print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
  342. if ($search_all) {
  343. foreach ($fieldstosearchall as $key => $val) {
  344. $fieldstosearchall[$key] = $langs->trans($val);
  345. }
  346. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  347. }
  348. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  349. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  350. $massactionbutton = '';
  351. if ($massactionbutton) {
  352. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  353. }
  354. $moreforfilter = '';
  355. print '<div class="div-table-responsive">';
  356. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : '').'">';
  357. // Fields title search
  358. // --------------------------------------------------------------------
  359. print '<tr class="liste_titre_filter">';
  360. // Action column
  361. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  362. print '<td class="liste_titre center maxwidthsearch">';
  363. $searchpicto = $form->showFilterButtons('left');
  364. print $searchpicto;
  365. print '</td>';
  366. }
  367. // #
  368. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  369. print '<td class="liste_titre">';
  370. print '</td>';
  371. }
  372. // Filter: Ref
  373. if (!empty($arrayfields['p.ref']['checked'])) {
  374. print '<td class="liste_titre left">';
  375. print '<input class="flat" type="text" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  376. print '</td>';
  377. }
  378. // Filter: Date
  379. if (!empty($arrayfields['p.datep']['checked'])) {
  380. print '<td class="liste_titre center">';
  381. print '<div class="nowrapfordate">';
  382. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  383. print '</div>';
  384. print '<div class="nowrapfordate">';
  385. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  386. print '</div>';
  387. print '</td>';
  388. }
  389. // Filter: Thirdparty
  390. if (!empty($arrayfields['s.nom']['checked'])) {
  391. print '<td class="liste_titre">';
  392. print '<input class="flat" type="text" size="6" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  393. print '</td>';
  394. }
  395. // Filter: Payment type
  396. if (!empty($arrayfields['c.libelle']['checked'])) {
  397. print '<td class="liste_titre">';
  398. print $form->select_types_paiements($search_paymenttype, 'search_paymenttype', '', 2, 1, 1, 0, 1, 'maxwidth100', 1);
  399. print '</td>';
  400. }
  401. // Filter: Bank transaction number
  402. if (!empty($arrayfields['transaction']['checked'])) {
  403. print '<td class="liste_titre">';
  404. print '<input class="flat" type="text" size="4" name="search_payment_num" value="'.dol_escape_htmltag($search_payment_num).'">';
  405. print '</td>';
  406. }
  407. // Filter: Cheque number (fund transfer)
  408. if (!empty($arrayfields['p.num_paiement']['checked'])) {
  409. print '<td class="liste_titre">';
  410. print '</td>';
  411. }
  412. // Filter: Bank account
  413. if (!empty($arrayfields['ba.label']['checked'])) {
  414. print '<td class="liste_titre">';
  415. $form->select_comptes($search_account, 'search_account', 0, '', 1);
  416. print '</td>';
  417. }
  418. // Filter: Amount
  419. if (!empty($arrayfields['p.amount']['checked'])) {
  420. print '<td class="liste_titre right">';
  421. print '<input class="flat" type="text" size="4" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
  422. print '</td>';
  423. }
  424. // Filter: Status (only placeholder)
  425. if (!empty($arrayfields['p.statut']['checked'])) {
  426. print '<td class="liste_titre right">';
  427. print '</td>';
  428. }
  429. // Fields from hook
  430. $parameters = array('arrayfields'=>$arrayfields);
  431. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  432. print $hookmanager->resPrint;
  433. // Action column
  434. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  435. print '<td class="liste_titre center maxwidthsearch">';
  436. $searchpicto = $form->showFilterButtons();
  437. print $searchpicto;
  438. print '</td>';
  439. }
  440. print '</tr>'."\n";
  441. $totalarray = array();
  442. $totalarray['nbfield'] = 0;
  443. // Fields title label
  444. // --------------------------------------------------------------------
  445. print '<tr class="liste_titre">';
  446. // Action column
  447. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  448. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  449. $totalarray['nbfield']++;
  450. }
  451. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  452. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  453. $totalarray['nbfield']++;
  454. }
  455. if (!empty($arrayfields['p.ref']['checked'])) {
  456. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  457. $totalarray['nbfield']++;
  458. }
  459. if (!empty($arrayfields['p.datep']['checked'])) {
  460. print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], "p.datep", '', $param, '', $sortfield, $sortorder, 'center ');
  461. $totalarray['nbfield']++;
  462. }
  463. if (!empty($arrayfields['s.nom']['checked'])) {
  464. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
  465. $totalarray['nbfield']++;
  466. }
  467. if (!empty($arrayfields['c.libelle']['checked'])) {
  468. print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", '', $param, '', $sortfield, $sortorder);
  469. $totalarray['nbfield']++;
  470. }
  471. if (!empty($arrayfields['p.num_paiement']['checked'])) {
  472. print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
  473. $totalarray['nbfield']++;
  474. }
  475. if (!empty($arrayfields['transaction']['checked'])) {
  476. print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
  477. $totalarray['nbfield']++;
  478. }
  479. if (!empty($arrayfields['ba.label']['checked'])) {
  480. print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", '', $param, '', $sortfield, $sortorder);
  481. $totalarray['nbfield']++;
  482. }
  483. if (!empty($arrayfields['p.amount']['checked'])) {
  484. print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], "p.amount", '', $param, 'class="right"', $sortfield, $sortorder);
  485. $totalarray['nbfield']++;
  486. }
  487. if (!empty($arrayfields['p.statut']['checked'])) {
  488. print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", '', $param, 'class="right"', $sortfield, $sortorder);
  489. $totalarray['nbfield']++;
  490. }
  491. // Extra fields
  492. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  493. // Hook fields
  494. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  495. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  496. print $hookmanager->resPrint;
  497. // Action column
  498. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  499. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  500. $totalarray['nbfield']++;
  501. }
  502. print '</tr>'."\n";
  503. // Detect if we need a fetch on each output line
  504. $needToFetchEachLine = 0;
  505. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  506. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  507. if (!is_null($val) && preg_match('/\$object/', $val)) {
  508. $needToFetchEachLine++; // There is at least one compute field that use $object
  509. }
  510. }
  511. }
  512. // Loop on record
  513. // --------------------------------------------------------------------
  514. $i = 0;
  515. $savnbfield = $totalarray['nbfield'];
  516. $totalarray = array();
  517. $totalarray['nbfield'] = 0;
  518. $imaxinloop = ($limit ? min($num, $limit) : $num);
  519. while ($i < $imaxinloop) {
  520. $objp = $db->fetch_object($resql);
  521. if (empty($objp)) {
  522. break; // Should not happen
  523. }
  524. $object->id = $objp->rowid;
  525. $object->ref = ($objp->ref ? $objp->ref : $objp->rowid);
  526. $object->date = $db->jdate($objp->datep);
  527. $object->amount = $objp->amount;
  528. $companystatic->id = $objp->socid;
  529. $companystatic->name = $objp->name;
  530. $companystatic->email = $objp->email;
  531. if ($mode == 'kanban') {
  532. if ($i == 0) {
  533. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  534. print '<div class="box-flex-container kanban">';
  535. }
  536. // Output Kanban
  537. $selected = -1;
  538. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  539. $selected = 0;
  540. if (in_array($object->id, $arrayofselected)) {
  541. $selected = 1;
  542. }
  543. }
  544. //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
  545. print $object->getKanbanView('', array('selected' => $selected));
  546. if ($i == ($imaxinloop - 1)) {
  547. print '</div>';
  548. print '</td></tr>';
  549. }
  550. } else {
  551. // Show line of result
  552. $j = 0;
  553. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  554. // Action column
  555. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  556. print '<td class="nowrap center">';
  557. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  558. $selected = 0;
  559. if (in_array($object->id, $arrayofselected)) {
  560. $selected = 1;
  561. }
  562. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  563. }
  564. print '</td>';
  565. if (!$i) {
  566. $totalarray['nbfield']++;
  567. }
  568. }
  569. // No
  570. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
  571. print '<td class="nowraponall">'.(($offset * $limit) + $i).'</td>';
  572. if (!$i) {
  573. $totalarray['nbfield']++;
  574. }
  575. }
  576. // Ref
  577. if (!empty($arrayfields['p.ref']['checked'])) {
  578. print '<td class="nowraponall">'.$object->getNomUrl(1).'</td>';
  579. if (!$i) {
  580. $totalarray['nbfield']++;
  581. }
  582. }
  583. // Date
  584. if (!empty($arrayfields['p.datep']['checked'])) {
  585. $dateformatforpayment = 'dayhour';
  586. print '<td class="nowraponall center">'.dol_print_date($db->jdate($objp->datep), $dateformatforpayment, 'tzuser').'</td>';
  587. if (!$i) {
  588. $totalarray['nbfield']++;
  589. }
  590. }
  591. // Thirdparty
  592. if (!empty($arrayfields['s.nom']['checked'])) {
  593. print '<td class="tdoverflowmax125">';
  594. if ($objp->socid > 0) {
  595. print $companystatic->getNomUrl(1, '', 24);
  596. }
  597. print '</td>';
  598. if (!$i) {
  599. $totalarray['nbfield']++;
  600. }
  601. }
  602. // Payment type
  603. if (!empty($arrayfields['c.libelle']['checked'])) {
  604. print '<td>'.$langs->trans("PaymentTypeShort".$objp->paiement_code).'</td>';
  605. if (!$i) {
  606. $totalarray['nbfield']++;
  607. }
  608. }
  609. // Filter: Cheque number (fund transfer)
  610. if (!empty($arrayfields['p.num_paiement']['checked'])) {
  611. print '<td>'.$objp->num_payment.'</td>';
  612. if (!$i) {
  613. $totalarray['nbfield']++;
  614. }
  615. }
  616. // Bank transaction
  617. if (!empty($arrayfields['transaction']['checked'])) {
  618. print '<td class="tdoverflowmax125">';
  619. if ($objp->fk_bank > 0) {
  620. $bankline->fetch($objp->fk_bank);
  621. print $bankline->getNomUrl(1, 0);
  622. }
  623. print '</td>';
  624. if (!$i) {
  625. $totalarray['nbfield']++;
  626. }
  627. }
  628. // Bank account
  629. if (!empty($arrayfields['ba.label']['checked'])) {
  630. print '<td>';
  631. if ($objp->bid > 0) {
  632. $accountstatic->id = $objp->bid;
  633. $accountstatic->ref = $objp->bref;
  634. $accountstatic->label = $objp->blabel;
  635. $accountstatic->number = $objp->number;
  636. $accountstatic->account_number = $objp->account_number;
  637. $accountingjournal = new AccountingJournal($db);
  638. $accountingjournal->fetch($objp->accountancy_journal);
  639. $accountstatic->accountancy_journal = $accountingjournal->code;
  640. print $accountstatic->getNomUrl(1);
  641. }
  642. print '</td>';
  643. if (!$i) {
  644. $totalarray['nbfield']++;
  645. }
  646. }
  647. // Amount
  648. if (!empty($arrayfields['p.amount']['checked'])) {
  649. print '<td class="right">';
  650. if ($objp->nbinvoices > 1 || ($objp->totalamount && $objp->amount != $objp->totalamount)) {
  651. print $form->textwithpicto('', $langs->trans("PaymentMadeForSeveralInvoices"));
  652. }
  653. print '<span class="amount">'.price($objp->amount).'</span>';
  654. print '</td>';
  655. if (!$i) {
  656. $totalarray['nbfield']++;
  657. $totalarray['pos'][$totalarray['nbfield']] = 'amount';
  658. }
  659. if (empty($totalarray['val']['amount'])) {
  660. $totalarray['val']['amount'] = $objp->amount;
  661. } else {
  662. $totalarray['val']['amount'] += $objp->amount;
  663. }
  664. }
  665. // Status
  666. if (!empty($arrayfields['p.statut']['checked'])) {
  667. print '<td class="right">';
  668. if ($objp->statut == 0) {
  669. print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">';
  670. }
  671. print $object->LibStatut($objp->statut, 5);
  672. if ($objp->statut == 0) {
  673. print '</a>';
  674. }
  675. print '</td>';
  676. if (!$i) {
  677. $totalarray['nbfield']++;
  678. }
  679. }
  680. // Action column
  681. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  682. print '<td class="nowrap center">';
  683. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  684. $selected = 0;
  685. if (in_array($object->id, $arrayofselected)) {
  686. $selected = 1;
  687. }
  688. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  689. }
  690. print '</td>';
  691. if (!$i) {
  692. $totalarray['nbfield']++;
  693. }
  694. }
  695. print '</tr>'."\n";
  696. }
  697. $i++;
  698. }
  699. // Show total line
  700. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  701. // If no record found
  702. if ($num == 0) {
  703. $colspan = 1;
  704. foreach ($arrayfields as $key => $val) {
  705. if (!empty($val['checked'])) {
  706. $colspan++;
  707. }
  708. }
  709. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  710. }
  711. $db->free($resql);
  712. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  713. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  714. print $hookmanager->resPrint;
  715. print '</table>'."\n";
  716. print '</div>'."\n";
  717. print '</form>'."\n";
  718. // End of page
  719. llxFooter();
  720. $db->close();