index.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2020 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/paymentbybanktransfer/index.php
  23. * \ingroup paymentbybanktransfer
  24. * \brief Payment by bank transfer index page
  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.'/fourn/class/fournisseur.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, 'paymentbybanktransfer', '', '');
  41. $usercancreate = $user->rights->paymentbybanktransfer->create;
  42. /*
  43. * Actions
  44. */
  45. // None
  46. /*
  47. * View
  48. */
  49. llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
  50. if (prelevement_check_config('bank-transfer') < 0) {
  51. $langs->load("errors");
  52. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors');
  53. }
  54. $newcardbutton = '';
  55. if ($usercancreate) {
  56. $newcardbutton .= dolGetButtonTitle($langs->trans('NewPaymentByBankTransfer'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer');
  57. }
  58. print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton);
  59. print '<div class="fichecenter"><div class="fichethirdleft">';
  60. $thirdpartystatic = new Societe($db);
  61. $invoicestatic = new FactureFournisseur($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("NbOfInvoiceToPayByBankTransfer").'</td>';
  67. print '<td class="right">';
  68. print '<a class="badge badge-info" href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0&type=bank-transfer">';
  69. print $bprev->nbOfInvoiceToPay('bank-transfer');
  70. print '</a>';
  71. print '</td></tr>';
  72. print '<tr class="oddeven"><td>'.$langs->trans("AmountToTransfer").'</td>';
  73. print '<td class="right"><span class="amount">';
  74. print price($bprev->SommeAPrelever('bank-transfer'), '', '', 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, f.datef, f.date_lim_reglement,";
  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_fourn 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('supplier_invoice').")";
  90. $sql .= " AND f.total_ttc > 0";
  91. if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
  92. $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
  93. }
  94. $sql .= " AND pfd.traite = 0";
  95. $sql .= " AND pfd.ext_payment_id IS NULL";
  96. $sql .= " AND pfd.fk_facture_fourn = 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("SupplierInvoiceWaitingWithdraw").' <span class="opacitymedium">('.$num.')</span></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->status = $obj->fk_statut;
  117. $invoicestatic->statut = $obj->fk_statut; // For backward comaptibility
  118. $invoicestatic->paye = $obj->paye;
  119. $invoicestatic->type = $obj->type;
  120. $invoicestatic->date = $db->jdate($obj->datef);
  121. $invoicestatic->date_echeance = $db->jdate($obj->date_lim_reglement);
  122. $invoicestatic->total_ttc = $obj->total_ttc;
  123. $alreadypayed = $invoicestatic->getSommePaiement();
  124. $thirdpartystatic->id = $obj->socid;
  125. $thirdpartystatic->name = $obj->name;
  126. $thirdpartystatic->email = $obj->email;
  127. $thirdpartystatic->tva_intra = $obj->tva_intra;
  128. $thirdpartystatic->siren = $obj->idprof1;
  129. $thirdpartystatic->siret = $obj->idprof2;
  130. $thirdpartystatic->ape = $obj->idprof3;
  131. $thirdpartystatic->idprof1 = $obj->idprof1;
  132. $thirdpartystatic->idprof2 = $obj->idprof2;
  133. $thirdpartystatic->idprof3 = $obj->idprof3;
  134. $thirdpartystatic->idprof4 = $obj->idprof4;
  135. $thirdpartystatic->idprof5 = $obj->idprof5;
  136. $thirdpartystatic->idprof6 = $obj->idprof6;
  137. print '<tr class="oddeven"><td class="nowraponall">';
  138. print $invoicestatic->getNomUrl(1, 'withdraw');
  139. print '</td>';
  140. print '<td class="tdoverflowmax150">';
  141. print $thirdpartystatic->getNomUrl(1, 'supplier');
  142. print '</td>';
  143. print '<td class="right">';
  144. print '<span class="amount">'.price($obj->amount).'</span>';
  145. print '</td>';
  146. print '<td class="right">';
  147. print dol_print_date($db->jdate($obj->date_demande), 'day');
  148. print '</td>';
  149. print '<td class="right">';
  150. print $invoicestatic->getLibStatut(3, $alreadypayed);
  151. print '</td>';
  152. print '</tr>';
  153. $i++;
  154. }
  155. } else {
  156. $titlefortab = $langs->transnoentitiesnoconv("BankTransfer");
  157. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("NoSupplierInvoiceToWithdraw", $titlefortab, $titlefortab).'</span></td></tr>';
  158. }
  159. print "</table></div><br>";
  160. } else {
  161. dol_print_error($db);
  162. }
  163. print '</div><div class="fichetwothirdright">';
  164. /*
  165. * Withdraw receipts
  166. */
  167. $limit = 5;
  168. $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
  169. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  170. $sql .= " WHERE p.type = 'bank-transfer'";
  171. $sql .= " AND p.entity IN (".getEntity('invoice').")";
  172. $sql .= " ORDER BY datec DESC";
  173. $sql .= $db->plimit($limit);
  174. $result = $db->query($sql);
  175. if ($result) {
  176. $num = $db->num_rows($result);
  177. $i = 0;
  178. print"\n<!-- debut table -->\n";
  179. print '<div class="div-table-responsive-no-min">';
  180. print '<table class="noborder centpercent">';
  181. print '<tr class="liste_titre">';
  182. print '<th>'.$langs->trans("LatestBankTransferReceipts", $limit).'</th>';
  183. print '<th>'.$langs->trans("Date").'</th>';
  184. print '<th class="right">'.$langs->trans("Amount").'</th>';
  185. print '<th class="right">'.$langs->trans("Status").'</th>';
  186. print '</tr>';
  187. if ($num > 0) {
  188. while ($i < min($num, $limit)) {
  189. $obj = $db->fetch_object($result);
  190. print '<tr class="oddeven">';
  191. print '<td class="nowraponall">';
  192. $bprev->id = $obj->rowid;
  193. $bprev->ref = $obj->ref;
  194. $bprev->statut = $obj->statut;
  195. print $bprev->getNomUrl(1);
  196. print "</td>\n";
  197. print '<td>'.dol_print_date($db->jdate($obj->datec), "dayhour")."</td>\n";
  198. print '<td class="right nowraponall"><span class="amount">'.price($obj->amount)."</span></td>\n";
  199. print '<td class="right"><span class="amount">'.$bprev->getLibStatut(3)."</span></td>\n";
  200. print "</tr>\n";
  201. $i++;
  202. }
  203. } else {
  204. print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  205. }
  206. print "</table></div><br>";
  207. $db->free($result);
  208. } else {
  209. dol_print_error($db);
  210. }
  211. print '</div></div>';
  212. // End of page
  213. llxFooter();
  214. $db->close();