PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/recap-compta.php

https://github.com/asterix14/dolibarr
PHP | 216 lines | 136 code | 44 blank | 36 comment | 12 complexity | 0dac5a70e5adaacb3a92d053c4a7c797 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/recap-compta.php
  20. * \ingroup compta
  21. * \brief Page de fiche recap compta
  22. */
  23. require('../main.inc.php');
  24. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  26. $langs->load("companies");
  27. if ($conf->facture->enabled) $langs->load("bills");
  28. // Security check
  29. $socid = $_GET["socid"];
  30. if ($user->societe_id > 0)
  31. {
  32. $action = '';
  33. $socid = $user->societe_id;
  34. }
  35. /*
  36. * View
  37. */
  38. llxHeader();
  39. if ($socid > 0)
  40. {
  41. $societe = new Societe($db);
  42. $societe->fetch($socid);
  43. /*
  44. * Affichage onglets
  45. */
  46. $head = societe_prepare_head($societe);
  47. dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company');
  48. print "<table width=\"100%\">\n";
  49. print '<tr><td valign="top" width="50%">';
  50. print '<table class="border" width="100%">';
  51. // Nom
  52. print '<tr><td width="20%">'.$langs->trans("Name").'</td><td width="80%" colspan="3">'.$societe->nom.'</td></tr>';
  53. // Prefix
  54. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  55. {
  56. print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
  57. print ($societe->prefix_comm?$societe->prefix_comm:'&nbsp;');
  58. print '</td></tr>';
  59. }
  60. print "</table>";
  61. print "</td></tr></table>\n";
  62. print '</div>';
  63. if ($conf->facture->enabled && $user->rights->facture->lire)
  64. {
  65. // Factures
  66. print_fiche_titre($langs->trans("CustomerPreview"));
  67. print '<table class="noborder" width="100%">';
  68. $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, f.datef as df,";
  69. $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
  70. $sql.= " u.login, u.rowid as userid";
  71. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u";
  72. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
  73. $sql.= " AND f.fk_user_valid = u.rowid";
  74. $sql.= " ORDER BY f.datef DESC";
  75. $resql=$db->query($sql);
  76. if ($resql)
  77. {
  78. $var=true;
  79. $num = $db->num_rows($resql);
  80. print '<tr class="liste_titre">';
  81. print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
  82. print '<td>&nbsp;</td>';
  83. print '<td>'.$langs->trans("Status").'</td>';
  84. print '<td align="right">'.$langs->trans("Debit").'</td>';
  85. print '<td align="right">'.$langs->trans("Credit").'</td>';
  86. print '<td align="right">'.$langs->trans("Balance").'</td>';
  87. print '<td>&nbsp;</td>';
  88. print '</tr>';
  89. if (! $num > 0)
  90. {
  91. print '<tr><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
  92. }
  93. $solde = 0;
  94. // Boucle sur chaque facture
  95. for ($i = 0 ; $i < $num ; $i++)
  96. {
  97. $objf = $db->fetch_object($resql);
  98. $fac = new Facture($db);
  99. $ret=$fac->fetch($objf->facid);
  100. if ($ret < 0)
  101. {
  102. print $fac->error."<br>";
  103. continue;
  104. }
  105. $totalpaye = $fac->getSommePaiement();
  106. $var=!$var;
  107. print "<tr $bc[$var]>";
  108. print "<td align=\"center\">".dol_print_date($fac->date)."</td>\n";
  109. print "<td><a href=\"../compta/facture.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."</a></td>\n";
  110. print '<td aling="left">'.$fac->getLibStatut(2,$totalpaye).'</td>';
  111. print '<td align="right">'.price($fac->total_ttc)."</td>\n";
  112. $solde = $solde + $fac->total_ttc;
  113. print '<td align="right">&nbsp;</td>';
  114. print '<td align="right">'.price($solde)."</td>\n";
  115. // Auteur
  116. print '<td nowrap="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$objf->userid.'">'.img_object($langs->trans("ShowUser"),'user').' '.$objf->login.'</a></td>';
  117. print "</tr>\n";
  118. // Paiements
  119. $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
  120. $sql.= " p.fk_user_creat, u.login, u.rowid as userid";
  121. $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf,";
  122. $sql.= " ".MAIN_DB_PREFIX."paiement as p";
  123. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_creat = u.rowid";
  124. $sql.= " WHERE pf.fk_paiement = p.rowid";
  125. $sql.= " AND pf.fk_facture = ".$fac->id;
  126. $resqlp = $db->query($sql);
  127. if ($resqlp)
  128. {
  129. $nump = $db->num_rows($resqlp);
  130. $j = 0;
  131. while ($j < $nump)
  132. {
  133. $objp = $db->fetch_object($resqlp);
  134. //$var=!$var;
  135. print "<tr $bc[$var]>";
  136. print '<td align="center">'.dol_print_date($db->jdate($objp->dp))."</td>\n";
  137. print '<td>';
  138. print '&nbsp; &nbsp; &nbsp; '; // Decalage
  139. print '<a href="paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
  140. print "<td>&nbsp;</td>\n";
  141. print "<td>&nbsp;</td>\n";
  142. print '<td align="right">'.price($objp->amount).'</td>';
  143. $solde = $solde - $objp->amount;
  144. print '<td align="right">'.price($solde)."</td>\n";
  145. // Auteur
  146. print '<td nowrap="nowrap" width="50"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$objp->userid.'">'.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'</a></td>';
  147. print '</tr>';
  148. $j++;
  149. }
  150. $db->free($resqlp);
  151. }
  152. else
  153. {
  154. dol_print_error($db);
  155. }
  156. }
  157. }
  158. else
  159. {
  160. dol_print_error($db);
  161. }
  162. print "</table>";
  163. print "<br>";
  164. }
  165. }
  166. else
  167. {
  168. dol_print_error($db);
  169. }
  170. $db->close();
  171. llxFooter();
  172. ?>