index.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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@capnetworks.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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/prelevement/index.php
  23. * \ingroup prelevement
  24. * \brief Prelevement index page
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.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'));
  34. // Security check
  35. $socid = GETPOST('socid','int');
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'prelevement','','');
  38. /*
  39. * Actions
  40. */
  41. /*
  42. * View
  43. */
  44. llxHeader('',$langs->trans("CustomersStandingOrdersArea"));
  45. if (prelevement_check_config() < 0)
  46. {
  47. $langs->load("errors");
  48. setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
  49. }
  50. print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"));
  51. print '<div class="fichecenter"><div class="fichethirdleft">';
  52. $thirdpartystatic=new Societe($db);
  53. $invoicestatic=new Facture($db);
  54. $bprev = new BonPrelevement($db);
  55. print '<table class="noborder" width="100%">';
  56. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  57. print '<tr class="oddeven"><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
  58. print '<td align="right">';
  59. print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/demandes.php?status=0">';
  60. print $bprev->NbFactureAPrelever();
  61. print '</a>';
  62. print '</td></tr>';
  63. print '<tr class="oddeven"><td>'.$langs->trans("AmountToWithdraw").'</td>';
  64. print '<td align="right">';
  65. print price($bprev->SommeAPrelever(),'','',1,-1,-1,'auto');
  66. print '</td></tr></table><br>';
  67. /*
  68. * Invoices waiting for withdraw
  69. */
  70. $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
  71. $sql.= " pfd.date_demande, pfd.amount,";
  72. $sql.= " s.nom as name, s.rowid as socid";
  73. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
  74. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  75. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  76. $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  77. $sql.= " WHERE s.rowid = f.fk_soc";
  78. $sql.= " AND f.entity = ".$conf->entity;
  79. $sql.= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
  80. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  81. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  82. $resql=$db->query($sql);
  83. if ($resql)
  84. {
  85. $num = $db->num_rows($resql);
  86. $i = 0;
  87. print '<table class="noborder" width="100%">';
  88. print '<tr class="liste_titre">';
  89. print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
  90. if ($num)
  91. {
  92. while ($i < $num && $i < 20)
  93. {
  94. $obj = $db->fetch_object($resql);
  95. $invoicestatic->id=$obj->rowid;
  96. $invoicestatic->ref=$obj->facnumber;
  97. $invoicestatic->statut=$obj->fk_statut;
  98. $invoicestatic->paye=$obj->paye;
  99. $invoicestatic->type=$obj->type;
  100. $alreadypayed=$invoicestatic->getSommePaiement();
  101. print '<tr class="oddeven"><td>';
  102. print $invoicestatic->getNomUrl(1,'withdraw');
  103. print '</td>';
  104. print '<td>';
  105. $thirdpartystatic->id=$obj->socid;
  106. $thirdpartystatic->name=$obj->name;
  107. print $thirdpartystatic->getNomUrl(1,'customer');
  108. print '</td>';
  109. print '<td align="right">';
  110. print price($obj->amount);
  111. print '</td>';
  112. print '<td align="right">';
  113. print dol_print_date($db->jdate($obj->date_demande),'day');
  114. print '</td>';
  115. print '<td align="right">';
  116. print $invoicestatic->getLibStatut(3,$alreadypayed);
  117. print '</td>';
  118. print '</tr>';
  119. $i++;
  120. }
  121. }
  122. else
  123. {
  124. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders")).'</td></tr>';
  125. }
  126. print "</table><br>";
  127. }
  128. else
  129. {
  130. dol_print_error($db);
  131. }
  132. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  133. /*
  134. * Withdraw receipts
  135. */
  136. $limit=5;
  137. $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut";
  138. $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  139. $sql.= " ORDER BY datec DESC";
  140. $sql.= $db->plimit($limit);
  141. $result = $db->query($sql);
  142. if ($result)
  143. {
  144. $num = $db->num_rows($result);
  145. $i = 0;
  146. print"\n<!-- debut table -->\n";
  147. print '<table class="noborder" width="100%">';
  148. print '<tr class="liste_titre"><th>'.$langs->trans("LastWithdrawalReceipt",$limit).'</th>';
  149. print '<th>'.$langs->trans("Date").'</th>';
  150. print '<th align="right">'.$langs->trans("Amount").'</th>';
  151. print '<th align="right">'.$langs->trans("Status").'</th>';
  152. print '</tr>';
  153. while ($i < min($num,$limit))
  154. {
  155. $obj = $db->fetch_object($result);
  156. print '<tr class="oddeven">';
  157. print "<td>";
  158. $bprev->id=$obj->rowid;
  159. $bprev->ref=$obj->ref;
  160. $bprev->statut=$obj->statut;
  161. print $bprev->getNomUrl(1);
  162. print "</td>\n";
  163. print '<td>'.dol_print_date($db->jdate($obj->datec),"dayhour")."</td>\n";
  164. print '<td align="right">'.price($obj->amount)."</td>\n";
  165. print '<td align="right">'.$bprev->getLibStatut(3)."</td>\n";
  166. print "</tr>\n";
  167. $i++;
  168. }
  169. print "</table><br>";
  170. $db->free($result);
  171. }
  172. else
  173. {
  174. dol_print_error($db);
  175. }
  176. print '</div></div></div>';
  177. llxFooter();
  178. $db->close();