demandes.php 9.9 KB

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