| ';
$sql = "SELECT sum(f.total) as amount , date_format(f.datef,'%Y-%m') as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.fk_statut in (1,2)";
-if ($conf->compta->mode != 'CREANCES-DETTES')
+if ($modecompta != 'CREANCES-DETTES')
{
$sql .= " AND f.paye = 1";
}
@@ -67,7 +64,7 @@ print ' | ';
$sql = "SELECT sum(f.total) as amount, year(f.datef) as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.fk_statut in (1,2)";
-if ($conf->compta->mode != 'CREANCES-DETTES') {
+if ($modecompta != 'CREANCES-DETTES') {
$sql .= " AND f.paye = 1";
}
if ($socid)
diff --git a/htdocs/compta/stats/exercices.php b/htdocs/compta/stats/exercices.php
index 734d047a2dc..d1dbe171c49 100644
--- a/htdocs/compta/stats/exercices.php
+++ b/htdocs/compta/stats/exercices.php
@@ -15,33 +15,32 @@
* 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/stats/exercices.php
+ \brief Page ???
+ \version $Id$
+*/
+
require("./pre.inc.php");
require("./lib.inc.php");
-/*
- *
- */
+// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
+$modecompta = $conf->compta->mode;
+if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
-llxHeader();
-
-/*
- * Sécurité accés client
- */
+// Sécurité accés client
if ($user->societe_id > 0)
{
$socid = $user->societe_id;
}
-$mode='recettes';
-if ($conf->compta->mode == 'CREANCES-DETTES') { $mode='creances'; }
-print_titre("Comparatif CA année en cours avec année précédente (".$langs->trans("Currency".$conf->monnaie)." HT, ".$mode.")");
+llxHeader();
+
+print_titre("Comparatif CA année en cours avec année précédente (".$langs->trans("Currency".$conf->monnaie)." HT, ".$modecompta.")");
print " \n";
@@ -256,5 +255,5 @@ ppt($db, $cyear, $socid);
$db->close();
-llxFooter("Dernière modification $Date$ révision $Revision$");
+llxFooter('$Date$ révision $Revision$');
?>
diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index fb4bfe2b121..54399293e9e 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -47,9 +47,11 @@ if ($user->societe_id > 0)
$socid = $user->societe_id;
}
+// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->compta->mode;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
+
llxHeader();
$html=new Form($db);
diff --git a/htdocs/compta/stats/lib.inc.php b/htdocs/compta/stats/lib.inc.php
index d2cf3980c5a..95bfb201c9c 100644
--- a/htdocs/compta/stats/lib.inc.php
+++ b/htdocs/compta/stats/lib.inc.php
@@ -45,7 +45,8 @@ function get_ca_propal ($db, $year, $socid)
function get_ca ($db, $year, $socid)
{
-
+ global $conf;
+
$sql = "SELECT sum(f.amount) as sum FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.fk_statut in (1,2)";
if ($conf->compta->mode != 'CREANCES-DETTES') {
diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php
index bd8125193cf..8faad0a7565 100644
--- a/htdocs/compta/tva/clients.php
+++ b/htdocs/compta/tva/clients.php
@@ -1,7 +1,7 @@
* Copyright (C) 2004 Éric Seigne
- * Copyright (C) 2004-2006 Laurent Destailleur
+ * Copyright (C) 2004-2008 Laurent Destailleur
* Copyright (C) 2006 Yannick Warnier
*
* This program is free software; you can redistribute it and/or modify
@@ -17,21 +17,21 @@
* 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$
+ \version $Id$
*/
require("./pre.inc.php");
-require("../../tva.class.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/report.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/tva.class.php");
+
+$langs->load("compta");
+$langs->load("companies");
$year=$_GET["year"];
if ($year == 0 or $year!=intval(strval($year)))
@@ -50,173 +50,10 @@ if($min == 0 or $min!=floatval(strval($min))){
//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.rowid as socid";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
- $sql.= " WHERE ";
- $sql.= " f.fk_statut in (1,2)";
- $sql.= " AND date_format(f.datef,'%Y') = ".$y;
- $sql.= " AND s.rowid = f.fk_soc ";
- $sql.= " GROUP BY s.rowid";
- }
- 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;
-*/
- }
+// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
+$modecompta = $conf->compta->mode;
+if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
- $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.rowid as socid";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
- $sql.= " WHERE ";
- $sql.= " f.fk_statut in (1,2)";
- $sql.= " AND date_format(f.datef,'%Y') = ".$y;
- $sql.= " AND s.rowid = f.fk_soc ";
- $sql.= " GROUP BY s.rowid";
- }
- 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)
- {
- $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 "| $date | ";
- print "".$langs->trans("Amount")." | ";
- print " | \n";
- print " \n";
- $var=True;
- while ($i < $num)
- {
- $obj = $db->fetch_object($result);
- $var=!$var;
- print "";
- print "| $obj->dm | \n";
- $total = $total + $obj->amount;
-
- print "".price($obj->amount)." | ".$total." | \n";
- print " \n";
-
- $i++;
- }
- print "| ".$langs->trans("Total")." : | ".price($total)." | | ";
-
- print " ";
- $db->free($result);
- }
- else {
- dolibar_print_error($db);
- }
-}
/*
@@ -225,61 +62,85 @@ function pt ($db, $sql, $date)
llxHeader();
-$textprevyear="".img_previous()."";
-$textnextyear=" ".img_next()."";
+$company_static=new Societe($db);
-print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear");
+print_fiche_titre($langs->trans("VAT"),"");
-echo '';
+$fsearch='';
-echo '';
-echo '| ';
-print_fiche_titre($langs->trans("VATSummary"));
-//echo ' | ';
-//print_fiche_titre($langs->trans("VATPayed"));
-echo ' | ';
+// Affiche en-tête du rapport
+if ($modecompta=="CREANCES-DETTES")
+{
+ $nom=$langs->trans("ReportByCustomers");
+ $nom.=' ('.$langs->trans("SeeReportInInputOutputMode",'','').')';
+ $period=$year_start;
+ $periodlink=($year_start?"".img_previous()." ".img_next()."":"");
+ $description=$langs->trans("VATReportDesc");
+ $description.=$fsearch;
+ $builddate=time();
+ $exportlink=$langs->trans("NotYetAvailable");
+}
+else {
+ $nom=$langs->trans("ReportByCustomers");
+ $nom.=' ('.$langs->trans("SeeReportInDueDebtMode",'','').')';
+ $period=$year_start;
+ $periodlink=($year_start?"".img_previous()." ".img_next()."":"");
+ $description=$langs->trans("VATReportDesc");
+ if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.=' '.img_warning().' '.$langs->trans('OptionModeTrueInfoModuleComptabilite');
+ $description.=$fsearch;
+ $builddate=time();
+ $exportlink=$langs->trans("NotYetAvailable");
+}
+report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
-//echo '| ';
-echo ' | ';
+
+// VAT Received
+
+print " ";
+print_fiche_titre($langs->trans("VATReceived"));
print "";
print "";
-print " | ";
-print "".$langs->trans("Name")." | ";
+print ''.$langs->trans("Num")." | ";
+print ''.$langs->trans("Company")." | ";
print "".$langs->trans("VATIntra")." | ";
-print "".$langs->trans("CA")." | ";
-print "".$langs->trans("VATToPay")." | ";
+print "".$langs->trans("SalesTurnover")." ".$langs->trans("HT")." | ";
+print "".$langs->trans("VATReceived")." | ";
print " \n";
-if ($conf->compta->mode == "CREANCES-DETTES")
+$coll_list = tva_coll($db,$year_current);
+if (is_array($coll_list))
{
- $y = $year_current ;
-
-
- $var=True;
+ $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)){
+ 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'){
+ if(empty($intra))
+ {
+ if($coll[4] == '1')
+ {
$intra = $langs->trans('Unknown');
- }else{
+ }
+ else
+ {
$intra = $langs->trans('NotRegistered');
}
}
print "";
- print "| ".$i." | ";
- print ''.$coll[0].' | ';
+ print "".$i." | ";
+ $company_static->id=$coll[5];
+ $company_static->nom=$coll[0];
+ print ''.$company_static->getNomUrl(1).' | ';
$find = array(' ','.');
$replace = array('','');
print "".$intra." | ";
@@ -291,9 +152,75 @@ if ($conf->compta->mode == "CREANCES-DETTES")
}
}
- print ' | '.$langs->trans("TotalToPay").': | '.price($total).' | ';
+ print ' | '.$langs->trans("TotalVATReceived").': | '.price($total).' | ';
print ' ';
+}
+else
+{
+ print '| '.$langs->trans("FeatureNotYetAvailable").' | ';
+ print '| '.$langs->trans("FeatureIsSupportedInInOutModeOnly").' | ';
+}
+print ' ';
+
+
+// VAT Payed
+
+print " ";
+print_fiche_titre($langs->trans("VATPayed"));
+
+print "";
+print "";
+print '| '.$langs->trans("Num")." | ";
+print ''.$langs->trans("Company")." | ";
+print "".$langs->trans("VATIntra")." | ";
+print "".$langs->trans("Outcome")." ".$langs->trans("HT")." | ";
+print "".$langs->trans("VATPayed")." | ";
+print " \n";
+
+$company_static=new Societe($db);
+
+$coll_list = tva_paye($db,$year_current);
+if (is_array($coll_list))
+{
+ $var=true;
+ $total = 0; $subtotal = 0;
+ $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 "| ".$i." | ";
+ $company_static->id=$coll[5];
+ $company_static->nom=$coll[0];
+ print ''.$company_static->getNomUrl(1).' | ';
+ $find = array(' ','.');
+ $replace = array('','');
+ print "".$intra." | ";
+ print "".price($coll[2])." | ";
+ print "".price($coll[3])." | ";
+ $total = $total + $coll[3];
+ print " \n";
+ $i++;
+ }
+ }
+
+ print '| '.$langs->trans("TotalVATReceived").': | '.price($total).' | ';
+ print ' ';
}
else
{
@@ -303,29 +230,165 @@ else
print ' ';
-
-//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 '