diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 99e387e15e1..34af7e07bb7 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -687,7 +687,7 @@ else $var=!$var; print ''.$langs->trans("FiscalMonthStart").''; - $monthstart=! emptpy($conf->global->SOCIETE_FISCAL_MONTH_START)? $conf->global->SOCIETE_FISCAL_MONTH_START : 1; + $monthstart=(! empty($conf->global->SOCIETE_FISCAL_MONTH_START)) ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1; print monthArrayOrSelected($monthstart) . ''; print ""; diff --git a/htdocs/admin/compta.php b/htdocs/admin/compta.php index ae112662190..c744d5ef29d 100644 --- a/htdocs/admin/compta.php +++ b/htdocs/admin/compta.php @@ -89,7 +89,18 @@ print ''.$langs->trans('OptionMode').''.$langs->trans('Description' print ''; print "\n"; print ' '.$langs->trans('OptionModeTrue').''; -print ''.nl2br($langs->trans('OptionModeTrueDesc'))."\n"; +print ''.nl2br($langs->trans('OptionModeTrueDesc')); +// Write info on way to count VAT +print "
\n"; +if ($conf->global->MAIN_MODULE_COMPTABILITE) +{ + print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite')); +} +else +{ +// print nl2br($langs->trans('OptionModeTrueInfoExpert')); +} +print "\n"; print ' '.$langs->trans('OptionModeVirtual').''; print ''.nl2br($langs->trans('OptionModeVirtualDesc'))."\n"; print ''; @@ -170,5 +181,4 @@ $db->close(); llxFooter('$Date$ - $Revision$'); - ?> diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 915ec8e50a5..16dec63f953 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -38,6 +38,7 @@ if (!$user->rights->facture->lire) $year=$_GET["year"]; if (! $year) { $year = strftime("%Y", time()); } +// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 6e19b3da74e..766f6e3eade 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -15,14 +15,12 @@ * 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$ */ /** \file htdocs/compta/resultat/index.php \brief Page reporting resultat - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -48,6 +46,7 @@ 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"]; diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index 448905f716f..c08ea1219a9 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -15,14 +15,12 @@ * 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$ */ /** \file htdocs/compta/stats/cabyuser.php \brief Page reporting CA par utilisateur - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -31,6 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/report.inc.php"); $year=$_GET["year"]; if (! $year) { $year = strftime("%Y", time()); } +// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 4a23ae6c124..ac817398824 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -33,6 +33,7 @@ $langs->load("companies"); $year=$_GET["year"]; if (! $year) { $year = strftime("%Y", time()); } +// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; diff --git a/htdocs/compta/stats/cumul.php b/htdocs/compta/stats/cumul.php index c1d77292009..e2a95dfeb35 100644 --- a/htdocs/compta/stats/cumul.php +++ b/htdocs/compta/stats/cumul.php @@ -15,33 +15,30 @@ * 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/cumul.php \brief Page reporting compta chiffre affaire cumulé - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); - -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'; } +// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') +$modecompta = $conf->compta->mode; +if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; + + + +llxHeader(); + print_titre("Chiffre d'affaire cumulé (".$langs->trans("Currency".$conf->monnaie)." HT)"); @@ -50,7 +47,7 @@ print '
'; $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 ""; - 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); - } -} /* @@ -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 '
'; -echo ' '; -echo ' '; -echo ' '; -echo ' '; -echo '
'; +$fsearch='
'; +$fsearch.=' '; +$fsearch.=' '.$langs->trans("SalesTurnover").' '.$langs->trans("Minimum").': '; +$fsearch.=' '; +$fsearch.=' '; +$fsearch.='
'; -echo ''; -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 ''; + +// VAT Received + +print "
"; +print_fiche_titre($langs->trans("VATReceived")); print "
'; -print_fiche_titre($langs->trans("VATSummary")); -//echo ''; -//print_fiche_titre($langs->trans("VATPayed")); -echo '
'; -echo '
"; print ""; -print ""; -print ""; +print '"; +print '"; print ""; -print ""; -print ""; +print ""; +print ""; 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 ""; - print ''; + print ""; + $company_static->id=$coll[5]; + $company_static->nom=$coll[0]; + print ''; $find = array(' ','.'); $replace = array('',''); print ""; @@ -291,9 +152,75 @@ if ($conf->compta->mode == "CREANCES-DETTES") } } - print ''; + print ''; print ''; +} +else +{ + print ''; + print ''; +} +print '
".$langs->trans("Name")."'.$langs->trans("Num")."'.$langs->trans("Company")."".$langs->trans("VATIntra")."".$langs->trans("CA")."".$langs->trans("VATToPay")."".$langs->trans("SalesTurnover")." ".$langs->trans("HT")."".$langs->trans("VATReceived")."
".$i."'.$coll[0].'".$i."'.$company_static->getNomUrl(1).'".$intra."
'.$langs->trans("TotalToPay").':'.price($total).'
'.$langs->trans("TotalVATReceived").':'.price($total).'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'; + + +// VAT Payed + +print "
"; +print_fiche_titre($langs->trans("VATPayed")); + +print ""; +print ""; +print '"; +print '"; +print ""; +print ""; +print ""; +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 ""; + $company_static->id=$coll[5]; + $company_static->nom=$coll[0]; + print ''; + $find = array(' ','.'); + $replace = array('',''); + print ""; + print ""; + print ""; + $total = $total + $coll[3]; + print "\n"; + $i++; + } + } + + print ''; + print ''; } else { @@ -303,29 +230,165 @@ else print '
'.$langs->trans("Num")."'.$langs->trans("Company")."".$langs->trans("VATIntra")."".$langs->trans("Outcome")." ".$langs->trans("HT")."".$langs->trans("VATPayed")."
".$i."'.$company_static->getNomUrl(1).'".$intra."".price($coll[2])."".price($coll[3])."
'.$langs->trans("TotalVATReceived").':'.price($total).'
'; - -//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$'); + + +/** + * \brief Look for collectable VAT clients in the chosen year + * \param db Database handle + * \param y Year + * \return array Liste of third parties + */ +function tva_coll($db,$y) +{ + global $conf, $modecompta; + + // Define sql request + $sql=''; + if ($modecompta == "CREANCES-DETTES") + { + // If vat payed on due invoices (non draft) + $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; + $sql.= " sum(f.total) as amount, sum(f.tva) as tva,"; + $sql.= " 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)"; // Validated or payed (partially or completely) + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND s.rowid = f.fk_soc"; + $sql.= " GROUP BY s.rowid"; + } + else + { + // If vat payed on payments + if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) + { + // \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). + } + if ($conf->global->MAIN_MODULE_COMPTABILITE) + { + // Tva sur factures payés (should be on payment) + $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; + $sql.= " sum(f.total) as amount, sum(f.tva) as tva,"; + $sql.= " 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 (2)"; // Payed (partially or completely) + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND s.rowid = f.fk_soc"; + $sql.= " GROUP BY s.rowid"; + } + } + + if ($sql) + { + dolibarr_syslog("Client::tva_coll sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $list = array(); + while($assoc = $db->fetch_array($resql)) + { + $list[] = $assoc; + } + $db->free(); + return $list; + } + else + { + dolibarr_print_error($db); + return -2; + } + } + else + { + return -1; + } +} + + +/** + * Get payable VAT + * @param resource Database handle + * @param int Year + */ +function tva_paye($db, $y) +{ + global $conf, $modecompta; + + // Define sql request + $sql=''; + if ($modecompta == "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,"; + $sql.= " sum(f.total_ht) as amount, sum(f.total_tva) as tva,"; + $sql.= " 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)"; // Validated or payed (partially or completely) + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND s.rowid = f.fk_soc "; + $sql.= " GROUP BY s.rowid"; + } + else + { + // Si on paye la tva sur les payments + + if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) + { + // \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). + } + if ($conf->global->MAIN_MODULE_COMPTABILITE) + { + // Tva sur factures payés + $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,"; + $sql.= " sum(f.total_ht) as amount, sum(f.total_tva) as tva,"; + $sql.= " 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 (2)"; // Payed (partially or completely) + $sql.= " f.paye in (1)"; // Payed (completely) + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND s.rowid = f.fk_soc "; + $sql.= " GROUP BY s.rowid"; + } + } + + if ($sql) + { + dolibarr_syslog("Client::tva_paye sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $list = array(); + while($assoc = $db->fetch_array($resql)) + { + $list[] = $assoc; + } + return $list; + } + else + { + dolibarr_print_error($db); + return -2; + } + } + else + { + return -1; + } +} + ?> diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index 7eac99da5a9..293d1c1bff2 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -15,14 +15,13 @@ * 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$ */ /** \file htdocs/compta/tva/fiche.php + \ingroup tax \brief Page des règlements de TVA - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index a3c6c0721a2..61d6d76b9e6 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -24,7 +24,7 @@ /** \file htdocs/compta/tva/index.php - \ingroup compta + \ingroup tax \brief Page des societes \version $Revision$ */ diff --git a/htdocs/compta/tva/pre.inc.php b/htdocs/compta/tva/pre.inc.php index fd82e09dd98..77e36044199 100644 --- a/htdocs/compta/tva/pre.inc.php +++ b/htdocs/compta/tva/pre.inc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Laurent Destailleur + * Copyright (C) 2005-2008 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 @@ -15,11 +15,8 @@ * 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("../../main.inc.php"); function llxHeader($head = "") { diff --git a/htdocs/compta/tva/quadri.php b/htdocs/compta/tva/quadri.php index 08ba0a48df9..39ac08d0bd0 100644 --- a/htdocs/compta/tva/quadri.php +++ b/htdocs/compta/tva/quadri.php @@ -17,18 +17,14 @@ * 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/quadri.php - \ingroup compta + \ingroup tax \brief Trimestrial page - \version $Revision$ - @todo deal with recurrent invoices as well + \version $Id$ + \todo Deal with recurrent invoices as well */ require("./pre.inc.php"); diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 8d6c0e07190..c51a811cbf2 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.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-2007 Yannick Warnier * * This program is free software; you can redistribute it and/or modify @@ -17,23 +17,23 @@ * 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/quadri_detail.php - \ingroup compta + \ingroup tax \brief Trimestrial page - detailed version - \version $Revision$ - @todo deal with recurrent invoices as well + \version $Id$ + \todo Deal with recurrent invoices as well */ 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("bills"); +$langs->load("compta"); +$langs->load("companies"); $year=$_GET["year"]; if ($year == 0 ) @@ -45,6 +45,218 @@ if ($year == 0 ) $year_start = $year; } +// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') +$modecompta = $conf->compta->mode; +if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; + + + +/** + * Affichage page + */ + +llxHeader(); + +$company_static=new Societe($db); + +print_fiche_titre($langs->trans("VAT"),""); + +// Affiche en-tête du rapport +if ($modecompta=="CREANCES-DETTES") +{ + $nom=$langs->trans("ReportByQuarter"); + $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("ReportByQuarter"); + $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); + + +// VAT Received and payed + +echo ''; + +$y = $year_current; +for ($q = 1 ; $q <= 4 ; $q++ ) +{ + $total = 0; $subtotal = 0; + $i=0; + $subtot_coll_total = 0; + $subtot_coll_vat = 0; + $subtot_paye_total = 0; + $subtot_paye_vat = 0; + $var=true; + $x_coll = tva_coll($db, $y, $q); + $x_paye = tva_paye($db, $y, $q); + + if (! is_array($x_coll)) + { + print ''; + print ''; + break; + } + + $x_both = array(); + //now, from these two arrays, get another array with one rate per line + foreach(array_keys($x_coll) as $my_coll_rate){ + $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; + $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; + $x_both[$my_coll_rate]['paye']['totalht'] = 0; + $x_both[$my_coll_rate]['paye']['vat'] = 0; + $x_both[$my_coll_rate]['coll']['links'] = ''; + $x_both[$my_coll_rate]['coll']['detail'] = array(); + foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy){ + $x_both[$my_coll_rate]['coll']['detail'][] = array( + 'id'=>$x_coll[$my_coll_rate]['facid'][$id], + 'descr'=>$x_coll[$my_coll_rate]['descr'][$id], + 'link'=>''.$x_coll[$my_coll_rate]['facnum'][$id].' ', + 'totalht'=>$x_coll[$my_coll_rate]['totalht_list'][$id], + 'vat'=>$x_coll[$my_coll_rate]['vat_list'][$id]); + //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; + } + } + // tva payed + foreach(array_keys($x_paye) as $my_paye_rate){ + $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; + $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; + if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){ + $x_both[$my_paye_rate]['coll']['totalht'] = 0; + $x_both[$my_paye_rate]['coll']['vat'] = 0; + } + $x_both[$my_paye_rate]['paye']['links'] = ''; + $x_both[$my_paye_rate]['paye']['detail'] = array(); + foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy){ + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id'=>$x_paye[$my_paye_rate]['facid'][$id], + 'descr'=>$x_paye[$my_paye_rate]['descr'][$id], + 'link'=>''.$x_paye[$my_paye_rate]['facnum'][$id].' ', + 'totalht'=>$x_paye[$my_paye_rate]['totalht_list'][$id], + 'vat'=>$x_paye[$my_paye_rate]['vat_list'][$id]); + //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; + } + } + //now we have an array (x_both) indexed by rates for coll and paye + + //print table headers for this quadri - incomes first + //imprime les en-tete de tables pour ce quadri - d'abord les revenus + + $x_coll_sum = 0; + $x_coll_ht = 0; + $x_paye_sum = 0; + $x_paye_ht = 0; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //foreach($x_both as $rate => $both){ + foreach(array_keys($x_coll) as $rate){ + $var=!$var; + if(is_array($x_both[$rate]['coll']['detail'])){ + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['coll']['detail'] as $index=>$fields){ + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + $x_coll_sum += $x_both[$rate]['coll']['vat']; + $subtot_coll_total += $x_both[$rate]['coll']['totalht']; + $subtot_coll_vat += $x_both[$rate]['coll']['vat']; + } + print '' . + '' . + '' . + '' . + '' . + '' ; + + //print table headers for this quadri - expenses now + //imprime les en-tete de tables pour ce quadri - maintenant les dépenses + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + foreach(array_keys($x_paye) as $rate){ + $var=!$var; + if(is_array($x_both[$rate]['paye']['detail'])) + { + print ""; + print ''; + print ''."\n"; + foreach($x_both[$rate]['paye']['detail'] as $index=>$fields){ + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + $x_paye_sum += $x_both[$rate]['paye']['vat']; + $subtot_paye_total += $x_both[$rate]['paye']['totalht']; + $subtot_paye_vat += $x_both[$rate]['paye']['vat']; + } + print '' . + '' . + '' . + '' . + '' . + ''; + + print ''; + print ''; + print ''."\n"; + + $diff = $x_coll_sum - $x_paye_sum; + //$total = $total + $diff; + //$subtotal = $subtotal + $diff; + + print ""; + print ''; + //print '' . + print '\n"; + print "\n"; + + print ''."\n"; + + $i++; +} + +echo '
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(0,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",mktime(0,0,0,($q*3),1,$y)).')
'.$langs->trans("CustomersInvoices").' '.$langs->trans("Description").''.$langs->trans("Income").''.$langs->trans("VATToPay").'
'.$langs->trans("Rate").': '.$rate.'%
'.$fields['link'].''.$fields['descr'].''.price($fields['totalht']).''.price($fields['vat']).'
'.$langs->trans("Total").':'.price($subtot_coll_total).''.price($subtot_coll_vat).'
'.$langs->trans("SuppliersInvoices").''.$langs->trans("Description").''.$langs->trans("Outcome").''.$langs->trans("VATToCollect").'
'.$langs->trans("Rate").': '.$rate.'%
'.$fields['link'].''.$fields['descr'].''.price($fields['totalht']).''.price($fields['vat']).'
'.$langs->trans("Total").':'.price($subtot_paye_total).''.price($subtot_paye_vat).'
'.$langs->trans("TotalToPay").' - '.$langs->trans("Quadri").$q.'
'.price($total).''.price($diff)."
 
'; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); /** @@ -59,54 +271,85 @@ if ($year == 0 ) */ function tva_coll($db,$y,$q) { - global $conf; - if ($conf->compta->mode == "CREANCES-DETTES") + global $conf, $modecompta; + + // Define sql request + $sql=''; + if ($modecompta == "CREANCES-DETTES") { - // if vat payed on due invoices - $sql = "SELECT d.fk_facture as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.total_tva as amount, d.description as descr"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, "; - $sql.= MAIN_DB_PREFIX."facturedet as d " ; + // If vat payed on due invoices (non draft) + $sql = "SELECT d.rowid, d.fk_facture as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.total_tva as amount, d.description as descr"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."facturedet as d" ; $sql.= " WHERE "; - $sql.= " f.fk_statut in (1,2) "; - $sql.= " AND f.rowid = d.fk_facture "; - $sql.= " AND date_format(f.datef,'%Y') = ".$y; + $sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) + $sql.= " AND f.rowid = d.fk_facture"; + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; - $sql.= " ORDER BY rate, facid"; - + $sql.= " ORDER BY rate, facid, d.rowid"; } else { - // if vat payed on paiments + // If vat payed on payments + if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) + { + // \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). + } + if ($conf->global->MAIN_MODULE_COMPTABILITE) + { + // Tva sur factures payés (should be on payment) + $sql = "SELECT d.rowid, d.fk_facture as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.total_tva as amount, d.description as descr"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."facturedet as d" ; + $sql.= " WHERE "; + $sql.= " f.fk_statut in (2)"; // Payed (partially or completely) + $sql.= " AND f.rowid = d.fk_facture"; + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; + $sql.= " ORDER BY d.rowid, rate, facid"; + } } - $resql = $db->query($sql); - - if ($resql) - { - $list = array(); - $rate = -1; - while($assoc = $db->fetch_array($resql)) - { - if($assoc['rate'] != $rate){ //new rate - $list[$assoc['rate']]['totalht'] = $assoc['totalht']; - $list[$assoc['rate']]['vat'] = $assoc['amount']; - }else{ - $list[$assoc['rate']]['totalht'] += $assoc['totalht']; - $list[$assoc['rate']]['vat'] += $assoc['amount']; - } - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['totalht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['amount']; - $rate = $assoc['rate']; - } - return $list; - } - else - { - dolibarr_print_error($db); - } + if ($sql) + { + dolibarr_syslog("Client::tva_coll sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $list = array(); + $rate = -1; + while($assoc = $db->fetch_array($resql)) + { + if($assoc['rate'] != $rate){ //new rate + $list[$assoc['rate']]['totalht'] = $assoc['totalht']; + $list[$assoc['rate']]['vat'] = $assoc['amount']; + }else{ + $list[$assoc['rate']]['totalht'] += $assoc['totalht']; + $list[$assoc['rate']]['vat'] += $assoc['amount']; + } + $list[$assoc['rate']]['facid'][] = $assoc['facid']; + $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; + $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$assoc['rate']]['totalht_list'][] = $assoc['totalht']; + $list[$assoc['rate']]['vat_list'][] = $assoc['amount']; + $rate = $assoc['rate']; + } + return $list; + } + else + { + dolibarr_print_error($db); + return -2; + } + } + else + { + return -1; + } } @@ -121,235 +364,88 @@ function tva_coll($db,$y,$q) */ function tva_paye($db, $y,$q) { - global $conf; + global $conf, $modecompta; - if ($conf->compta->mode == "CREANCES-DETTES") + // Define sql request + $sql=''; + if ($modecompta == "CREANCES-DETTES") { // Si on paye la tva sur les factures dues (non brouillon) - $sql = "SELECT d.fk_facture_fourn as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.tva as amount, d.description as descr "; + $sql = "SELECT d.rowid, d.fk_facture_fourn as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.tva as amount, d.description as descr "; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, "; - $sql.= MAIN_DB_PREFIX."facture_fourn_det as d " ; + $sql.= " ".MAIN_DB_PREFIX."facture_fourn_det as d " ; $sql.= " WHERE "; - $sql.= " f.fk_statut in (1,2) "; + $sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) $sql.= " AND f.rowid = d.fk_facture_fourn "; - $sql.= " AND date_format(f.datef,'%Y') = ".$y; + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; - $sql.= " ORDER BY rate, facid "; + $sql.= " ORDER BY d.rowid, rate, facid "; } else { // Si on paye la tva sur les payments - } - $resql = $db->query($sql); - if ($resql) - { - $list = array(); - $rate = -1; - while($assoc = $db->fetch_array($resql)) - { - if($assoc['rate'] != $rate){ //new rate - $list[$assoc['rate']]['totalht'] = $assoc['totalht']; - $list[$assoc['rate']]['vat'] = $assoc['amount']; - }else{ - $list[$assoc['rate']]['totalht'] += $assoc['totalht']; - $list[$assoc['rate']]['vat'] += $assoc['amount']; - } - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['totalht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['amount']; - $rate = $assoc['rate']; - } - return $list; - - } - else - { - dolibarr_print_error($db); - } -} - -/** - * Main script - */ - -llxHeader(); - -$textprevyear="".img_previous().""; -$textnextyear=" ".img_next().""; - -print_fiche_titre($langs->trans("VAT"),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear"); -print '
'; - -echo ''; - -if ($conf->compta->mode == "CREANCES-DETTES") -{ - $y = $year_current ; - - - for ($q = 1 ; $q <= 4 ; $q++ ) - { - $total = 0; $subtotal = 0; - $i=0; - $subtot_coll_total = 0; - $subtot_coll_vat = 0; - $subtot_paye_total = 0; - $subtot_paye_vat = 0; - $var=true; - $x_coll = tva_coll($db, $y, $q); - $x_paye = tva_paye($db, $y, $q); - $x_both = array(); - //now, from these two arrays, get another array with one rate per line - foreach(array_keys($x_coll) as $my_coll_rate){ - $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; - $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; - $x_both[$my_coll_rate]['paye']['totalht'] = 0; - $x_both[$my_coll_rate]['paye']['vat'] = 0; - $x_both[$my_coll_rate]['coll']['links'] = ''; - $x_both[$my_coll_rate]['coll']['detail'] = array(); - foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy){ - $x_both[$my_coll_rate]['coll']['detail'][] = array( - 'id'=>$x_coll[$my_coll_rate]['facid'][$id], - 'descr'=>$x_coll[$my_coll_rate]['descr'][$id], - 'link'=>''.$x_coll[$my_coll_rate]['facnum'][$id].' ', - 'totalht'=>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat'=>$x_coll[$my_coll_rate]['vat_list'][$id]); - //$x_both[$my_coll_rate]['coll']['links'] .= '..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).' '; - } + if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT) + { + // \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 payed - foreach(array_keys($x_paye) as $my_paye_rate){ - $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; - $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; - if(!isset($x_both[$my_paye_rate]['coll']['totalht'])){ - $x_both[$my_paye_rate]['coll']['totalht'] = 0; - $x_both[$my_paye_rate]['coll']['vat'] = 0; - } - $x_both[$my_paye_rate]['paye']['links'] = ''; - $x_both[$my_paye_rate]['paye']['detail'] = array(); - foreach($x_paye[$my_paye_rate]['facid'] as $id=>$dummy){ - $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id'=>$x_paye[$my_paye_rate]['facid'][$id], - 'descr'=>$x_paye[$my_paye_rate]['descr'][$id], - 'link'=>''.$x_paye[$my_paye_rate]['facnum'][$id].' ', - 'totalht'=>$x_paye[$my_paye_rate]['totalht_list'][$id], - 'vat'=>$x_paye[$my_paye_rate]['vat_list'][$id]); - //$x_both[$my_paye_rate]['paye']['links'] .= '..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).' '; - } + if ($conf->global->MAIN_MODULE_COMPTABILITE) + { + // Tva sur factures payés + $sql = "SELECT d.rowid, d.fk_facture_fourn as facid, f.facnumber as facnum, d.tva_taux as rate, d.total_ht as totalht, d.tva as amount, d.description as descr "; + $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, "; + $sql.= " ".MAIN_DB_PREFIX."facture_fourn_det as d " ; + $sql.= " WHERE "; + //$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely) + $sql.= " f.paye in (1)"; // Payed (completely) + $sql.= " AND f.rowid = d.fk_facture_fourn "; + $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'"; + $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")"; + $sql.= " ORDER BY d.rowid, rate, facid "; } - //now we have an array (x_both) indexed by rates for coll and paye - - //print table headers for this quadri - incomes first - //imprime les en-tete de tables pour ce quadri - d'abord les revenus - - $x_coll_sum = 0; - $x_coll_ht = 0; - $x_paye_sum = 0; - $x_paye_ht = 0; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - //foreach($x_both as $rate => $both){ - foreach(array_keys($x_coll) as $rate){ - $var=!$var; - if(is_array($x_both[$rate]['coll']['detail'])){ - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['coll']['detail'] as $index=>$fields){ - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - } - $x_coll_sum += $x_both[$rate]['coll']['vat']; - $subtot_coll_total += $x_both[$rate]['coll']['totalht']; - $subtot_coll_vat += $x_both[$rate]['coll']['vat']; - } - print '' . - '' . - '' . - '' . - '' . - '' ; - - //print table headers for this quadri - expenses now - //imprime les en-tete de tables pour ce quadri - maintenant les dépenses - print ''; - print ''; - print ''; - print ''; - print ''; - print ''."\n"; - foreach(array_keys($x_paye) as $rate){ - $var=!$var; - if(is_array($x_both[$rate]['paye']['detail'])) - { - print ""; - print ''; - print ''."\n"; - foreach($x_both[$rate]['paye']['detail'] as $index=>$fields){ - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - } - $x_paye_sum += $x_both[$rate]['paye']['vat']; - $subtot_paye_total += $x_both[$rate]['paye']['totalht']; - $subtot_paye_vat += $x_both[$rate]['paye']['vat']; - } - print '' . - '' . - '' . - '' . - '' . - ''; - - print ''; - print ''; - print ''."\n"; - - $diff = $x_coll_sum - $x_paye_sum; - //$total = $total + $diff; - //$subtotal = $subtotal + $diff; - - print ""; - print ''; - //print '' . - print '\n"; - print "\n"; - - print ''."\n"; - - $i++; } -} -else -{ - print ''; - print ''; + if ($sql) + { + dolibarr_syslog("Client::tva_paye sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $list = array(); + $rate = -1; + while($assoc = $db->fetch_array($resql)) + { + if($assoc['rate'] != $rate){ //new rate + $list[$assoc['rate']]['totalht'] = $assoc['totalht']; + $list[$assoc['rate']]['vat'] = $assoc['amount']; + }else{ + $list[$assoc['rate']]['totalht'] += $assoc['totalht']; + $list[$assoc['rate']]['vat'] += $assoc['amount']; + } + $list[$assoc['rate']]['facid'][] = $assoc['facid']; + $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; + $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$assoc['rate']]['totalht_list'][] = $assoc['totalht']; + $list[$assoc['rate']]['vat_list'][] = $assoc['amount']; + $rate = $assoc['rate']; + } + return $list; + + } + else + { + dolibarr_print_error($db); + return -2; + } + } + else + { + return -1; + } } -echo '
'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(0,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",mktime(0,0,0,($q*3),1,$y)).')
'.$langs->trans("CustomersInvoices").' '.$langs->trans("Description").''.$langs->trans("Income").''.$langs->trans("VATToPay").'
'.$langs->trans("Rate").': '.$rate.'%
'.$fields['link'].''.$fields['descr'].''.price($fields['totalht']).''.price($fields['vat']).'
'.$langs->trans("Total").':'.price($subtot_coll_total).''.price($subtot_coll_vat).'
'.$langs->trans("SuppliersInvoices").''.$langs->trans("Description").''.$langs->trans("Outcome").''.$langs->trans("VATToCollect").'
'.$langs->trans("Rate").': '.$rate.'%
'.$fields['link'].''.$fields['descr'].''.price($fields['totalht']).''.price($fields['vat']).'
'.$langs->trans("Total").':'.price($subtot_paye_total).''.price($subtot_paye_vat).'
'.$langs->trans("TotalToPay").' - '.$langs->trans("Quadri").$q.'
'.price($total).''.price($diff)."
 
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'
'; - - -$db->close(); - -llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 668d314dbf3..196e7ea9704 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -21,6 +21,7 @@ /** \file htdocs/compta/tva/reglement.php + \ingroup tax \brief Liste des règlements de TVA effectués \version $Revision$ */ diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php index 8760943c15d..8303697ce1c 100644 --- a/htdocs/conf/conf.class.php +++ b/htdocs/conf/conf.class.php @@ -380,15 +380,16 @@ class Conf if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE='EUR'; $this->monnaie=$this->global->MAIN_MONNAIE; - // $this->compta->mode = Option du module Compta: Defini le mode de calcul des etats comptables (CA,...) - $this->compta->mode = 'RECETTES-DEPENSES'; // Par defaut - if (defined('COMPTA_MODE') && COMPTA_MODE) { + // $this->compta->mode = Option du module Comptabilite (simple ou expert): + // Defini le mode de calcul des etats comptables (CA,...) + $this->compta->mode = 'RECETTES-DEPENSES'; // By default + if (isset($this->global->COMPTA_MODE)) { // Peut etre 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' - $this->compta->mode = COMPTA_MODE; + $this->compta->mode = $this->global->COMPTA_MODE; } // $this->defaulttx - if (defined('FACTURE_TVAOPTION') && FACTURE_TVAOPTION == 'franchise') + if (isset($this->global->FACTURE_TVAOPTION) && $this->global->FACTURE_TVAOPTION == 'franchise') { $this->defaulttx='0'; // Taux par defaut des factures clients } @@ -454,7 +455,7 @@ class Conf /* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de desactiver la fonction TVA * (pour particuliers ou liberaux en franchise) - * En attendant, valeur forcee a 1 + * En attendant, valeur forcee a 1 car toujours interessant a avoir meme ceux qui veulent pas. */ $this->compta->tva=1; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 8b48de8f3ee..8a49833b367 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -21,15 +21,13 @@ * 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$ */ /** \file htdocs/facture.class.php \ingroup facture \brief Fichier de la classe des factures clients - \version $Revision$ + \version $Id$ */ require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 50fa5eb6efe..af921d070da 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -18,16 +18,13 @@ * 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/fourn/fournisseur.facture.class.php \ingroup fournisseur,facture \brief Fichier de la classe des factures fournisseurs - \version $Revision$ + \version $Id$ */ include_once(DOL_DOCUMENT_ROOT."/facture.class.php"); @@ -43,8 +40,15 @@ class FactureFournisseur extends Facture var $id; var $db; var $socid; + + //! 0=brouillon, + //! 1=validée, + //! TODO Ce statut doit etre 2 et non 1 classée payée partiellement (close_code='discount_vat','badcustomer') ou complètement (close_code=null), + //! TODO Ce statut doit etre 2 et non 1 classée abandonnée et aucun paiement n'a eu lieu (close_code='badcustomer','abandon' ou 'replaced') var $statut; + //! 1 si facture payée COMPLETEMENT, 0 sinon (ce champ ne devrait plus servir car insuffisant) var $paye; + var $author; var $libelle; var $date; diff --git a/htdocs/includes/modules/modComptabilite.class.php b/htdocs/includes/modules/modComptabilite.class.php index 7a58b812e9c..36fa31f53e0 100644 --- a/htdocs/includes/modules/modComptabilite.class.php +++ b/htdocs/includes/modules/modComptabilite.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * @@ -17,12 +17,11 @@ * 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$ */ /** \defgroup comptabilite Module comptabilite \brief Module pour inclure des fonctions de comptabilit� (gestion de comptes comptables et rapports) + \version $Id$ */ /** diff --git a/htdocs/includes/modules/modComptabiliteExpert.class.php b/htdocs/includes/modules/modComptabiliteExpert.class.php index 50a959643d7..4fff9b43071 100644 --- a/htdocs/includes/modules/modComptabiliteExpert.class.php +++ b/htdocs/includes/modules/modComptabiliteExpert.class.php @@ -17,12 +17,11 @@ * 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$ */ /** \defgroup comptabilite_expert Module comptabilite expert \brief Module pour inclure des fonctions de comptabilit� (gestion de comptes comptables et rapports) + \version $Id$ */ /** diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 73aa6c17d34..1af16c6d131 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -6,8 +6,10 @@ MenuFinancial=Financial OptionMode=Option for accountancy OptionModeTrue=Option Input-Ouput OptionModeVirtual=Option Credits-Debits -OptionModeTrueDesc=In this context, the turnover is calculated over paid invoices. \nThe validity of the figures is assured only if the book-keeping is scrutinized through the input/output on the accounts via invoices. \nRemarks: in this version, Dolibarr use the passed date of invoices with state 'Validated' and not passed date with state 'Paid'. +OptionModeTrueDesc=In this context, the turnover is calculated over paid invoices. \nThe validity of the figures is assured only if the book-keeping is scrutinized through the input/output on the accounts via invoices. +OptionModeTrueInfoModuleComptabilite=Remarks: In this accountancy module, Dolibarr use the passed date of invoices with state 'Validated' and not passed date of real individual payments. OptionModeVirtualDesc=In this context, the turnover is calculated over validated invoices. When these invoices are due, whether they have been paid or not, they are listed in the turnover output. +VATReportDesc=This report sows VAT received and payed. FeatureIsSupportedInInOutModeOnly=Feature only available in CREDITS-DEBTS accountancy mode (See Accountancy module configuration) Param=Setup AccountsGeneral=Accounts @@ -24,6 +26,7 @@ Withdrawal=Withdrawal Withdrawals=Withdrawals VAT=VAT VATToPay=VAT to pay +VATReceived=VAT received VATToCollect=VAT to collect VATSummary=VAT Summary VATPayed=VAT payed @@ -49,6 +52,7 @@ NewVATPayment=New VAT payment VATPayment=VAT Payment VATPayments=VAT Payments TotalToPay=Total to pay +TotalVATReceived=Total VAT received CustomerAccountancyCode=Customer accountancy code SupplierAccountancyCode=Supplier accountacy code AlreadyPayed=Already payed diff --git a/htdocs/langs/fr_BE/compta.lang b/htdocs/langs/fr_BE/compta.lang index bfc12f24937..0cf86715657 100644 --- a/htdocs/langs/fr_BE/compta.lang +++ b/htdocs/langs/fr_BE/compta.lang @@ -6,7 +6,8 @@ MenuFinancial=Financier OptionMode=Option de tenue de comptabilité OptionModeTrue=Option Recettes-Dépenses OptionModeVirtual=Option Créances-Dettes -OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des factures payées.\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures.\nRemarque : dans cette version, Dolibarr utilise la date de passage de la facture à l'état 'Validée' et non la date de passage à l'état 'Payée'. +OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des factures payées.\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures. +OptionModeTrueInfoModuleComptabilite=Remarque : Dans ce module comptabilite, Dolibarr utilise la date de passage de la facture à l'état 'Validée' et non la date de passage à l'état 'Payée'. OptionModeVirtualDesc=Dans ce mode, le CA est calculé sur la base des factures validées. Qu'elles soient ou non payés, dès lors qu'elles sont dues, elles apparaissent dans le résultat. FeatureIsSupportedInInOutModeOnly=Fonctionnalité disponible uniquement en mode de comptabilité CREDITS-DEBITS (voir configuration du module Comptabilité) Param=Configuration diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index 0b6e76dd485..ab4663f2ff5 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -6,8 +6,10 @@ MenuFinancial=Compta/Tr OptionMode=Option de tenue de comptabilité OptionModeTrue=Option Recettes-Dépenses OptionModeVirtual=Option Créances-Dettes -OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des factures payées.\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures.\nRemarque : dans cette version, Dolibarr utilise la date de passage de la facture à l'état 'Validée' et non la date de passage à l'état 'Payée'. +OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des factures payées.\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures. +OptionModeTrueInfoModuleComptabilite=Remarque : Dans le module comptabilite actif, Dolibarr utilise la date de passage de la facture à l'état 'Validée' et non la date des paiements individuels. OptionModeVirtualDesc=Dans ce mode, le CA est calculé sur la base des factures validées. Payées ou non, elles apparaissent dans le résultat dès qu'elles sont dues. +VATReportDesc=Cet écran présente le rapport des TVA perçus et payés. FeatureIsSupportedInInOutModeOnly=Fonction disponible uniquement en mode compta CREANCES-DETTES (Voir configuration du module compta) Param=Paramétrage AccountsGeneral=Comptes généraux @@ -24,6 +26,7 @@ Withdrawl=Pr Withdrawls=Prélèvements VAT=TVA VATToPay=TVA à payer +VATReceived=TVA perçue VATToCollect=TVA à récupérer VATSummary=Résumé TVA VATPayed=TVA payée @@ -49,6 +52,7 @@ NewVATPayment=Nouveau r VATPayment=Réglement TVA VATPayments=Réglements TVA TotalToPay=Total à payer +TotalVATReceived=Total TVA perçue CustomerAccountancyCode=Code compta client SupplierAccountancyCode=Code compta fournisseur AlreadyPayed=Déjà réglé