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