recap-fourn.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2019 Pierre Ardoin <mapiolca@me.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fourn/recap-fourn.php
  21. * \ingroup fournisseur
  22. * \brief Page de fiche recap supplier
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array('bills', 'companies'));
  30. // Security check
  31. $socid = GETPOST("socid", 'int');
  32. if ($user->socid > 0) {
  33. $action = '';
  34. $socid = $user->socid;
  35. }
  36. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  37. $hookmanager->initHooks(array('supplierbalencelist', 'globalcard'));
  38. /*
  39. * View
  40. */
  41. $form = new Form($db);
  42. $userstatic = new User($db);
  43. llxHeader();
  44. if ($socid > 0) {
  45. $societe = new Societe($db);
  46. $societe->fetch($socid);
  47. /*
  48. * Affichage onglets
  49. */
  50. $head = societe_prepare_head($societe);
  51. print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
  52. dol_banner_tab($societe, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  53. print dol_get_fiche_end();
  54. if ((isModEnabled("fournisseur") && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_invoice") && $user->rights->supplier_invoice->lire)) {
  55. // Invoice list
  56. print load_fiche_titre($langs->trans("SupplierPreview"));
  57. print '<table class="noborder tagtable liste centpercent">';
  58. $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.datef as df,";
  59. $sql .= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
  60. $sql .= " u.login, u.rowid as userid";
  61. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
  62. $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $societe->id);
  63. $sql .= " AND f.entity IN (".getEntity("facture_fourn").")"; // Recognition of the entity attributed to this invoice for Multicompany
  64. $sql .= " AND f.fk_user_valid = u.rowid";
  65. $sql .= " ORDER BY f.datef DESC";
  66. $resql = $db->query($sql);
  67. if ($resql) {
  68. $num = $db->num_rows($resql);
  69. print '<tr class="liste_titre">';
  70. print '<td width="100" class="center">'.$langs->trans("Date").'</td>';
  71. print '<td>&nbsp;</td>';
  72. print '<td>'.$langs->trans("Status").'</td>';
  73. print '<td class="right">'.$langs->trans("Debit").'</td>';
  74. print '<td class="right">'.$langs->trans("Credit").'</td>';
  75. print '<td class="right">'.$langs->trans("Balance").'</td>';
  76. print '<td>&nbsp;</td>';
  77. print '</tr>';
  78. if ($num <= 0) {
  79. print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
  80. }
  81. $solde = 0;
  82. // Boucle sur chaque facture
  83. for ($i = 0; $i < $num; $i++) {
  84. $objf = $db->fetch_object($resql);
  85. $fac = new FactureFournisseur($db);
  86. $ret = $fac->fetch($objf->facid);
  87. if ($ret < 0) {
  88. print $fac->error."<br>";
  89. continue;
  90. }
  91. $totalpaid = $fac->getSommePaiement();
  92. print '<tr class="oddeven">';
  93. print '<td class="center">'.dol_print_date($fac->date)."</td>\n";
  94. print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"), "bill")." ".$fac->ref."</a></td>\n";
  95. print '<td class="left">'.$fac->getLibStatut(2, $totalpaid).'</td>';
  96. print '<td class="right">'.price($fac->total_ttc)."</td>\n";
  97. $solde = $solde + $fac->total_ttc;
  98. print '<td class="right">&nbsp;</td>';
  99. print '<td class="right">'.price($solde)."</td>\n";
  100. // Author
  101. print '<td class="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objf->userid.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$objf->login.'</a></td>';
  102. print "</tr>\n";
  103. // Payments
  104. $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
  105. $sql .= " p.fk_user_author, u.login, u.rowid as userid";
  106. $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
  107. $sql .= " ".MAIN_DB_PREFIX."paiementfourn as p";
  108. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
  109. $sql .= " WHERE pf.fk_paiementfourn = p.rowid";
  110. $sql .= " AND pf.fk_facturefourn = ".((int) $fac->id);
  111. $resqlp = $db->query($sql);
  112. if ($resqlp) {
  113. $nump = $db->num_rows($resqlp);
  114. $j = 0;
  115. while ($j < $nump) {
  116. $objp = $db->fetch_object($resqlp);
  117. //
  118. print '<tr class="oddeven">';
  119. print '<td class="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
  120. print '<td>';
  121. print '&nbsp; &nbsp; &nbsp; '; // Decalage
  122. print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"), "payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
  123. print "<td>&nbsp;</td>\n";
  124. print "<td>&nbsp;</td>\n";
  125. print '<td class="right">'.price($objp->amount).'</td>';
  126. $solde = $solde - $objp->amount;
  127. print '<td class="right">'.price($solde)."</td>\n";
  128. // Auteur
  129. print '<td class="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objp->userid.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$objp->login.'</a></td>';
  130. print '</tr>';
  131. $j++;
  132. }
  133. $db->free($resqlp);
  134. } else {
  135. dol_print_error($db);
  136. }
  137. }
  138. } else {
  139. dol_print_error($db);
  140. }
  141. print "</table>";
  142. }
  143. } else {
  144. dol_print_error($db);
  145. }
  146. // End of page
  147. llxFooter();
  148. $db->close();