* Copyright (C) 2004 Éric Seigne * Copyright (C) 2004-2006 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$ * */ /** \file htdocs/compta/tva/index.php \ingroup compta \brief Page des societes \version $Revision$ */ require("./pre.inc.php"); require("../../tva.class.php"); $langs->load("other"); $year=$_GET["year"]; if ($year == 0 ) { $year_current = strftime("%Y",time()); $year_start = $year_current; } else { $year_current = $year; $year_start = $year; } /** * \brief On cherche la tva à collecter * \param db Handle accès base * \param y Année * \param m Mois */ function tva_coll($db,$y,$m) { global $conf; if ($conf->compta->mode == "CREANCES-DETTES") { // Si on paye la tva sur les factures dues (non brouillon) $sql = "SELECT sum(f.tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " WHERE "; $sql.= " f.fk_statut in (1,2)"; $sql.= " AND date_format(f.datef,'%Y') = ".$y; $sql.= " AND date_format(f.datef,'%m') = ".$m; } else { // Si on paye la tva sur les payments // \todo a ce jour on se sait pas la compter car le montant tva d'un payment // n'est pas stocké dans la table des payments. // Seul le module compta expert peut résoudre ce problème. // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le // detail part tva et part ht). /* // Tva sur factures payés $sql = "SELECT sum(f.tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " WHERE "; $sql.= " f.paye = 1"; $sql.= " AND date_format(f.datef,'%Y') = ".$y; $sql.= " AND date_format(f.datef,'%m') = ".$m; */ } $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); return $obj->amount; } else { dolibarr_print_error($db); } } /** * \brief On récupère la tva à payer * \param db Handle accès base * \param y Année * \param m Mois */ function tva_paye($db, $y,$m) { global $conf; if ($conf->compta->mode == "CREANCES-DETTES") { // Si on paye la tva sur les factures dues (non brouillon) $sql = "SELECT sum(f.total_tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= " WHERE "; $sql.= " f.fk_statut in (1,2)"; $sql.= " AND date_format(f.datef,'%Y') = $y"; $sql.= " AND date_format(f.datef,'%m') = $m"; } else { // Si on paye la tva sur les payments // \todo a ce jour on se sait pas la compter car le montant tva d'un payment // n'est pas stocké dans la table des payments. // Seul le module compta expert peut résoudre ce problème. // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le // detail part tva et part ht). /* // \todo a ce jour on se sait pas la compter car le montant tva d'un payment // n'est pas stocké dans la table des payments. // Il faut quand un payment a lieu, stocker en plus du montant du paiement le // detail part tva et part ht. // Tva sur factures payés $sql = "SELECT sum(f.total_tva) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; // $sql.= " WHERE "; $sql .= " WHERE f.fk_statut in (1,2)"; // $sql.= " f.paye = 1"; $sql.= " AND date_format(f.datef,'%Y') = $y"; $sql.= " AND date_format(f.datef,'%m') = $m"; //print "xx $sql"; */ } $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); return $obj->amount; } else { dolibarr_print_error($db); } } function pt ($db, $sql, $date) { global $conf, $bc,$langs; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $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 "
$date".$langs->trans("Amount")." 
$obj->dm".price($obj->amount)."".$total."
".$langs->trans("Total")." :".price($total)." 
"; $db->free($result); } else { dolibar_print_error($db); } } /* * */ llxHeader(); $tva = new Tva($db); $textprevyear="".img_previous().""; $textnextyear=" ".img_next().""; print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); echo ''; echo ''; echo '
'; print_fiche_titre($langs->trans("VATSummary")); echo ''; print_fiche_titre($langs->trans("VATPayed")); echo '
'; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; if ($conf->compta->mode == "CREANCES-DETTES") { $y = $year_current ; $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"; $i++; if ($i > 2) { print ''; $i = 0; $subtotal = 0; } } print ''; print "\n"; print ''; } else { print ''; print ''; } print '
".$langs->trans("Year")." $y".$langs->trans("VATToPay")."".$langs->trans("VATToCollect")."".$langs->trans("TotalToPay")."
'.strftime("%b %Y",mktime(0,0,0,$m,1,$y)).'".price($x_coll)."".price($x_paye)."".price($diff)."
'.$langs->trans("SubTotal").':'.price($subtotal).'
'.$langs->trans("TotalToPay").':'.price($total).' 
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'; echo '
'; /* * Réglée */ $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,$langs->trans("Year")." $y"); print "
"; echo ''; echo ''; $db->close(); llxFooter('$Date$ - $Revision$'); ?>