demandes.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-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/demandes.php
  22. * \ingroup prelevement
  23. * \brief Page to list bank transfer requests (debit order or payments of vendors)
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/modPrelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
  34. // Security check
  35. $socid = GETPOST('socid', 'int');
  36. $status = GETPOST('status', 'int');
  37. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  38. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  39. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  40. $type = GETPOST('type', 'aZ09');
  41. $search_facture = GETPOST('search_facture', 'alpha');
  42. $search_societe = GETPOST('search_societe', 'alpha');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "DESC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "f.ref";
  59. }
  60. $massactionbutton = '';
  61. $hookmanager->initHooks(array('withdrawalstodolist'));
  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. $parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
  74. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  75. if ($reshook < 0) {
  76. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. }
  78. // Purge search criteria
  79. 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
  80. $search_facture = '';
  81. $search_societe = '';
  82. $search_array_options = array();
  83. }
  84. /*
  85. * View
  86. */
  87. if ($type != 'bank-transfer') {
  88. if (!$status) {
  89. $title = $langs->trans("RequestStandingOrderToTreat");
  90. } else {
  91. $title = $langs->trans("RequestStandingOrderTreated");
  92. }
  93. } else {
  94. if (!$status) {
  95. $title = $langs->trans("RequestPaymentsByBankTransferToTreat");
  96. } else {
  97. $title = $langs->trans("RequestPaymentsByBankTransferTreated");
  98. }
  99. }
  100. llxHeader('', $title);
  101. $thirdpartystatic = new Societe($db);
  102. if ($type == 'bank-transfer') {
  103. $invoicestatic = new FactureFournisseur($db);
  104. } else {
  105. $invoicestatic = new Facture($db);
  106. }
  107. // List of requests
  108. $sql = "SELECT f.ref, f.rowid, f.total_ttc,";
  109. $sql .= " s.nom as name, s.rowid as socid,";
  110. $sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande";
  111. if ($type != 'bank-transfer') {
  112. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
  113. } else {
  114. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
  115. }
  116. $sql .= " ".MAIN_DB_PREFIX."societe as s,";
  117. $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  118. if (empty($user->rights->societe->client->voir) && !$socid) {
  119. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  120. }
  121. $sql .= " WHERE s.rowid = f.fk_soc";
  122. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  123. if (empty($user->rights->societe->client->voir) && !$socid) {
  124. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  125. }
  126. if ($socid) {
  127. $sql .= " AND f.fk_soc = ".((int) $socid);
  128. }
  129. if (!$status) {
  130. $sql .= " AND pfd.traite = 0";
  131. }
  132. $sql .= " AND pfd.ext_payment_id IS NULL";
  133. if ($status) {
  134. $sql .= " AND pfd.traite = ".((int) $status);
  135. }
  136. $sql .= " AND f.total_ttc > 0";
  137. if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
  138. $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
  139. }
  140. if ($type != 'bank-transfer') {
  141. $sql .= " AND pfd.fk_facture = f.rowid";
  142. } else {
  143. $sql .= " AND pfd.fk_facture_fourn = f.rowid";
  144. }
  145. if ($search_facture) {
  146. $sql .= natural_search("f.ref", $search_facture);
  147. }
  148. if ($search_societe) {
  149. $sql .= natural_search("s.nom", $search_societe);
  150. }
  151. $sql .= $db->order($sortfield, $sortorder);
  152. // Count total nb of records
  153. $nbtotalofrecords = '';
  154. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  155. $resql = $db->query($sql);
  156. $nbtotalofrecords = $db->num_rows($resql);
  157. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  158. $page = 0;
  159. $offset = 0;
  160. }
  161. }
  162. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  163. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  164. $num = $nbtotalofrecords;
  165. } else {
  166. $sql .= $db->plimit($limit + 1, $offset);
  167. $resql = $db->query($sql);
  168. if (!$resql) {
  169. dol_print_error($db);
  170. exit;
  171. }
  172. $num = $db->num_rows($resql);
  173. }
  174. $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/prelevement/index.php">'.$langs->trans("Back").'</a>';
  175. if ($type == 'bank-transfer') {
  176. $newcardbutton = '<a class="marginrightonly" href="'.DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php">'.$langs->trans("Back").'</a>';
  177. }
  178. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
  179. if ($optioncss != '') {
  180. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  181. }
  182. print '<input type="hidden" name="token" value="'.newToken().'">';
  183. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  184. print '<input type="hidden" name="action" value="list">';
  185. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  186. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  187. print '<input type="hidden" name="page" value="'.$page.'">';
  188. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  189. $param = '';
  190. $label = 'NewStandingOrder';
  191. $typefilter = '';
  192. if ($type == 'bank-transfer') {
  193. $label = 'NewPaymentByBankTransfer';
  194. $typefilter = 'type='.$type;
  195. }
  196. $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php'.($typefilter ? '?'.$typefilter : ''));
  197. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
  198. print '<table class="liste centpercent">';
  199. print '<tr class="liste_titre">';
  200. print_liste_field_titre("Bill", $_SERVER["PHP_SELF"]);
  201. print_liste_field_titre("Company", $_SERVER["PHP_SELF"]);
  202. print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
  203. print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
  204. print_liste_field_titre('');
  205. print '</tr>';
  206. print '<tr class="liste_titre">';
  207. print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
  208. print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  209. print '<td class="liste_titre"></td>';
  210. print '<td class="liste_titre"></td>';
  211. // Action column
  212. print '<td class="liste_titre maxwidthsearch">';
  213. $searchpicto = $form->showFilterButtons();
  214. print $searchpicto;
  215. print '</td>';
  216. print '</tr>';
  217. $i = 0;
  218. while ($i < min($num, $limit)) {
  219. $obj = $db->fetch_object($resql);
  220. if (empty($obj)) {
  221. break; // Should not happen
  222. }
  223. $invoicestatic->fetch($obj->rowid);
  224. print '<tr class="oddeven">';
  225. // Ref facture
  226. print '<td>';
  227. print $invoicestatic->getNomUrl(1, 'withdraw');
  228. print '</td>';
  229. print '<td>';
  230. $thirdpartystatic->id = $obj->socid;
  231. $thirdpartystatic->name = $obj->name;
  232. print $thirdpartystatic->getNomUrl(1, 'customer');
  233. print '</td>';
  234. print '<td class="right">';
  235. print '<span class="amount">';
  236. print price($obj->amount, 1, $langs, 1, -1, -1, $conf->currency).' / '.price($obj->total_ttc, 1, $langs, 1, -1, -1, $conf->currency);
  237. print '</span>';
  238. print '</td>';
  239. print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
  240. print '<td class="right"></td>';
  241. print '</tr>';
  242. $i++;
  243. }
  244. print "</table><br>";
  245. print '</form>';
  246. // End of page
  247. llxFooter();
  248. $db->close();