From 754d09d187a90c1e35822e1604b1697014ac370b Mon Sep 17 00:00:00 2001 From: ywarnier Date: Sun, 26 Nov 2006 23:45:53 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20fiche=20TVA=20par=20clients,=20par?= =?UTF-8?q?=20ann=E9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/tva/clients.php | 331 ++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 htdocs/compta/tva/clients.php diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php new file mode 100644 index 00000000000..79bad772612 --- /dev/null +++ b/htdocs/compta/tva/clients.php @@ -0,0 +1,331 @@ + + * Copyright (C) 2004 Éric Seigne + * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2006 Yannick Warnier + * + * 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/clients.php + \ingroup compta + \brief Page des societes + \version $Revision$ +*/ + +require("./pre.inc.php"); +require("../../tva.class.php"); + +$year=$_GET["year"]; +if ($year == 0 or $year!=intval(strval($year))) +{ + $year_current = strftime("%Y",time()); + $year_start = $year_current; +} else { + $year_current = $year; + $year_start = $year; +} + +$min = $_GET["min"]; +if($min == 0 or $min!=floatval(strval($min))){ + $min = 0.00; +}else{ + //keep min +} + +/** + * Look for collectable VAT clients in the chosen year + * @param resource Database handle + * @param int Year + */ +function tva_coll($db,$y) +{ + global $conf; + + if ($conf->compta->mode == "CREANCES-DETTES") + { + // Si on paye la tva sur les factures dues (non brouillon) + $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.idp as id_soc"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE "; + $sql.= " f.fk_statut = 1"; + $sql.= " AND date_format(f.datef,'%Y') = ".$y; + $sql.= " AND s.idp = f.fk_soc "; + $sql.= " GROUP BY s.idp"; + } + 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) + { + $list = array(); + while($assoc = $db->fetch_array($resql)){ + $list[] = $assoc; + } + return $list; + } + else + { + dolibarr_print_error($db); + } +} + + +/** + * Get payable VAT + * @param resource Database handle + * @param int Year + */ +function tva_paye($db, $y) +{ + global $conf; + + if ($conf->compta->mode == "CREANCES-DETTES") + { + // Si on paye la tva sur les factures dues (non brouillon) + $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total_ht) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.idp as id_soc"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE "; + $sql.= " f.fk_statut = 1"; + $sql.= " AND date_format(f.datef,'%Y') = ".$y; + $sql.= " AND s.idp = f.fk_soc "; + $sql.= " GROUP BY s.idp"; + } + 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 = 1"; +// $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) + { + $list = array(); + while($assoc = $db->fetch_array($resql)){ + $list[] = $assoc; + } + return $list; + } + else + { + dolibarr_print_error($db); + } +} + +/** + * Print VAT tables + * @param resource Database handler + * @param string SQL query + * @param string Date + */ +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); + } +} + + +/* + * Code + */ + +llxHeader(); + +$textprevyear="".img_previous().""; +$textnextyear=" ".img_next().""; + +print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); + +echo '
'; +echo ' '; +echo ' '; +echo ' '; +echo ' '; +echo '
'; + +echo ''; +echo ''; + +//echo ''; + +print "
'; +print_fiche_titre($langs->trans("VATSummary")); +//echo ''; +//print_fiche_titre($langs->trans("VATPayed")); +echo '
'; +echo '
"; +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print "\n"; + +if ($conf->compta->mode == "CREANCES-DETTES") +{ + $y = $year_current ; + + + $var=True; + $total = 0; $subtotal = 0; + $var=!$var; + $coll_list = tva_coll($db,$y); + $i = 1; + foreach($coll_list as $coll){ + if($min == 0 or ($min>0 and $coll[2]>$min)){ + $var=!$var; + $intra = str_replace($find,$replace,$coll[1]); + if(empty($intra)){ + if($coll[4] == '1'){ + $intra = $langs->trans('Unknown'); + }else{ + $intra = $langs->trans('NotRegistered'); + } + } + print ""; + print ""; + print ''; + $find = array(' ','.'); + $replace = array('',''); + print ""; + print ""; + print ""; + $total = $total + $coll[3]; + print "\n"; + $i++; + } + } + + print ''; + print ''; + +} +else +{ + print ''; + print ''; +} + +print '
".$langs->trans("Name")."".$langs->trans("VATIntra")."".$langs->trans("CA")."".$langs->trans("VATToPay")."
".$i."'.$coll[0].'".$intra."".price($coll[2])."".price($coll[3])."
'.$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$'); +?>