[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/compta/resultat/ -> clientfourn.php (source)

   1  <?php
   2  /* Copyright (C) 2002      Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-2005 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, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: clientfourn.php,v 1.25 2005/12/17 00:26:35 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/resultat/clientfourn.php,v $
  21   */
  22  
  23  /**
  24          \file        htdocs/compta/resultat/clientfourn.php
  25          \brief       Page reporting resultat
  26          \version     $Revision: 1.25 $
  27  */
  28  
  29  require ("./pre.inc.php");
  30  require_once ("../../tva.class.php");
  31  require_once ("../../chargesociales.class.php");
  32  
  33  $langs->load("bills");
  34  
  35  $user->getrights('compta');
  36  if (!$user->rights->compta->resultat->lire)
  37    accessforbidden();
  38  
  39  $year=$_GET["year"];
  40  if (! $year) { $year = strftime("%Y", time()); }
  41  $modecompta = $conf->compta->mode;
  42  if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
  43  
  44  
  45  
  46  llxHeader();
  47  
  48  $html=new Form($db);
  49  
  50  // Affiche en-tête de rapport
  51  if ($modecompta=="CREANCES-DETTES")
  52  {
  53      $nom="Bilan des recettes et dépenses, détail";
  54      $nom.=' (Voir le rapport en <a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">recettes-dépenses</a> pour n\'inclure que les factures effectivement payées)';
  55      $period=$langs->trans("Year")." ".$year;
  56      $periodlink='<a href='.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
  57      $description=$langs->trans("RulesResultDue");
  58      $builddate=time();
  59      $exportlink=$langs->trans("NotYetAvailable");
  60  }
  61  else {
  62      $nom="Bilan des recettes et dépenses, détail";
  63      $nom.=' (Voir le rapport en <a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">créances-dettes</a> pour inclure les factures non encore payée)';
  64      $period=$langs->trans("Year")." ".$year;
  65      $periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
  66      $description=$langs->trans("RulesResultInOut");
  67      $builddate=time();
  68      $exportlink=$langs->trans("NotYetAvailable");
  69  }
  70  $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  71  
  72  // Affiche rapport
  73  print '<table class="noborder" width="100%">';
  74  print '<tr class="liste_titre">';
  75  print '<td width="10%">&nbsp;</td><td>'.$langs->trans("Element").'</td>';
  76  if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".$langs->trans("AmountHT")."</td>";
  77  print "<td align=\"right\">".$langs->trans("AmountTTC")."</td>";
  78  print "</tr>\n";
  79  print '<tr><td colspan="4">&nbsp;</td></tr>';
  80  
  81  /*
  82   * Factures clients
  83   */
  84  print '<tr><td colspan="4">Facturation clients</td></tr>';
  85  
  86  if ($modecompta == 'CREANCES-DETTES') { 
  87      $sql = "SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc";
  88      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
  89      $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1";
  90      if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
  91  } else {
  92      /*
  93       * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
  94       * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin)
  95       */
  96      $sql = "SELECT s.nom as nom, s.idp as idp, sum(pf.amount) as amount_ttc";
  97      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  98      $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp";
  99      if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 100  }    
 101  $sql .= " GROUP BY nom";
 102  $sql .= " ORDER BY nom";
 103  
 104  $result = $db->query($sql);
 105  if ($result) {
 106      $num = $db->num_rows($result);
 107      $i = 0;
 108      $var=true;
 109      while ($i < $num)
 110      {
 111          $objp = $db->fetch_object($result);
 112          $var=!$var;
 113              
 114          print "<tr $bc[$var]><td>&nbsp</td>";
 115          print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socidp=$objp->idp\">$objp->nom</td>\n";
 116          
 117          if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n";
 118          print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n";
 119          
 120          $total_ht = $total_ht + $objp->amount_ht;
 121          $total_ttc = $total_ttc + $objp->amount_ttc;
 122          print "</tr>\n";
 123          $i++;
 124      }
 125      $db->free($result);
 126  } else {
 127      dolibarr_print_error($db);
 128  }
 129  
 130  // On ajoute les paiements clients anciennes version, non liés par paiement_facture
 131  if ($modecompta != 'CREANCES-DETTES') { 
 132      $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc";
 133      $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
 134      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
 135      $sql .= " WHERE pf.rowid IS NULL";
 136      if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 137      $sql .= " GROUP BY nom";
 138      $sql .= " ORDER BY nom";
 139  
 140      $result = $db->query($sql);
 141      if ($result) {
 142          $num = $db->num_rows($result);
 143          $i = 0;
 144          if ($num) {
 145              while ($i < $num)
 146              {
 147                  $objp = $db->fetch_object($result);
 148                  $var=!$var;
 149                      
 150                  print "<tr $bc[$var]><td>&nbsp</td>";
 151                  print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (anciens paiements liés à aucune facture)\n";
 152                  
 153                  if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n";
 154                  print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n";
 155                  
 156                  $total_ht = $total_ht + $objp->amount_ht;
 157                  $total_ttc = $total_ttc + $objp->amount_ttc;
 158                  print "</tr>\n";
 159                  $i++;
 160              }
 161          }
 162          $db->free($result);
 163      } else {
 164          dolibarr_print_error($db);
 165      }
 166  }
 167  
 168  if ($total_ttc == 0)
 169  {
 170      $var=!$var;
 171      print "<tr $bc[$var]><td>&nbsp</td>";
 172      print '<td colspan="3">'.$langs->trans("None").'</td>';
 173      print '</tr>';
 174  }
 175  
 176  print '<tr class="liste_total">';
 177  if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price($total_ht).'</td>';
 178  print '<td colspan="3" align="right">'.price($total_ttc).'</td>';
 179  print '</tr>';
 180  
 181  
 182  /*
 183   * Frais, factures fournisseurs.
 184   */
 185  if ($modecompta == 'CREANCES-DETTES') { 
 186      $sql = "SELECT s.nom, s.idp, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
 187      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f";
 188      $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1";
 189     if ($year) {
 190          $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 191      }
 192  } else {
 193      $sql = "SELECT s.nom, s.idp, sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
 194      $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
 195      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f";
 196      $sql .= " ON f.rowid = pf.fk_facturefourn";
 197      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
 198      $sql .= " ON f.fk_soc = s.idp";
 199      $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
 200      if ($year) {
 201          $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 202      }
 203  }
 204  $sql .= " GROUP BY nom, idp";
 205  $sql .= " ORDER BY nom, idp";
 206  
 207  print '<tr><td colspan="4">Facturation fournisseurs</td></tr>';
 208  $subtotal_ht = 0;
 209  $subtotal_ttc = 0;
 210  $result = $db->query($sql);
 211  if ($result) {
 212    $num = $db->num_rows($result);
 213    $i = 0;
 214    $var=true;
 215    if ($num > 0) {
 216      while ($i < $num) {
 217        $objp = $db->fetch_object($result);
 218        $var=!$var;
 219              
 220        print "<tr $bc[$var]><td>&nbsp</td>";
 221        print "<td>".$langs->trans("Bills")." <a href=\"../../fourn/facture/index.php?socid=".$objp->idp."\">$objp->nom</a></td>\n";
 222        
 223        if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price(-$objp->amount_ht)."</td>\n";
 224        print "<td align=\"right\">".price(-$objp->amount_ttc)."</td>\n";
 225        
 226        $total_ht = $total_ht - $objp->amount_ht;
 227        $total_ttc = $total_ttc - $objp->amount_ttc;
 228        $subtotal_ht = $subtotal_ht + $objp->amount_ht;
 229        $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc;
 230        print "</tr>\n";
 231        $i++;
 232      }
 233    }
 234    else {
 235      $var=!$var;
 236      print "<tr $bc[$var]><td>&nbsp</td>";
 237      print '<td colspan="3">'.$langs->trans("None").'</td>';
 238      print '</tr>';
 239    }
 240  
 241    $db->free($result);
 242  } else {
 243    dolibarr_print_error($db);
 244  }
 245  print '<tr class="liste_total">';
 246  if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
 247  print '<td colspan="3" align="right">'.price(-$subtotal_ttc).'</td>';
 248  print '</tr>';
 249  
 250  
 251  /*
 252   * TVA
 253   */
 254  print '<tr><td colspan="4">'.$langs->trans("VAT").'</td></tr>';
 255  $subtotal_ht = 0;
 256  $subtotal_ttc = 0;
 257  
 258  if ($modecompta == 'CREANCES-DETTES')
 259  {
 260      // TVA à payer
 261      $amount=0;
 262      $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; 
 263      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
 264      $sql .= " WHERE f.fk_statut = 1";
 265      if ($year) {
 266          $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 267      }
 268      $sql .= " GROUP BY dm";
 269      $sql .= " ORDER BY dm DESC";
 270      $result=$db->query($sql);
 271      if ($result) {
 272          $num = $db->num_rows($result);
 273          $var=false;
 274          $i = 0;
 275          if ($num) {    
 276            while ($i < $num) {
 277              $obj = $db->fetch_object($result);
 278          
 279              $amount = $amount - $obj->amount;
 280              $total_ht = $total_ht - $obj->amount;
 281              $total_ttc = $total_ttc - $obj->amount;
 282              $subtotal_ht = $subtotal_ht - $obj->amount;
 283              $subtotal_ttc = $subtotal_ttc - $obj->amount;
 284              $i++;
 285            }
 286          }
 287      } else {
 288          dolibarr_print_error($db);
 289      }
 290      print "<tr $bc[$var]><td>&nbsp</td>";
 291      print "<td>".$langs->trans("VATToPay")."</td>\n";
 292      if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
 293      print "<td align=\"right\">".price($amount)."</td>\n";
 294      print "</tr>\n";
 295  
 296      // TVA à récupérer
 297      $amount=0;
 298      $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; 
 299      $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
 300      $sql .= " WHERE f.fk_statut = 1";
 301      if ($year) {
 302          $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 303      }
 304      $sql .= " GROUP BY dm";
 305      $sql .= " ORDER BY dm DESC";
 306  
 307      $result=$db->query($sql);
 308      if ($result) {
 309          $num = $db->num_rows($result);
 310          $var=true;
 311          $i = 0;
 312          if ($num) {    
 313            while ($i < $num) {
 314              $obj = $db->fetch_object($result);
 315          
 316              $amount = $amount + $obj->amount;
 317              $total_ht = $total_ht + $obj->amount;
 318              $total_ttc = $total_ttc + $obj->amount;
 319              $subtotal_ht = $subtotal_ht + $obj->amount;
 320              $subtotal_ttc = $subtotal_ttc + $obj->amount;
 321          
 322              $i++;
 323            }
 324          }
 325      } else {
 326          dolibarr_print_error($db);
 327      }
 328      print "<tr $bc[$var]><td>&nbsp</td>";
 329      print "<td>".$langs->trans("VATToCollect")."</td>\n";
 330      if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
 331      print "<td align=\"right\">".price($amount)."</td>\n";
 332      print "</tr>\n";
 333  }
 334  else
 335  {
 336      // TVA réellement déjà payée
 337      $amount=0;
 338      $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; 
 339      $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
 340      $sql .= " WHERE amount > 0";
 341      if ($year) {
 342          $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 343      }
 344      $sql .= " GROUP BY dm";
 345      $sql .= " ORDER BY dm DESC";
 346      $result=$db->query($sql);
 347      if ($result) {
 348          $num = $db->num_rows($result);
 349          $var=false;
 350          $i = 0;
 351          if ($num) {    
 352            while ($i < $num) {
 353              $obj = $db->fetch_object($result);
 354          
 355              $amount = $amount - $obj->amount;
 356              $total_ht = $total_ht - $obj->amount;
 357              $total_ttc = $total_ttc - $obj->amount;
 358              $subtotal_ht = $subtotal_ht - $obj->amount;
 359              $subtotal_ttc = $subtotal_ttc - $obj->amount;
 360          
 361              $i++;
 362            }
 363          }
 364          $db->free($result);
 365      } else {
 366          dolibarr_print_error($db);
 367      }
 368      print "<tr $bc[$var]><td>&nbsp</td>";
 369      print "<td>".$langs->trans("VATPayed")."</td>\n";
 370      if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
 371      print "<td align=\"right\">".price($amount)."</td>\n";
 372      print "</tr>\n";
 373  
 374      // TVA récupérée
 375      $amount=0;
 376      $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; 
 377      $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
 378      $sql .= " WHERE amount < 0";
 379      if ($year) {
 380          $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 381      }
 382      $sql .= " GROUP BY dm";
 383      $sql .= " ORDER BY dm DESC";
 384      $result=$db->query($sql);
 385      if ($result) {
 386          $num = $db->num_rows($result);
 387          $var=true;
 388          $i = 0;
 389          if ($num) {    
 390            while ($i < $num) {
 391              $obj = $db->fetch_object($result);
 392          
 393              $amount = $amount + $obj->amount;
 394              $total_ht = $total_ht + $obj->amount;
 395              $total_ttc = $total_ttc + $obj->amount;
 396              $subtotal_ht = $subtotal_ht + $obj->amount;
 397              $subtotal_ttc = $subtotal_ttc + $obj->amount;
 398          
 399              $i++;
 400            }
 401          }
 402          $db->free($result);
 403      } else {
 404          dolibarr_print_error($db);
 405      }
 406      print "<tr $bc[$var]><td>&nbsp</td>";
 407      print "<td>".$langs->trans("VATCollected")."</td>\n";
 408      if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
 409      print "<td align=\"right\">".price($amount)."</td>\n";
 410      print "</tr>\n";
 411  }
 412  print '<tr class="liste_total">';
 413  if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price($subtotal_ht).'</td>';
 414  print '<td colspan="3" align="right">'.price($subtotal_ttc).'</td>';
 415  print '</tr>';
 416  
 417  
 418  /*
 419   * Charges sociales non déductibles
 420   */
 421  
 422  print '<tr><td colspan="4">Prestations/Charges NON déductibles</td></tr>';
 423  
 424  if ($modecompta == 'CREANCES-DETTES') {
 425      $sql = "SELECT c.libelle as nom, sum(s.amount) as amount";
 426      $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s";
 427      $sql .= " WHERE s.fk_type = c.id AND c.deductible=0";
 428      if ($year) {
 429          $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'";
 430      }
 431      $sql .= " GROUP BY c.libelle";
 432  }
 433  else {
 434      $sql = "SELECT c.libelle as nom, sum(p.amount) as amount";
 435      $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p";
 436      $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=0";
 437      if ($year) {
 438          $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'";
 439      }
 440      $sql .= " GROUP BY c.libelle";
 441  }
 442  $result=$db->query($sql);
 443  $subtotal_ht = 0;
 444  $subtotal_ttc = 0;
 445  if ($result) {
 446      $num = $db->num_rows($result);
 447      $var=true;
 448      $i = 0;
 449      if ($num) {    
 450        while ($i < $num) {
 451          $obj = $db->fetch_object($result);
 452      
 453          $total_ht = $total_ht - $obj->amount;
 454          $total_ttc = $total_ttc - $obj->amount;
 455          $subtotal_ht = $subtotal_ht + $obj->amount;
 456          $subtotal_ttc = $subtotal_ttc + $obj->amount;
 457      
 458          $var = !$var;
 459          print "<tr $bc[$var]><td>&nbsp</td>";
 460          print '<td>'.$obj->nom.'</td>';
 461          if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
 462          print '<td align="right">'.price(-$obj->amount).'</td>';
 463          print '</tr>';
 464          $i++;
 465        }
 466      }
 467      else {
 468          print "<tr $bc[$var]><td>&nbsp</td>";
 469          print '<td colspan="3">'.$langs->trans("None").'</td>';
 470          print '</tr>';
 471      }
 472  } else {
 473    dolibarr_print_error($db);
 474  }
 475  print '<tr class="liste_total">';
 476  if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
 477  print '<td colspan="3" align="right">'.price(-$subtotal_ttc).'</td>';
 478  print '</tr>';
 479  
 480  
 481  /*
 482   * Charges sociales déductibles
 483   */
 484  
 485  print '<tr><td colspan="4">Prestations/Charges déductibles</td></tr>';
 486  
 487  if ($modecompta == 'CREANCES-DETTES') {
 488      $sql = "SELECT c.libelle as nom, sum(s.amount) as amount";
 489      $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s";
 490      $sql .= " WHERE s.fk_type = c.id AND c.deductible=1";
 491      if ($year) {
 492          $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'";
 493      }
 494      $sql .= " GROUP BY c.libelle DESC";
 495  }
 496  else {
 497      $sql = "SELECT c.libelle as nom, sum(p.amount) as amount";
 498      $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p";
 499      $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=1";
 500      if ($year) {
 501          $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'";
 502      }
 503      $sql .= " GROUP BY c.libelle";
 504  }
 505  $result=$db->query($sql);
 506  $subtotal_ht = 0;
 507  $subtotal_ttc = 0;
 508  if ($result) {
 509      $num = $db->num_rows($result);
 510      $var=false;
 511      $i = 0;
 512      if ($num) {
 513          while ($i < $num) {
 514          $obj = $db->fetch_object($result);
 515          
 516          $total_ht = $total_ht - $obj->amount;
 517          $total_ttc = $total_ttc - $obj->amount;
 518          $subtotal_ht = $subtotal_ht + $obj->amount;
 519          $subtotal_ttc = $subtotal_ttc + $obj->amount;
 520          
 521          $var = !$var;
 522          print "<tr $bc[$var]><td>&nbsp</td>";
 523          print '<td>'.$obj->nom.'</td>';
 524          if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
 525          print '<td align="right">'.price(-$obj->amount).'</td>';
 526          print '</tr>';
 527          $i++;
 528          }
 529      }
 530      else {
 531          print "<tr $bc[$var]><td>&nbsp</td>";
 532          print '<td colspan="3">'.$langs->trans("None").'</td>';
 533          print '</tr>';
 534      }
 535  } else {
 536    dolibarr_print_error($db);
 537  }
 538  print '<tr class="liste_total">';
 539  if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
 540  print '<td colspan="3" align="right">'.price(-$subtotal_ttc).'</td>';
 541  print '</tr>';
 542  
 543  
 544  // Total
 545  
 546  print '<tr>';
 547  print '<td colspan="4">&nbsp;</td>';
 548  print '</tr>';
 549  
 550  print '<tr class="liste_total"><td align="left" colspan="2">'.$langs->trans("Profit").'</td>';
 551  if ($modecompta == 'CREANCES-DETTES') print '<td class="border" align="right">'.price($total_ht).'</td>';
 552  print '<td class="border" align="right">'.price($total_ttc).'</td>';
 553  print '</tr>';
 554  
 555  
 556  print "</table>";
 557  print '<br>';
 558  
 559  
 560  $db->close();
 561  
 562  llxFooter('$Date: 2005/12/17 00:26:35 $ - $Revision: 1.25 $');
 563  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics