From 0ace4b44f273dbf1955f3f44d47a8c45e1e51299 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 May 2005 00:21:33 +0000 Subject: [PATCH] =?UTF-8?q?Corrections=20mauvais=20r=E9sultat=20du=20ca=20?= =?UTF-8?q?par=20utilisateur=20et=20support=20des=202=20modes=20comptables?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/resultat/clientfourn.php | 28 ++-- htdocs/compta/resultat/index.php | 45 ++++-- htdocs/compta/stats/cabyuser.php | 201 +++++++++++++++++-------- htdocs/compta/stats/casoc.php | 9 +- htdocs/compta/stats/index.php | 58 +++++-- htdocs/langs/en_US/main.lang | 1 + htdocs/langs/fr_FR/main.lang | 1 + 7 files changed, 234 insertions(+), 109 deletions(-) diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 5601152f90a..6fe2755865d 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -80,30 +80,26 @@ print ' '; /* * Factures clients */ +print 'Facturation clients'; + if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; - if ($year) { - $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } + if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } else { /* - * Liste des paiements par société (les anciens paiements ne sont pas inclus - * car n'était pas liés sur les vieilles versions) + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) */ - $sql = "SELECT s.nom as nom, s.idp as idp, sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; + $sql = "SELECT s.nom as nom, s.idp as idp, sum(pf.amount) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE f.fk_soc = s.idp AND f.rowid = pf.fk_facture AND pf.fk_paiement = p.rowid"; - if ($year) { - $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } + $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp"; + if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } $sql .= " GROUP BY nom"; $sql .= " ORDER BY nom"; -print 'Facturation clients'; - $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -130,15 +126,13 @@ if ($result) { dolibarr_print_error($db); } -// Ajoute paiements anciennes version non liés par paiement_facture +// On ajoute les paiements anciennes version, non liés par paiement_facture if ($modecompta != 'CREANCES-DETTES') { - $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; + $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql .= " WHERE pf.rowid IS NULL"; - if ($year) { - $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } + if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; $sql .= " GROUP BY nom"; $sql .= " ORDER BY nom"; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 803ada1f2aa..dd04866db41 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -84,18 +84,17 @@ if ($modecompta == 'CREANCES-DETTES') { $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; } else { - $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f"; - $sql .= " ON f.rowid = p.fk_facture"; - $sql .= " WHERE 1=1"; -} -if ($socidp) -{ - $sql .= " AND f.fk_soc = $socidp"; + /* + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) + */ + $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid"; } +if ($socidp) $sql .= " AND f.fk_soc = $socidp"; $sql .= " GROUP BY dm"; - +$sql .= " ORDER BY dm"; $result=$db->query($sql); if ($result) @@ -115,6 +114,32 @@ else { dolibarr_print_error($db); } +// On ajoute les paiements anciennes version, non liés par paiement_facture +if ($modecompta != 'CREANCES-DETTES') { + $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + $sql .= " GROUP BY dm"; + $sql .= " ORDER BY dm"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_object($result); + $encaiss[$row->dm] += $row->amount_ht; + $encaiss_ttc[$row->dm] += $row->amount_ttc; + $i++; + } + } + else { + dolibarr_print_error($db); + } +} + /* * Frais, factures fournisseurs. diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index 8ea19b3a436..4c82200e53c 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004-2005 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 @@ -20,98 +20,167 @@ * $Source$ * */ + +/** + \file htdocs/compta/stats/cabyuser.php + \brief Page reporting CA par utilisateur + \version $Revision$ +*/ + require("./pre.inc.php"); /* * Sécurité accés client */ -if ($user->societe_id > 0) +if ($user->societe_id > 0) { - $socidp = $user->societe_id; + $socidp = $user->societe_id; } -/* - * - */ + +$year=$_GET["year"]; +if (! $year) { $year = strftime("%Y", time()); } +$modecompta = $conf->compta->mode; +if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; + + + llxHeader(); -print_titre("Chiffre d'affaire par utilisateur (euros HT)"); -/* - * Ca total - * - */ +$html=new Form($db); -$sql = "SELECT sum(f.total) as ca FROM ".MAIN_DB_PREFIX."facture as f"; -$sql .= " WHERE f.fk_statut = 1"; -if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; -} -if ($socidp) +// Affiche en-tête du rapport +if ($modecompta=="CREANCES-DETTES") { - $sql .= " AND f.fk_soc = $socidp"; + $nom="Chiffre d'affaire par utilisateur, auteur de la facture"; + $nom.=' (Voir le rapport recettes-dépenses pour n\'inclure que les factures effectivement payées)'; + $period="".img_previous()." ".$langs->trans("Year")." $year ".img_next().""; + $description=$langs->trans("RulesCADue"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); } +else { + $nom="Chiffre d'affaire par utilisateur, auteur de la facture"; + $nom.=' (Voir le rapport en créances-dettes pour inclure les factures non encore payée)'; + $period="".img_previous()." ".$langs->trans("Year")." $year ".img_next().""; + $description=$langs->trans("RulesCAIn"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); +} +$html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); + + +// Charge tableau +$catotal=0; +if ($modecompta == 'CREANCES-DETTES') +{ + $sql = "SELECT u.rowid as rowid, u.name as name, u.firstname as firstname, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u,".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut = 1 AND f.fk_user_author = u.rowid"; + if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; +} +else +{ + /* + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) + */ + $sql = "SELECT u.rowid as rowid, u.name as name, u.firstname as firstname, sum(pf.amount) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_user_author = u.rowid"; + if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; +} +if ($socidp) $sql .= " AND f.fk_soc = $socidp"; +$sql .= " GROUP BY rowid"; +$sql .= " ORDER BY rowid"; + $result = $db->query($sql); if ($result) { - if ($db->num_rows() > 0) + $num = $db->num_rows($result); + $i=0; + while ($i < $num) { - $objp = $db->fetch_object($result); - $catotal = $objp->ca; + $obj = $db->fetch_object($result); + $amount[$obj->rowid] = $obj->amount_ttc; + $name[$obj->rowid] = $obj->name.' '.$obj->firstname; + $catotal+=$obj->amount_ttc; + $i++; + } +} +else { + dolibarr_print_error($db); +} + +// On ajoute les paiements anciennes version, non liés par paiement_facture +if ($modecompta != 'CREANCES-DETTES') +{ + $sql = "SELECT -1 as rowid, '' as name, '' as firstname, sum(p.amount) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql .= " GROUP BY rowid"; + $sql .= " ORDER BY rowid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i=0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $amount[$obj->rowid] = $obj->amount_ttc; + $name[$obj->rowid] = $obj->name.' '.$obj->firstname; + $catotal+=$obj->amount_ttc; + $i++; + } + } + else { + dolibarr_print_error($db); } } -print "
Cumul : ".price($catotal).""; -if ($catotal == 0) { $catotal = 1; }; +$i = 0; +print ""; +print ""; +print ""; +print ''; +print "\n"; +$var=true; - -$sql = "SELECT u.name, u.firstname, sum(f.total) as ca"; -$sql .= " FROM ".MAIN_DB_PREFIX."user as u,".MAIN_DB_PREFIX."facture as f"; -$sql .= " WHERE f.fk_statut = 1 AND f.fk_user_author = u.rowid"; -if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; -} -if ($socidp) +if (sizeof($amount)) { - $sql .= " AND f.fk_soc = $socidp"; -} -$sql .= " GROUP BY u.name, u.firstname ORDER BY ca DESC"; - -$result = $db->query($sql); -if ($result) -{ - $num = $db->num_rows(); - if ($num > 0) + foreach($amount as $key=>$value) { - $i = 0; - print "

