orders_list.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. $permissiontodelete = $user->hasRight('prelevement', 'creer');
  67. if ($type == 'bank-transfer') {
  68. $usercancreate = $user->rights->paymentbybanktransfer->create;
  69. $permissiontodelete = $user->hasRight('paymentbybanktransfer', 'create');
  70. }
  71. // Security check
  72. $socid = GETPOST('socid', 'int');
  73. if ($user->socid) {
  74. $socid = $user->socid;
  75. }
  76. if ($type == 'bank-transfer') {
  77. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  78. } else {
  79. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  80. }
  81. /*
  82. * Actions
  83. */
  84. 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
  85. $search_ref = "";
  86. $search_amount = "";
  87. }
  88. // Mass actions
  89. // Delete draft
  90. if (($massaction == "delete" || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
  91. $db->begin();
  92. $objecttmp = new BonPrelevement($db);
  93. foreach ($toselect as $toselectid) {
  94. $result = $objecttmp->fetch($toselectid);
  95. if ($result > 0) {
  96. if ($objecttmp->status != $objecttmp::STATUS_DRAFT || $objecttmp->credite > 0 || $objecttmp->date_creation != null) {
  97. $langs->load("errors");
  98. $nbignored++;
  99. $TMsg[] = '<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'</div><br>';
  100. continue;
  101. }
  102. $result = $objecttmp->delete($user);
  103. if ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later
  104. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  105. $error++;
  106. break;
  107. } else {
  108. $nbok++;
  109. }
  110. } else {
  111. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  112. $error++;
  113. break;
  114. }
  115. }
  116. if (empty($error)) {
  117. // Message for elements well deleted
  118. if ($nbok > 1) {
  119. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  120. } elseif ($nbok > 0) {
  121. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  122. } else {
  123. setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
  124. }
  125. // Message for elements which can't be deleted
  126. if (!empty($TMsg)) {
  127. sort($TMsg);
  128. setEventMessages('', array_unique($TMsg), 'warnings');
  129. }
  130. $db->commit();
  131. } else {
  132. $db->rollback();
  133. }
  134. $massaction = '';
  135. }
  136. $objectclass = 'BonPrelevement';
  137. $objectlabel = 'BonPrelevement';
  138. $uploaddir = $conf->prelevement->dir_output;
  139. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  140. /*
  141. * View
  142. */
  143. $directdebitorder = new BonPrelevement($db);
  144. $titlekey = "WithdrawalsReceipts";
  145. $title = $langs->trans("WithdrawalsReceipts");
  146. if ($type == 'bank-transfer') {
  147. $titlekey = "BankTransferReceipts";
  148. $title = $langs->trans("BankTransferReceipts");
  149. }
  150. $help_url = '';
  151. $sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
  152. $sqlfields = $sql; // $sql fields to remove for count total
  153. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  154. $sql .= " WHERE p.entity IN (".getEntity('invoice').")";
  155. if ($type == 'bank-transfer') {
  156. $sql .= " AND p.type = 'bank-transfer'";
  157. } else {
  158. $sql .= " AND p.type = 'debit-order'";
  159. }
  160. if ($search_ref) {
  161. $sql .= natural_search("p.ref", $search_ref);
  162. }
  163. if ($search_amount) {
  164. $sql .= natural_search("p.amount", $search_amount, 1);
  165. }
  166. // Count total nb of records
  167. $nbtotalofrecords = '';
  168. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  169. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  170. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  171. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  172. $resql = $db->query($sqlforcount);
  173. if ($resql) {
  174. $objforcount = $db->fetch_object($resql);
  175. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  176. } else {
  177. dol_print_error($db);
  178. }
  179. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  180. $page = 0;
  181. $offset = 0;
  182. }
  183. $db->free($resql);
  184. }
  185. // Complete request and execute it with limit
  186. $sql .= $db->order($sortfield, $sortorder);
  187. if ($limit) {
  188. $sql .= $db->plimit($limit + 1, $offset);
  189. }
  190. $resql = $db->query($sql);
  191. if (!$resql) {
  192. dol_print_error($db);
  193. exit;
  194. }
  195. $num = $db->num_rows($resql);
  196. // Output page
  197. // --------------------------------------------------------------------
  198. llxHeader('', $title, $help_url);
  199. $arrayofselected = is_array($toselect) ? $toselect : array();
  200. $param = '';
  201. $param .= "&statut=".urlencode($statut);
  202. if ($type == 'bank-transfer') {
  203. $param .= '&type=bank-transfer';
  204. }
  205. if (!empty($mode)) {
  206. $param .= '&mode='.urlencode($mode);
  207. }
  208. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  209. $param .= '&contextpage='.urlencode($contextpage);
  210. }
  211. if ($limit > 0 && $limit != $conf->liste_limit) {
  212. $param .= '&limit='.((int) $limit);
  213. }
  214. if ($optioncss != '') {
  215. $param .= '&optioncss='.urlencode($optioncss);
  216. }
  217. $arrayofmassactions = array(
  218. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  219. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  220. );
  221. if (!empty($permissiontodelete)) {
  222. $arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  223. }
  224. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  225. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  226. print '<input type="hidden" name="token" value="'.newToken().'">';
  227. if ($optioncss != '') {
  228. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  229. }
  230. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  231. print '<input type="hidden" name="action" value="list">';
  232. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  233. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  234. print '<input type="hidden" name="page" value="'.$page.'">';
  235. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  236. print '<input type="hidden" name="page_y" value="">';
  237. print '<input type="hidden" name="mode" value="'.$mode.'">';
  238. if ($type != '') {
  239. print '<input type="hidden" name="type" value="'.$type.'">';
  240. }
  241. $newcardbutton = '';
  242. $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'));
  243. $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'));
  244. if ($usercancreate) {
  245. $newcardbutton .= dolGetButtonTitleSeparator();
  246. $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
  247. }
  248. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
  249. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  250. $moreforfilter = '';
  251. /*$moreforfilter.='<div class="divsearchfield">';
  252. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  253. $moreforfilter.= '</div>';*/
  254. $parameters = array();
  255. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  256. if (empty($reshook)) {
  257. $moreforfilter .= $hookmanager->resPrint;
  258. } else {
  259. $moreforfilter = $hookmanager->resPrint;
  260. }
  261. if (!empty($moreforfilter)) {
  262. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  263. print $moreforfilter;
  264. $parameters = array();
  265. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  266. print $hookmanager->resPrint;
  267. print '</div>';
  268. }
  269. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  270. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  271. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  272. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  273. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  274. // Fields title search
  275. // --------------------------------------------------------------------
  276. print '<tr class="liste_titre_filter">';
  277. // Action column
  278. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  279. print '<td class="liste_titre center maxwidthsearch">';
  280. $searchpicto = $form->showFilterButtons('left');
  281. print $searchpicto;
  282. print '</td>';
  283. }
  284. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  285. print '<td class="liste_titre">&nbsp;</td>';
  286. print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  287. print '<td class="liste_titre">&nbsp;</td>';
  288. // Action column
  289. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  290. print '<td class="liste_titre center maxwidthsearch">';
  291. $searchpicto = $form->showFilterButtons();
  292. print $searchpicto;
  293. print '</td>';
  294. }
  295. print '</tr>'."\n";
  296. $totalarray = array();
  297. $totalarray['nbfield'] = 0;
  298. // Fields title label
  299. // --------------------------------------------------------------------
  300. print '<tr class="liste_titre">';
  301. // Action column
  302. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  303. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  304. $totalarray['nbfield']++;
  305. }
  306. print_liste_field_titre($titlekey, $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  307. $totalarray['nbfield']++;
  308. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center ');
  309. $totalarray['nbfield']++;
  310. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "p.amount", "", $param, '', $sortfield, $sortorder, 'right ');
  311. $totalarray['nbfield']++;
  312. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
  313. $totalarray['nbfield']++;
  314. // Action column
  315. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  316. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  317. $totalarray['nbfield']++;
  318. }
  319. print '</tr>'."\n";
  320. // Loop on record
  321. // --------------------------------------------------------------------
  322. $i = 0;
  323. $savnbfield = $totalarray['nbfield'];
  324. $totalarray = array();
  325. $totalarray['nbfield'] = 0;
  326. $imaxinloop = ($limit ? min($num, $limit) : $num);
  327. while ($i < $imaxinloop) {
  328. $obj = $db->fetch_object($resql);
  329. $directdebitorder->id = $obj->rowid;
  330. $directdebitorder->ref = $obj->ref;
  331. $directdebitorder->date_echeance = $obj->datec;
  332. $directdebitorder->total = $obj->amount;
  333. $directdebitorder->statut = $obj->statut;
  334. $object = $directdebitorder;
  335. if ($mode == 'kanban') {
  336. if ($i == 0) {
  337. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  338. print '<div class="box-flex-container kanban">';
  339. }
  340. // Output Kanban
  341. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  342. $selected = 0;
  343. if (in_array($object->id, $arrayofselected)) {
  344. $selected = 1;
  345. }
  346. }
  347. print $directdebitorder->getKanbanView('', array('selected' => in_array($obj->id, $arrayofselected)));
  348. if ($i == ($imaxinloop - 1)) {
  349. print '</div>';
  350. print '</td></tr>';
  351. }
  352. } else {
  353. // Show line of result
  354. $j = 0;
  355. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  356. // Action column
  357. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  358. print '<td class="nowrap center">';
  359. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  360. $selected = 0;
  361. if (in_array($object->id, $arrayofselected)) {
  362. $selected = 1;
  363. }
  364. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  365. }
  366. print '</td>';
  367. if (!$i) {
  368. $totalarray['nbfield']++;
  369. }
  370. }
  371. print '<td>';
  372. print $directdebitorder->getNomUrl(1);
  373. print "</td>\n";
  374. print '<td class="center">'.dol_print_date($db->jdate($obj->datec), 'day')."</td>\n";
  375. print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
  376. print '<td class="right">';
  377. print $bon->LibStatut($obj->statut, 5);
  378. print '</td>';
  379. // Action column
  380. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  381. print '<td class="nowrap center">';
  382. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  383. $selected = 0;
  384. if (in_array($object->id, $arrayofselected)) {
  385. $selected = 1;
  386. }
  387. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  388. }
  389. print '</td>';
  390. if (!$i) {
  391. $totalarray['nbfield']++;
  392. }
  393. }
  394. print '</tr>'."\n";
  395. }
  396. $i++;
  397. }
  398. if ($num == 0) {
  399. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  400. }
  401. $db->free($result);
  402. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  403. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  404. print $hookmanager->resPrint;
  405. print '</table>'."\n";
  406. print '</div>'."\n";
  407. print '</form>'."\n";
  408. // End of page
  409. llxFooter();
  410. $db->close();