list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2018 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/prelevement/list.php
  23. * \ingroup prelevement
  24. * \brief Page list of direct debit orders or credit transfers orders
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('banks', 'withdrawals', 'companies', 'categories'));
  33. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  34. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  35. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  36. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  37. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  38. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlinelist'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  41. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  42. $type = GETPOST('type', 'aZ09');
  43. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortorder) {
  54. $sortorder = "DESC";
  55. }
  56. if (!$sortfield) {
  57. $sortfield = "p.datec";
  58. }
  59. $search_line = GETPOST('search_line', 'alpha');
  60. $search_bon = GETPOST('search_bon', 'alpha');
  61. $search_code = GETPOST('search_code', 'alpha');
  62. $search_company = GETPOST('search_company', 'alpha');
  63. $statut = GETPOST('statut', 'int');
  64. $bon = new BonPrelevement($db);
  65. $line = new LignePrelevement($db);
  66. $company = new Societe($db);
  67. $hookmanager->initHooks(array('withdrawalsreceiptslineslist'));
  68. // Security check
  69. $socid = GETPOST('socid', 'int');
  70. if ($user->socid) {
  71. $socid = $user->socid;
  72. }
  73. if ($type == 'bank-transfer') {
  74. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  75. } else {
  76. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  77. }
  78. /*
  79. * Actions
  80. */
  81. 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
  82. $search_line = "";
  83. $search_bon = "";
  84. $search_code = "";
  85. $search_company = "";
  86. $statut = "";
  87. }
  88. /*
  89. * View
  90. */
  91. $form = new Form($db);
  92. llxHeader('', $langs->trans("WithdrawalsLines"));
  93. $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
  94. $sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
  95. $sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
  96. $sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
  97. $sqlfields = $sql; // $sql fields to remove for count total
  98. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  99. $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  100. $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
  101. if ($type == 'bank-transfer') {
  102. $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
  103. } else {
  104. $sql .= " , ".MAIN_DB_PREFIX."facture as f";
  105. }
  106. $sql .= " , ".MAIN_DB_PREFIX."societe as s";
  107. $sql .= " WHERE pl.fk_prelevement_bons = p.rowid";
  108. $sql .= " AND pf.fk_prelevement_lignes = pl.rowid";
  109. if ($type == 'bank-transfer') {
  110. $sql .= " AND pf.fk_facture_fourn = f.rowid";
  111. } else {
  112. $sql .= " AND pf.fk_facture = f.rowid";
  113. }
  114. $sql .= " AND f.fk_soc = s.rowid";
  115. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  116. if ($socid) {
  117. $sql .= " AND s.rowid = ".((int) $socid);
  118. }
  119. if ($search_line) {
  120. $sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
  121. }
  122. if ($search_bon) {
  123. $sql .= natural_search("p.ref", $search_bon);
  124. }
  125. if ($type == 'bank-transfer') {
  126. if ($search_code) {
  127. $sql .= natural_search("s.code_fournisseur", $search_code);
  128. }
  129. } else {
  130. if ($search_code) {
  131. $sql .= natural_search("s.code_client", $search_code);
  132. }
  133. }
  134. if ($search_company) {
  135. $sql .= natural_search("s.nom", $search_company);
  136. }
  137. // Count total nb of records
  138. $nbtotalofrecords = '';
  139. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  140. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  141. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  142. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  143. $resql = $db->query($sqlforcount);
  144. if ($resql) {
  145. $objforcount = $db->fetch_object($resql);
  146. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  147. } else {
  148. dol_print_error($db);
  149. }
  150. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  151. $page = 0;
  152. $offset = 0;
  153. }
  154. $db->free($resql);
  155. }
  156. $sql .= $db->order($sortfield, $sortorder);
  157. if ($limit) {
  158. $sql .= $db->plimit($limit + 1, $offset);
  159. }
  160. $result = $db->query($sql);
  161. if ($result) {
  162. $num = $db->num_rows($result);
  163. $i = 0;
  164. $param = "&amp;statut=".urlencode($statut);
  165. $param .= "&amp;search_bon=".urlencode($search_bon);
  166. if ($type == 'bank-transfer') {
  167. $param .= '&amp;type=bank-transfer';
  168. }
  169. if ($limit > 0 && $limit != $conf->liste_limit) {
  170. $param .= '&limit='.urlencode($limit);
  171. }
  172. print"\n<!-- debut table -->\n";
  173. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  174. if ($optioncss != '') {
  175. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  176. }
  177. print '<input type="hidden" name="token" value="'.newToken().'">';
  178. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  179. print '<input type="hidden" name="action" value="list">';
  180. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  181. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  182. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  183. if ($type != '') {
  184. print '<input type="hidden" name="type" value="'.$type.'">';
  185. }
  186. $title = $langs->trans("WithdrawalsLines");
  187. if ($type == 'bank-transfer') {
  188. $title = $langs->trans("CreditTransferLines");
  189. }
  190. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 0, 0, 1);
  191. $moreforfilter = '';
  192. print '<div class="div-table-responsive">';
  193. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  194. print '<tr class="liste_titre">';
  195. print '<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'.dol_escape_htmltag($search_line).'" size="6"></td>';
  196. print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'.dol_escape_htmltag($search_bon).'" size="6"></td>';
  197. print '<td class="liste_titre">&nbsp;</td>';
  198. print '<td class="liste_titre"><input type="text" class="flat" name="search_company" value="'.dol_escape_htmltag($search_company).'" size="6"></td>';
  199. print '<td class="liste_titre center"><input type="text" class="flat" name="search_code" value="'.dol_escape_htmltag($search_code).'" size="6"></td>';
  200. print '<td class="liste_titre">&nbsp;</td>';
  201. print '<td class="liste_titre">&nbsp;</td>';
  202. print '<td class="liste_titre maxwidthsearch">';
  203. $searchpicto = $form->showFilterButtons();
  204. print $searchpicto;
  205. print '</td>';
  206. print '</tr>';
  207. $columntitle = "WithdrawalsReceipts";
  208. $columntitlethirdparty = "CustomerCode";
  209. $columncodethirdparty = "s.code_client";
  210. if ($type == 'bank-transfer') {
  211. $columntitle = "BankTransferReceipts";
  212. $columntitlethirdparty = "SupplierCode";
  213. $columncodethirdparty = "s.code_fournisseur";
  214. }
  215. print '<tr class="liste_titre">';
  216. print_liste_field_titre($columntitle, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  217. print_liste_field_titre("Line", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
  218. print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "f.ref", '', $param, '', $sortfield, $sortorder);
  219. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
  220. print_liste_field_titre($columntitlethirdparty, $_SERVER["PHP_SELF"], $columncodethirdparty, '', $param, '', $sortfield, $sortorder, 'center ');
  221. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
  222. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $param, '', $sortfield, $sortorder, 'right ');
  223. print_liste_field_titre('');
  224. print "</tr>\n";
  225. if ($num) {
  226. while ($i < min($num, $limit)) {
  227. $obj = $db->fetch_object($result);
  228. $bon->id = $obj->rowid;
  229. $bon->ref = $obj->ref;
  230. $bon->statut = $obj->status;
  231. $company->id = $obj->socid;
  232. $company->name = $obj->name;
  233. $company->email = $obj->email;
  234. $company->code_client = $obj->code_client;
  235. print '<tr class="oddeven">';
  236. print '<td>';
  237. print $bon->getNomUrl(1);
  238. print "</td>\n";
  239. print '<td>';
  240. print $line->LibStatut($obj->statut_ligne, 2);
  241. print "&nbsp;";
  242. print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid_ligne.'">';
  243. print substr('000000'.$obj->rowid_ligne, -6);
  244. print '</a></td>';
  245. print '<td>';
  246. $link_to_bill = '/compta/facture/card.php?facid=';
  247. $link_title = 'Invoice';
  248. $link_picto = 'bill';
  249. if ($type == 'bank-transfer') {
  250. $link_to_bill = '/fourn/facture/card.php?facid=';
  251. $link_title = 'SupplierInvoice';
  252. $link_picto = 'supplier_invoice';
  253. }
  254. print '<a href="'.DOL_URL_ROOT.$link_to_bill.$obj->facid.'">';
  255. print img_object($langs->trans($link_title), $link_picto);
  256. print '&nbsp;'.$obj->invoiceref."</td>\n";
  257. print '</a>';
  258. print '</td>';
  259. print '<td>';
  260. print $company->getNomUrl(1);
  261. print "</td>\n";
  262. print '<td class="center">';
  263. $link_to_tab = '/comm/card.php?socid=';
  264. $link_code = $obj->code_client;
  265. if ($type == 'bank-transfer') {
  266. $link_to_tab = '/fourn/card.php?socid=';
  267. $link_code = $obj->code_fournisseur;
  268. }
  269. print '<a href="'.DOL_URL_ROOT.$link_to_tab.$company->id.'">'.$link_code."</a></td>\n";
  270. print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
  271. print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
  272. print '<td>&nbsp;</td>';
  273. print "</tr>\n";
  274. $i++;
  275. }
  276. } else {
  277. print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  278. }
  279. print "</table>";
  280. print '</div>';
  281. print '</form>';
  282. $db->free($result);
  283. } else {
  284. dol_print_error($db);
  285. }
  286. // End of page
  287. llxFooter();
  288. $db->close();