".$langs->trans("User")."'.$langs->trans("AmountTTC").''.$langs->trans("Percentage").'
"; - print ""; - print ""; - print ''; - print "\n"; - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ""; - - print "\n"; - print ''; - print ''; - print "\n"; - $i++; - } - print "
UtilisateurMontantPourcentage
$objp->firstname $objp->name'.price($objp->ca).''.price(100 / $catotal * $objp->ca).'%
"; + $var=!$var; + print ""; + + $fullname=$name[$key]; + if ($key >= 0) { + $linkname=''.img_object($langs->trans("ShowUser"),'user').' '.$fullname.''; + } + else { + $linkname=$langs->trans("Paiements liés à aucune facture"); + } + print "".$linkname."\n"; + print ''.price($value).''; + print ''.($catotal > 0 ? price(100 / $catotal * $value).'%' : ' ').''; + print "\n"; + $i++; } - $db->free(); -} -else -{ - print $db->error(); + + // Total + print ''.$langs->trans("Total").''.$catotal.' '; + + $db->free($result); } +print ""; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); + +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index d26a1baf508..275f731dbbe 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004-2005 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 @@ -20,6 +20,13 @@ * $Source$ * */ + +/** + \file htdocs/compta/stats/cassoc.php + \brief Page reporting CA par société + \version $Revision$ +*/ + require("./pre.inc.php"); /* diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index a99dbec249e..e596db7a083 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -79,27 +79,21 @@ $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$ if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT sum(f.total) as amount, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; + $sql = "SELECT sum(f.total) as amount, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " WHERE f.fk_statut = 1"; - $sql .= " AND f.paye = 1"; } else { -/* $sql = "SELECT sum(f.total) as amount, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f "; - $sql .= "left join ".MAIN_DB_PREFIX."paiement as p "; - $sql .= "on f.rowid = p.fk_facture";*/ - $sql = "SELECT sum(p.amount) as amount, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p "; - $sql .= "left join ".MAIN_DB_PREFIX."facture as f "; - $sql .= "on f.rowid = p.fk_facture"; -} -if ($socidp) -{ - $sql .= " AND f.fk_soc = $socidp"; + /* + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) + */ + $sql = "SELECT sum(pf.amount) as amount, date_format(p.datep,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid"; } +if ($socidp) $sql .= " AND f.fk_soc = $socidp"; $sql .= " GROUP BY dm DESC"; - $result = $db->query($sql); if ($result) { @@ -122,6 +116,40 @@ else { dolibarr_print_error($db); } +// On ajoute les paiements anciennes version, non liés par paiement_facture +if ($modecompta != 'CREANCES-DETTES') { + $sql = "SELECT sum(p.amount) as amount, date_format(p.datep,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + $sql .= " GROUP BY dm"; + $sql .= " ORDER BY dm"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $cum[$obj->dm] += $obj->amount; + if ($obj->amount) + { + $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); + $maxyearmonth=max($maxyearmonth,$obj->dm); + } + $i++; + } + } + else { + dolibarr_print_error($db); + } +} + + + + + print ''; print ''; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 6b0f5c1b713..428b7783efe 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -136,6 +136,7 @@ AmountTTC=Amount TTC AmountVAT=Amount VAT AmountTotal=Total amount AmountAverage=Average amount +Percentage=Pourcentage Total=Total SubTotal=Subtotal TotalHT=Total HT diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index f6034dc9ead..acfc176b921 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -136,6 +136,7 @@ AmountTTC=Montant TTC AmountVAT=Montant TVA AmountTotal=Montant total AmountAverage=Montant moyen +Percentage=Pourcentage Total=Total SubTotal=Sous total TotalHT=Total HT
'.$langs->trans("Month").'