orders_list.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/prelevement/orders_list.php
  22. * \ingroup prelevement
  23. * \brief Page to list direct debit orders or credit transfer orders
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
  31. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  32. $type = GETPOST('type', 'aZ09');
  33. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  34. $sortfield = GETPOST('sortfield', 'aZ09comma');
  35. $sortorder = GETPOST('sortorder', 'aZ09comma');
  36. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  37. if (empty($page) || $page == -1) {
  38. $page = 0;
  39. } // If $page is not defined, or '' or -1
  40. $offset = $limit * $page;
  41. $pageprev = $page - 1;
  42. $pagenext = $page + 1;
  43. if (!$sortorder) {
  44. $sortorder = "DESC";
  45. }
  46. if (!$sortfield) {
  47. $sortfield = "p.datec";
  48. }
  49. $optioncss = GETPOST('optioncss', 'alpha');
  50. // Get supervariables
  51. $statut = GETPOST('statut', 'int');
  52. $search_ref = GETPOST('search_ref', 'alpha');
  53. $search_amount = GETPOST('search_amount', 'alpha');
  54. $bon = new BonPrelevement($db);
  55. $hookmanager->initHooks(array('withdrawalsreceiptslist'));
  56. $usercancreate = $user->rights->prelevement->bons->creer;
  57. if ($type == 'bank-transfer') {
  58. $usercancreate = $user->rights->paymentbybanktransfer->create;
  59. }
  60. // Security check
  61. $socid = GETPOST('socid', 'int');
  62. if ($user->socid) {
  63. $socid = $user->socid;
  64. }
  65. if ($type == 'bank-transfer') {
  66. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  67. } else {
  68. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  69. }
  70. /*
  71. * Actions
  72. */
  73. 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
  74. $search_ref = "";
  75. $search_amount = "";
  76. }
  77. /*
  78. * View
  79. */
  80. llxHeader('', $langs->trans("WithdrawalsReceipts"));
  81. $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
  82. $sqlfields = $sql; // $sql fields to remove for count total
  83. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  84. $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
  85. if ($type == 'bank-transfer') {
  86. $sql .= " AND p.type = 'bank-transfer'";
  87. } else {
  88. $sql .= " AND p.type = 'debit-order'";
  89. }
  90. if ($search_ref) {
  91. $sql .= natural_search("p.ref", $search_ref);
  92. }
  93. if ($search_amount) {
  94. $sql .= natural_search("p.amount", $search_amount, 1);
  95. }
  96. // Count total nb of records
  97. $nbtotalofrecords = '';
  98. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  99. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  100. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  101. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  102. $resql = $db->query($sqlforcount);
  103. if ($resql) {
  104. $objforcount = $db->fetch_object($resql);
  105. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  106. } else {
  107. dol_print_error($db);
  108. }
  109. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  110. $page = 0;
  111. $offset = 0;
  112. }
  113. $db->free($resql);
  114. }
  115. // Complete request and execute it with limit
  116. $sql .= $db->order($sortfield, $sortorder);
  117. if ($limit) {
  118. $sql .= $db->plimit($limit + 1, $offset);
  119. }
  120. $result = $db->query($sql);
  121. if ($result) {
  122. $num = $db->num_rows($result);
  123. $i = 0;
  124. $param = '';
  125. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  126. $param .= '&contextpage='.urlencode($contextpage);
  127. }
  128. if ($type == 'bank-transfer') {
  129. $param .= '&amp;type=bank-transfer';
  130. }
  131. if ($limit > 0 && $limit != $conf->liste_limit) {
  132. $param .= '&limit='.urlencode($limit);
  133. }
  134. $param .= "&statut=".urlencode($statut);
  135. $selectedfields = '';
  136. $newcardbutton = '';
  137. if ($usercancreate) {
  138. $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
  139. }
  140. // Lines of title fields
  141. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  142. print '<input type="hidden" name="token" value="'.newToken().'">';
  143. if ($optioncss != '') {
  144. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  145. }
  146. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  147. print '<input type="hidden" name="action" value="list">';
  148. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  149. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  150. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  151. if ($type != '') {
  152. print '<input type="hidden" name="type" value="'.$type.'">';
  153. }
  154. $titlekey = "WithdrawalsReceipts";
  155. $title = $langs->trans("WithdrawalsReceipts");
  156. if ($type == 'bank-transfer') {
  157. $titlekey = "BankTransferReceipts";
  158. $title = $langs->trans("BankTransferReceipts");
  159. }
  160. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
  161. $moreforfilter = '';
  162. print '<div class="div-table-responsive">';
  163. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  164. print '<tr class="liste_titre">';
  165. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  166. print '<td class="liste_titre">&nbsp;</td>';
  167. print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  168. print '<td class="liste_titre">&nbsp;</td>';
  169. print '<td class="liste_titre maxwidthsearch">';
  170. $searchpicto = $form->showFilterButtons();
  171. print $searchpicto;
  172. print '</td>';
  173. print '</tr>';
  174. print '<tr class="liste_titre">';
  175. print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  176. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
  177. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
  178. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  179. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
  180. print "</tr>\n";
  181. $directdebitorder = new BonPrelevement($db);
  182. if ($num) {
  183. while ($i < min($num, $limit)) {
  184. $obj = $db->fetch_object($result);
  185. $directdebitorder->id = $obj->rowid;
  186. $directdebitorder->ref = $obj->ref;
  187. $directdebitorder->datec = $obj->datec;
  188. $directdebitorder->amount = $obj->amount;
  189. $directdebitorder->statut = $obj->statut;
  190. print '<tr class="oddeven">';
  191. print '<td>';
  192. print $directdebitorder->getNomUrl(1);
  193. print "</td>\n";
  194. print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
  195. print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
  196. print '<td class="right">';
  197. print $bon->LibStatut($obj->statut, 5);
  198. print '</td>';
  199. print '<td class="right"></td>'."\n";
  200. print "</tr>\n";
  201. $i++;
  202. }
  203. } else {
  204. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  205. }
  206. print "</table>";
  207. print '</div>';
  208. print '</form>';
  209. $db->free($result);
  210. } else {
  211. dol_print_error($db);
  212. }
  213. // End of page
  214. llxFooter();
  215. $db->close();