recap-fourn.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <http://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. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array('bills', 'companies'));
  29. // Security check
  30. $socid = GETPOST("socid",'int');
  31. if ($user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  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. {
  46. $societe = new Societe($db);
  47. $societe->fetch($socid);
  48. /*
  49. * Affichage onglets
  50. */
  51. $head = societe_prepare_head($societe);
  52. dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), 0, 'company');
  53. dol_banner_tab($societe, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
  54. dol_fiche_end();
  55. if (! empty($conf->fournisseur->enabled) && $user->rights->facture->lire)
  56. {
  57. // Invoice list
  58. print load_fiche_titre($langs->trans("SupplierPreview"));
  59. print '<table class="noborder tagtable liste" width="100%">';
  60. $sql = "SELECT s.nom, s.rowid as socid, f.ref_supplier, f.amount, f.datef as df,";
  61. $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
  62. $sql.= " u.login, u.rowid as userid";
  63. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."user as u";
  64. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
  65. $sql.= " AND f.entity IN (".getEntity("facture_fourn").")"; // Reconaissance de l'entité attribuée à cette facture pour Multicompany
  66. $sql.= " AND f.fk_user_valid = u.rowid";
  67. $sql.= " ORDER BY f.datef DESC";
  68. $resql=$db->query($sql);
  69. if ($resql)
  70. {
  71. $num = $db->num_rows($resql);
  72. print '<tr class="liste_titre">';
  73. print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
  74. print '<td>&nbsp;</td>';
  75. print '<td>'.$langs->trans("Status").'</td>';
  76. print '<td align="right">'.$langs->trans("Debit").'</td>';
  77. print '<td align="right">'.$langs->trans("Credit").'</td>';
  78. print '<td align="right">'.$langs->trans("Balance").'</td>';
  79. print '<td>&nbsp;</td>';
  80. print '</tr>';
  81. if (! $num > 0)
  82. {
  83. print '<tr><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
  84. }
  85. $solde = 0;
  86. // Boucle sur chaque facture
  87. for ($i = 0 ; $i < $num ; $i++)
  88. {
  89. $objf = $db->fetch_object($resql);
  90. $fac = new FactureFournisseur($db);
  91. $ret=$fac->fetch($objf->facid);
  92. if ($ret < 0)
  93. {
  94. print $fac->error."<br>";
  95. continue;
  96. }
  97. $totalpaye = $fac->getSommePaiement();
  98. print '<tr class="oddeven">';
  99. print "<td align=\"center\">".dol_print_date($fac->date)."</td>\n";
  100. print "<td><a href=\"facture/card.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."</a></td>\n";
  101. print '<td aling="left">'.$fac->getLibStatut(2,$totalpaye).'</td>';
  102. print '<td align="right">'.price($fac->total_ttc)."</td>\n";
  103. $solde = $solde + $fac->total_ttc;
  104. print '<td align="right">&nbsp;</td>';
  105. print '<td align="right">'.price($solde)."</td>\n";
  106. // Author
  107. 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>';
  108. print "</tr>\n";
  109. // Payments
  110. $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
  111. $sql.= " p.fk_user_author, u.login, u.rowid as userid";
  112. $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf,";
  113. $sql.= " ".MAIN_DB_PREFIX."paiementfourn as p";
  114. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_author = u.rowid";
  115. $sql.= " WHERE pf.fk_paiementfourn = p.rowid";
  116. $sql.= " AND pf.fk_facturefourn = ".$fac->id;
  117. $resqlp = $db->query($sql);
  118. if ($resqlp)
  119. {
  120. $nump = $db->num_rows($resqlp);
  121. $j = 0;
  122. while ($j < $nump)
  123. {
  124. $objp = $db->fetch_object($resqlp);
  125. //
  126. print '<tr class="oddeven">';
  127. print '<td align="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
  128. print '<td>';
  129. print '&nbsp; &nbsp; &nbsp; '; // Decalage
  130. print '<a href="paiement/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
  131. print "<td>&nbsp;</td>\n";
  132. print "<td>&nbsp;</td>\n";
  133. print '<td align="right">'.price($objp->amount).'</td>';
  134. $solde = $solde - $objp->amount;
  135. print '<td align="right">'.price($solde)."</td>\n";
  136. // Auteur
  137. 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>';
  138. print '</tr>';
  139. $j++;
  140. }
  141. $db->free($resqlp);
  142. }
  143. else
  144. {
  145. dol_print_error($db);
  146. }
  147. }
  148. }
  149. else
  150. {
  151. dol_print_error($db);
  152. }
  153. print "</table>";
  154. }
  155. }
  156. else
  157. {
  158. dol_print_error($db);
  159. }
  160. // End of page
  161. llxFooter();
  162. $db->close();