[ 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/tva/ -> index.php (source)

   1  <?php
   2  /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004      Éric Seigne          <eric.seigne@ryxeo.com>
   4   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   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 2 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, write to the Free Software
  18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19   *
  20   * $Id: index.php,v 1.20 2005/08/16 07:39:35 rodolphe Exp $
  21   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/tva/index.php,v $
  22   *
  23   */
  24  
  25  /**
  26          \file       htdocs/compta/tva/index.php
  27          \ingroup    compta
  28          \brief      Page des societes
  29          \version    $Revision: 1.20 $
  30  */
  31  
  32  require ("./pre.inc.php");
  33  require ("../../tva.class.php");
  34  
  35  $modecompta = $conf->compta->mode;
  36  
  37  
  38  /*
  39   * On récupère la tva à collecter
  40   */
  41  function tva_coll($db, $y,$m)
  42  {
  43      if ($modecompta=="CREANCES-DETTES")
  44      {
  45          // Si on paye la tva sur les factures dues (non brouillon)
  46          $sql = "SELECT sum(f.tva) as amount";
  47          $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  48          $sql.= " WHERE ";
  49          $sql.= " f.fk_statut = 1";
  50          $sql.= " AND date_format(f.datef,'%Y') = $y";
  51          $sql.= " AND date_format(f.datef,'%m') = $m";
  52      }
  53      else
  54      {
  55          // Si on paye la tva sur les payments
  56      
  57          // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
  58          // n'est pas stocké dans la table des payments.
  59          // Il faut quand un payment a lieu, stocker en plus du montant du paiement le
  60          // detail part tva et part ht.
  61          
  62          // En attendant, on renvoi tva sur factures payés
  63          $sql = "SELECT sum(f.tva) as amount";
  64          $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  65          $sql.= " WHERE ";
  66          $sql.= " f.paye = 1";
  67          $sql.= " AND date_format(f.datef,'%Y') = $y";
  68          $sql.= " AND date_format(f.datef,'%m') = $m";
  69      }
  70  
  71      $resql = $db->query($sql);
  72      if ($resql)
  73      {
  74          $obj = $db->fetch_object($resql);
  75          return $obj->amount;
  76      }
  77      else
  78      {
  79          dolibarr_print_error($db);
  80      }
  81  }
  82  
  83  
  84  /*
  85   * On récupère la tva à payer
  86   */
  87  function tva_paye($db, $y,$m)
  88  {
  89      if ($modecompta=="CREANCES-DETTES")
  90      {
  91          // Si on paye la tva sur les factures dues (non brouillon)
  92          $sql = "SELECT sum(f.total_tva) as amount";
  93          $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  94          $sql.= " WHERE ";
  95          $sql.= " f.fk_statut = 1";
  96          $sql.= " AND date_format(f.datef,'%Y') = $y";
  97          $sql.= " AND date_format(f.datef,'%m') = $m";
  98      }
  99      else
 100      {
 101          // Si on paye la tva sur les payments
 102      
 103          // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
 104          // n'est pas stocké dans la table des payments.
 105          // Il faut quand un payment a lieu, stocker en plus du montant du paiement le
 106          // detail part tva et part ht.
 107          
 108          // En attendant, on renvoi tva sur factures payés
 109          $sql = "SELECT sum(f.total_tva) as amount";
 110          $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
 111    //      $sql.= " WHERE ";
 112      $sql .= " WHERE f.fk_statut = 1";
 113  //        $sql.= " f.paye = 1";
 114          $sql.= " AND date_format(f.datef,'%Y') = $y";
 115          $sql.= " AND date_format(f.datef,'%m') = $m";
 116      //print "xx $sql";
 117      }
 118  
 119      $resql = $db->query($sql);
 120      if ($resql)
 121      {
 122          $obj = $db->fetch_object($resql);
 123          return $obj->amount;
 124      }
 125      else
 126      {
 127          dolibarr_print_error($db);
 128      }
 129  }
 130  
 131  
 132  function pt ($db, $sql, $date) {
 133      global $bc,$langs;
 134  
 135      $result = $db->query($sql);
 136      if ($result) {
 137          $num = $db->num_rows($result);
 138          $i = 0;
 139          $total = 0;
 140          print "<table class=\"noborder\" width=\"100%\">";
 141          print "<tr class=\"liste_titre\">";
 142          print "<td nowrap width=\"60%\">$date</td>";
 143          print "<td align=\"right\">".$langs->trans("Amount")."</td>";
 144          print "<td>&nbsp;</td>\n";
 145          print "</tr>\n";
 146          $var=True;
 147          while ($i < $num) {
 148              $obj = $db->fetch_object($result);
 149              $var=!$var;
 150              print "<tr $bc[$var]>";
 151              print "<td nowrap>$obj->dm</td>\n";
 152              $total = $total + $obj->amount;
 153  
 154              print "<td nowrap align=\"right\">".price($obj->amount)."</td><td nowrap align=\"right\">".$total."</td>\n";
 155              print "</tr>\n";
 156  
 157              $i++;
 158          }
 159          print "<tr class=\"liste_total\"><td align=\"right\">".$langs->trans("Total")." :</td><td nowrap align=\"right\"><b>".price($total)."</b></td><td>&nbsp;</td></tr>";
 160  
 161          print "</table>";
 162          $db->free($result);
 163          } else {
 164              dolibar_print_error($db);
 165          }
 166      }
 167  
 168  
 169  /*
 170   *
 171   */
 172  
 173  llxHeader();
 174  
 175  $tva = new Tva($db);
 176  
 177  $year=$_GET["year"];
 178  if ($year == 0 ) {
 179    $year_current = strftime("%Y",time());
 180    $year_start = $year_current;
 181  } else {
 182    $year_current = $year;
 183    $year_start = $year;
 184  }
 185  
 186  $textprevyear="<a href=\"index.php?year=" . ($year_current-1) . "\">".img_previous()."</a>";
 187  $textnextyear=" <a href=\"index.php?year=" . ($year_current+1) . "\">".img_next()."</a>";
 188  
 189  print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear");
 190  
 191  
 192  echo '<table width="100%">';
 193  echo '<tr><td>';
 194  print_fiche_titre($langs->trans("VATSummary"));
 195  echo '</td><td>';
 196  print_fiche_titre($langs->trans("VATPayed"));
 197  echo '</td></tr>';
 198  
 199  for ($y = $year_current ; $y >= $year_start ; $y=$y-1 ) {
 200  
 201    echo '<tr><td width="50%" valign="top">';
 202  
 203    print "<table class=\"noborder\" width=\"100%\">";
 204    print "<tr class=\"liste_titre\">";
 205    print "<td width=\"30%\">".$langs->trans("Year")." $y</td>";
 206    print "<td align=\"right\">".$langs->trans("VATToPay")."</td>";
 207    print "<td align=\"right\">".$langs->trans("VATToCollect")."</td>";
 208    print "<td align=\"right\">".$langs->trans("TotalToPay")."</td>";
 209    print "</tr>\n";
 210    $var=True;
 211    $total = 0;  $subtotal = 0;
 212    $i=0;
 213    for ($m = 1 ; $m < 13 ; $m++ ) {
 214      $var=!$var;
 215      print "<tr $bc[$var]>";
 216      print '<td nowrap>'.strftime("%b %Y",mktime(0,0,0,$m,1,$y)).'</td>';
 217      
 218      $x_coll = tva_coll($db, $y, $m);
 219      print "<td nowrap align=\"right\">".price($x_coll)."</td>";
 220      
 221      $x_paye = tva_paye($db, $y, $m);
 222      print "<td nowrap align=\"right\">".price($x_paye)."</td>";
 223      
 224      $diff = $x_coll - $x_paye;
 225      $total = $total + $diff;
 226      $subtotal = $subtotal + $diff;
 227      
 228      print "<td nowrap align=\"right\">".price($diff)."</td>\n";
 229      print "</tr>\n";
 230      
 231      $i++;
 232      if ($i > 2) {
 233        print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("SubTotal").':</td><td nowrap align="right">'.price($subtotal).'</td></tr>';
 234        $i = 0;
 235        $subtotal = 0;
 236      }
 237    }
 238    print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td nowrap align="right"><b>'.price($total).'</b></td>';
 239    print "<td>&nbsp;</td>\n";
 240    print "</table>";
 241  
 242  
 243    echo '</td><td valign="top" width="50%">';
 244  
 245  
 246    /*
 247     * Réglée
 248     */
 249  
 250    $sql = "SELECT amount, date_format(f.datev,'%Y-%m') as dm";
 251    $sql .= " FROM ".MAIN_DB_PREFIX."tva as f WHERE f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
 252    $sql .= " GROUP BY dm DESC";
 253    
 254    pt($db, $sql,$langs->trans("Year")." $y");
 255  
 256    
 257    print "</td></tr></table>";
 258  
 259    echo '</td></tr>';
 260  }
 261  
 262  
 263  echo '</table>';
 264  
 265  
 266  
 267  $db->close();
 268  
 269  llxFooter('$Date: 2005/08/16 07:39:35 $ - $Revision: 1.20 $');
 270  ?>


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