list.php 27 KB

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