index.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/prelevement/index.php
  23. * \ingroup prelevement
  24. * \brief Home page for direct debit orders
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
  35. // Security check
  36. $socid = GETPOST('socid', 'int');
  37. if ($user->socid) {
  38. $socid = $user->socid;
  39. }
  40. $result = restrictedArea($user, 'prelevement', '', 'bons');
  41. $usercancreate = $user->rights->prelevement->bons->creer;
  42. /*
  43. * Actions
  44. */
  45. // None
  46. /*
  47. * View
  48. */
  49. llxHeader('', $langs->trans("CustomersStandingOrdersArea"));
  50. if (prelevement_check_config() < 0) {
  51. $langs->load("errors");
  52. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByDirectDebit")), null, 'errors');
  53. }
  54. $newcardbutton = '';
  55. if ($usercancreate) {
  56. $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=');
  57. }
  58. print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"), $newcardbutton);
  59. print '<div class="fichecenter"><div class="fichethirdleft">';
  60. $thirdpartystatic = new Societe($db);
  61. $invoicestatic = new Facture($db);
  62. $bprev = new BonPrelevement($db);
  63. print '<div class="div-table-responsive-no-min">';
  64. print '<table class="noborder centpercent">';
  65. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  66. print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
  67. print '<td class="right">';
  68. print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
  69. print $bprev->nbOfInvoiceToPay('direct-debit');
  70. print '</a>';
  71. print '</td></tr>';
  72. print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
  73. print '<td class="right"><span class="amount">';
  74. print price($bprev->SommeAPrelever('direct-debit'), '', '', 1, -1, -1, 'auto');
  75. print '</span></td></tr></table></div><br>';
  76. /*
  77. * Invoices waiting for withdraw
  78. */
  79. $sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
  80. $sql .= " pfd.date_demande, pfd.amount,";
  81. $sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
  82. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
  83. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  84. if (empty($user->rights->societe->client->voir) && !$socid) {
  85. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  86. }
  87. $sql .= " , ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  88. $sql .= " WHERE s.rowid = f.fk_soc";
  89. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  90. $sql .= " AND f.total_ttc > 0";
  91. if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
  92. $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
  93. }
  94. $sql .= " AND pfd.traite = 0";
  95. $sql .= " AND pfd.ext_payment_id IS NULL";
  96. $sql .= " AND pfd.fk_facture = f.rowid";
  97. if (empty($user->rights->societe->client->voir) && !$socid) {
  98. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  99. }
  100. if ($socid) {
  101. $sql .= " AND f.fk_soc = ".((int) $socid);
  102. }
  103. $resql = $db->query($sql);
  104. if ($resql) {
  105. $num = $db->num_rows($resql);
  106. $i = 0;
  107. print '<div class="div-table-responsive-no-min">';
  108. print '<table class="noborder centpercent">';
  109. print '<tr class="liste_titre">';
  110. print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
  111. if ($num) {
  112. while ($i < $num && $i < 20) {
  113. $obj = $db->fetch_object($resql);
  114. $invoicestatic->id = $obj->rowid;
  115. $invoicestatic->ref = $obj->ref;
  116. $invoicestatic->statut = $obj->fk_statut;
  117. $invoicestatic->paye = $obj->paye;
  118. $invoicestatic->type = $obj->type;
  119. $alreadypayed = $invoicestatic->getSommePaiement();
  120. $thirdpartystatic->id = $obj->socid;
  121. $thirdpartystatic->name = $obj->name;
  122. $thirdpartystatic->email = $obj->email;
  123. $thirdpartystatic->tva_intra = $obj->tva_intra;
  124. $thirdpartystatic->siren = $obj->idprof1;
  125. $thirdpartystatic->siret = $obj->idprof2;
  126. $thirdpartystatic->ape = $obj->idprof3;
  127. $thirdpartystatic->idprof1 = $obj->idprof1;
  128. $thirdpartystatic->idprof2 = $obj->idprof2;
  129. $thirdpartystatic->idprof3 = $obj->idprof3;
  130. $thirdpartystatic->idprof4 = $obj->idprof4;
  131. $thirdpartystatic->idprof5 = $obj->idprof5;
  132. $thirdpartystatic->idprof6 = $obj->idprof6;
  133. print '<tr class="oddeven"><td class="nowraponall">';
  134. print $invoicestatic->getNomUrl(1, 'withdraw');
  135. print '</td>';
  136. print '<td class="tdoverflowmax150">';
  137. print $thirdpartystatic->getNomUrl(1, 'customer');
  138. print '</td>';
  139. print '<td class="right">';
  140. print '<span class="amount">'.price($obj->amount).'</span>';
  141. print '</td>';
  142. print '<td class="right">';
  143. print dol_print_date($db->jdate($obj->date_demande), 'day');
  144. print '</td>';
  145. print '<td class="right">';
  146. print $invoicestatic->getLibStatut(3, $alreadypayed);
  147. print '</td>';
  148. print '</tr>';
  149. $i++;
  150. }
  151. } else {
  152. $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
  153. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
  154. }
  155. print "</table></div><br>";
  156. } else {
  157. dol_print_error($db);
  158. }
  159. print '</div><div class="fichetwothirdright">';
  160. /*
  161. * Direct debit orders
  162. */
  163. $limit = 5;
  164. $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
  165. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  166. $sql .= " WHERE p.type = 'debit-order'";
  167. $sql .= " AND entity IN (".getEntity('prelevement').")";
  168. $sql .= " ORDER BY datec DESC";
  169. $sql .= $db->plimit($limit);
  170. $result = $db->query($sql);
  171. if ($result) {
  172. $num = $db->num_rows($result);
  173. $i = 0;
  174. print"\n<!-- debut table -->\n";
  175. print '<div class="div-table-responsive-no-min">';
  176. print '<table class="noborder centpercent">';
  177. print '<tr class="liste_titre">';
  178. print '<th>'.$langs->trans("LastWithdrawalReceipt", $limit).'</th>';
  179. print '<th>'.$langs->trans("Date").'</th>';
  180. print '<th class="right">'.$langs->trans("Amount").'</th>';
  181. print '<th class="right">'.$langs->trans("Status").'</th>';
  182. print '</tr>';
  183. if ($num > 0) {
  184. while ($i < min($num, $limit)) {
  185. $obj = $db->fetch_object($result);
  186. $bprev->id = $obj->rowid;
  187. $bprev->ref = $obj->ref;
  188. $bprev->statut = $obj->statut;
  189. print '<tr class="oddeven">';
  190. print '<td class="nowraponall">';
  191. print $bprev->getNomUrl(1);
  192. print "</td>\n";
  193. print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
  194. print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
  195. print '<td class="right">'.$bprev->getLibStatut(3)."</td>\n";
  196. print "</tr>\n";
  197. $i++;
  198. }
  199. } else {
  200. print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  201. }
  202. print "</table></div><br>";
  203. $db->free($result);
  204. } else {
  205. dol_print_error($db);
  206. }
  207. print '</div></div>';
  208. // End of page
  209. llxFooter();
  210. $db->close();