* Copyright (C) 2004 Éric Seigne * Copyright (C) 2004 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ require("./pre.inc.php"); require("../../tva.class.php"); /* * * */ function tva_coll($db, $y,$m) { $sql = "SELECT sum(f.tva) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; $sql .= " AND date_format(f.datef,'%Y') = $y"; $sql .= " AND date_format(f.datef,'%m') = $m"; $result = $db->query($sql); if ($result) { $obj = $db->fetch_object($result); return $obj->amount; } } /* * * */ function tva_paye($db, $y,$m) { $sql = "SELECT sum(f.total_tva) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f WHERE f.paye = 1"; $sql .= " AND date_format(f.datef,'%Y') = $y"; $sql .= " AND date_format(f.datef,'%m') = $m"; $result = $db->query($sql); if ($result) { $obj = $db->fetch_object($result); return $obj->amount; } } function pt ($db, $sql, $date) { global $bc; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0 ; print ""; print ""; print ""; print ""; print "\n"; print "\n"; $var=True; while ($i < $num) { $obj = $db->fetch_object($result); $var=!$var; print ""; print "\n"; $total = $total + $obj->amount; print "\n"; print "\n"; $i++; } print ""; print "
$dateMontant 
$obj->dm".price($obj->amount)."".$total."
Total :".price($total)."euros HT
"; $db->free(); } else { print $db->error(); } } /* * */ llxHeader(); $tva = new Tva($db); if ($year == 0 ) { $year_current = strftime("%Y",time()); //$year_start = $conf->years; $year_start = $year_current; } else { $year_current = $year; $year_start = $year; } $textprevyear="".img_previous().""; // On n'affiche pas "Année suivante" si c'est dans le futur ! if(($year < strftime("%Y",time())) && ($year != 0)) { $textnextyear=" ".img_next().""; } print_fiche_titre("TVA Solde : ".price($tva->solde($year_start)),"$textprevyear Année $year_start $textnextyear"); echo ''; echo ''; print_fiche_titre("TVA réglée"); //echo ''; echo ''; for ($y = $year_current ; $y >= $year_start ; $y=$y-1 ) { echo ''; } echo '
'; print_fiche_titre("TVA collectée"); echo ''; //TVA collectéeTva Réglée
'; print ""; print ""; print ""; print ""; print ""; print "\n"; print "\n"; print "\n"; $var=True; $total = 0; $subtotal = 0; $i=0; for ($m = 1 ; $m < 13 ; $m++ ) { $var=!$var; print ""; print ''; $x_coll = tva_coll($db, $y, $m); print ""; $x_paye = tva_paye($db, $y, $m); print ""; $diff = $x_coll - $x_paye; $total = $total + $diff; $subtotal = $subtotal + $diff; print "\n"; print "\n"; print "\n"; $i++; if ($i > 2) { print ''; $i = 0; $subtotal = 0; } } print ''; print "\n"; print "
Année $yCollectéePayée  
'.strftime("%b %Y",mktime(0,0,0,$m,1,$y)).'".price($x_coll)."".price($x_paye)."".price($diff)." 
Sous total :'.price($subtotal).''.price($subtotal * 0.8).'
'.$langs->trans("Total").':'.price($total).' 
"; echo '
'; /* * Réglée */ // print ""; // print "
"; $sql = "SELECT amount, date_format(f.datev,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."tva as f WHERE f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; $sql .= " GROUP BY dm DESC"; pt($db, $sql,"Année $y"); print "
"; echo '
'; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>