orders_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  32. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  33. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  34. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  35. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  36. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  37. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  38. $optioncss = GETPOST('optioncss', 'alpha');
  39. $mode = GETPOST('mode', 'alpha');
  40. $type = GETPOST('type', 'aZ09');
  41. // Load variable for pagination
  42. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  47. // If $page is not defined, or '' or -1 or if we click on clear filters
  48. $page = 0;
  49. }
  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. // Get supervariables
  60. $statut = GETPOST('statut', 'int');
  61. $search_ref = GETPOST('search_ref', 'alpha');
  62. $search_amount = GETPOST('search_amount', 'alpha');
  63. $bon = new BonPrelevement($db);
  64. $hookmanager->initHooks(array('withdrawalsreceiptslist'));
  65. $usercancreate = $user->rights->prelevement->bons->creer;
  66. if ($type == 'bank-transfer') {
  67. $usercancreate = $user->rights->paymentbybanktransfer->create;
  68. }
  69. // Security check
  70. $socid = GETPOST('socid', 'int');
  71. if ($user->socid) {
  72. $socid = $user->socid;
  73. }
  74. if ($type == 'bank-transfer') {
  75. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  76. } else {
  77. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  78. }
  79. /*
  80. * Actions
  81. */
  82. 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
  83. $search_ref = "";
  84. $search_amount = "";
  85. }
  86. /*
  87. * View
  88. */
  89. $directdebitorder = new BonPrelevement($db);
  90. $titlekey = "WithdrawalsReceipts";
  91. $title = $langs->trans("WithdrawalsReceipts");
  92. if ($type == 'bank-transfer') {
  93. $titlekey = "BankTransferReceipts";
  94. $title = $langs->trans("BankTransferReceipts");
  95. }
  96. $help_url = '';
  97. $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
  98. $sqlfields = $sql; // $sql fields to remove for count total
  99. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  100. $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
  101. if ($type == 'bank-transfer') {
  102. $sql .= " AND p.type = 'bank-transfer'";
  103. } else {
  104. $sql .= " AND p.type = 'debit-order'";
  105. }
  106. if ($search_ref) {
  107. $sql .= natural_search("p.ref", $search_ref);
  108. }
  109. if ($search_amount) {
  110. $sql .= natural_search("p.amount", $search_amount, 1);
  111. }
  112. // Count total nb of records
  113. $nbtotalofrecords = '';
  114. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  115. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  116. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  117. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  118. $resql = $db->query($sqlforcount);
  119. if ($resql) {
  120. $objforcount = $db->fetch_object($resql);
  121. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  122. } else {
  123. dol_print_error($db);
  124. }
  125. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  126. $page = 0;
  127. $offset = 0;
  128. }
  129. $db->free($resql);
  130. }
  131. // Complete request and execute it with limit
  132. $sql .= $db->order($sortfield, $sortorder);
  133. if ($limit) {
  134. $sql .= $db->plimit($limit + 1, $offset);
  135. }
  136. $resql = $db->query($sql);
  137. if (!$resql) {
  138. dol_print_error($db);
  139. exit;
  140. }
  141. $num = $db->num_rows($resql);
  142. // Output page
  143. // --------------------------------------------------------------------
  144. llxHeader('', $title, $help_url);
  145. $arrayofselected = is_array($toselect) ? $toselect : array();
  146. $param = '';
  147. $param .= "&statut=".urlencode($statut);
  148. if ($type == 'bank-transfer') {
  149. $param .= '&type=bank-transfer';
  150. }
  151. if (!empty($mode)) {
  152. $param .= '&mode='.urlencode($mode);
  153. }
  154. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  155. $param .= '&contextpage='.urlencode($contextpage);
  156. }
  157. if ($limit > 0 && $limit != $conf->liste_limit) {
  158. $param .= '&limit='.((int) $limit);
  159. }
  160. if ($optioncss != '') {
  161. $param .= '&optioncss='.urlencode($optioncss);
  162. }
  163. $arrayofmassactions = array(
  164. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  165. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  166. );
  167. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  168. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  169. print '<input type="hidden" name="token" value="'.newToken().'">';
  170. if ($optioncss != '') {
  171. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  172. }
  173. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  174. print '<input type="hidden" name="action" value="list">';
  175. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  176. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  177. print '<input type="hidden" name="page" value="'.$page.'">';
  178. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  179. print '<input type="hidden" name="page_y" value="">';
  180. print '<input type="hidden" name="mode" value="'.$mode.'">';
  181. if ($type != '') {
  182. print '<input type="hidden" name="type" value="'.$type.'">';
  183. }
  184. $newcardbutton = '';
  185. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  186. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  187. if ($usercancreate) {
  188. $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
  189. }
  190. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
  191. $moreforfilter = '';
  192. /*$moreforfilter.='<div class="divsearchfield">';
  193. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  194. $moreforfilter.= '</div>';*/
  195. $parameters = array();
  196. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  197. if (empty($reshook)) {
  198. $moreforfilter .= $hookmanager->resPrint;
  199. } else {
  200. $moreforfilter = $hookmanager->resPrint;
  201. }
  202. if (!empty($moreforfilter)) {
  203. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  204. print $moreforfilter;
  205. $parameters = array();
  206. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  207. print $hookmanager->resPrint;
  208. print '</div>';
  209. }
  210. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  211. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  212. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  213. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  214. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  215. // Fields title search
  216. // --------------------------------------------------------------------
  217. print '<tr class="liste_titre_filter">';
  218. // Action column
  219. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  220. print '<td class="liste_titre center maxwidthsearch">';
  221. $searchpicto = $form->showFilterButtons('left');
  222. print $searchpicto;
  223. print '</td>';
  224. }
  225. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  226. print '<td class="liste_titre">&nbsp;</td>';
  227. print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  228. print '<td class="liste_titre">&nbsp;</td>';
  229. // Action column
  230. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  231. print '<td class="liste_titre center maxwidthsearch">';
  232. $searchpicto = $form->showFilterButtons();
  233. print $searchpicto;
  234. print '</td>';
  235. }
  236. print '</tr>'."\n";
  237. $totalarray = array();
  238. $totalarray['nbfield'] = 0;
  239. // Fields title label
  240. // --------------------------------------------------------------------
  241. print '<tr class="liste_titre">';
  242. // Action column
  243. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  244. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  245. $totalarray['nbfield']++;
  246. }
  247. print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  248. $totalarray['nbfield']++;
  249. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
  250. $totalarray['nbfield']++;
  251. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
  252. $totalarray['nbfield']++;
  253. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  254. $totalarray['nbfield']++;
  255. // Action column
  256. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  257. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  258. $totalarray['nbfield']++;
  259. }
  260. print '</tr>'."\n";
  261. // Loop on record
  262. // --------------------------------------------------------------------
  263. $i = 0;
  264. $savnbfield = $totalarray['nbfield'];
  265. $totalarray = array();
  266. $totalarray['nbfield'] = 0;
  267. $imaxinloop = ($limit ? min($num, $limit) : $num);
  268. while ($i < $imaxinloop) {
  269. $obj = $db->fetch_object($resql);
  270. $directdebitorder->id = $obj->rowid;
  271. $directdebitorder->ref = $obj->ref;
  272. $directdebitorder->date_echeance = $obj->datec;
  273. $directdebitorder->total = $obj->amount;
  274. $directdebitorder->statut = $obj->statut;
  275. $object = $directdebitorder;
  276. if ($mode == 'kanban') {
  277. if ($i == 0) {
  278. print '<tr><td colspan="'.$savnbfield.'">';
  279. print '<div class="box-flex-container kanban">';
  280. }
  281. // Output Kanban
  282. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  283. $selected = 0;
  284. if (in_array($object->id, $arrayofselected)) {
  285. $selected = 1;
  286. }
  287. }
  288. print $directdebitorder->getKanbanView('', array('selected' => in_array($obj->id, $arrayofselected)));
  289. if ($i == ($imaxinloop - 1)) {
  290. print '</div>';
  291. print '</td></tr>';
  292. }
  293. } else {
  294. // Show line of result
  295. $j = 0;
  296. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  297. // Action column
  298. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  299. print '<td class="nowrap center">';
  300. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  301. $selected = 0;
  302. if (in_array($object->id, $arrayofselected)) {
  303. $selected = 1;
  304. }
  305. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  306. }
  307. print '</td>';
  308. if (!$i) {
  309. $totalarray['nbfield']++;
  310. }
  311. }
  312. print '<td>';
  313. print $directdebitorder->getNomUrl(1);
  314. print "</td>\n";
  315. print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
  316. print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
  317. print '<td class="right">';
  318. print $bon->LibStatut($obj->statut, 5);
  319. print '</td>';
  320. // Action column
  321. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  322. print '<td class="nowrap center">';
  323. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  324. $selected = 0;
  325. if (in_array($object->id, $arrayofselected)) {
  326. $selected = 1;
  327. }
  328. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  329. }
  330. print '</td>';
  331. if (!$i) {
  332. $totalarray['nbfield']++;
  333. }
  334. }
  335. print '</tr>'."\n";
  336. }
  337. $i++;
  338. }
  339. if ($num == 0) {
  340. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  341. }
  342. $db->free($result);
  343. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  344. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  345. print $hookmanager->resPrint;
  346. print '</table>'."\n";
  347. print '</div>'."\n";
  348. print '</form>'."\n";
  349. // End of page
  350. llxFooter();
  351. $db->close();