Corrections mauvais résultat du ca par utilisateur et support des 2 modes comptables.

This commit is contained in:
Laurent Destailleur 2005-05-06 00:21:33 +00:00
parent be04b07eb5
commit 0ace4b44f2
7 changed files with 234 additions and 109 deletions

View File

@ -80,30 +80,26 @@ print '<tr><td colspan="4">&nbsp;</td></tr>';
/* /*
* Factures clients * Factures clients
*/ */
print '<tr><td colspan="4">Facturation clients</td></tr>';
if ($modecompta == 'CREANCES-DETTES') { if ($modecompta == 'CREANCES-DETTES') {
$sql = "SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; $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 .= " 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"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1";
if ($year) { if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
$sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
} else { } else {
/* /*
* Liste des paiements par société (les anciens paiements ne sont pas inclus * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
* car n'était pas liés sur les vieilles versions) * 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 .= " 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"; $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp";
if ($year) { if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
$sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
} }
$sql .= " GROUP BY nom"; $sql .= " GROUP BY nom";
$sql .= " ORDER BY nom"; $sql .= " ORDER BY nom";
print '<tr><td colspan="4">Facturation clients</td></tr>';
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -130,15 +126,13 @@ if ($result) {
dolibarr_print_error($db); 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') { 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 .= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql .= " WHERE pf.rowid IS NULL"; $sql .= " WHERE pf.rowid IS NULL";
if ($year) { if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
$sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
$sql .= " GROUP BY nom"; $sql .= " GROUP BY nom";
$sql .= " ORDER BY nom"; $sql .= " ORDER BY nom";

View File

@ -84,18 +84,17 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $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"; $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut = 1";
} else { } 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"; * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f"; * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin)
$sql .= " ON f.rowid = p.fk_facture"; */
$sql .= " WHERE 1=1"; $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";
if ($socidp) $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid";
{
$sql .= " AND f.fk_soc = $socidp";
} }
if ($socidp) $sql .= " AND f.fk_soc = $socidp";
$sql .= " GROUP BY dm"; $sql .= " GROUP BY dm";
$sql .= " ORDER BY dm";
$result=$db->query($sql); $result=$db->query($sql);
if ($result) if ($result)
@ -115,6 +114,32 @@ else {
dolibarr_print_error($db); 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. * Frais, factures fournisseurs.

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,6 +20,13 @@
* $Source$ * $Source$
* *
*/ */
/**
\file htdocs/compta/stats/cabyuser.php
\brief Page reporting CA par utilisateur
\version $Revision$
*/
require("./pre.inc.php"); require("./pre.inc.php");
/* /*
@ -27,91 +34,153 @@ require("./pre.inc.php");
*/ */
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(); llxHeader();
print_titre("Chiffre d'affaire par utilisateur (euros HT)");
/* $html=new Form($db);
* Ca total
*
*/
$sql = "SELECT sum(f.total) as ca FROM ".MAIN_DB_PREFIX."facture as f"; // Affiche en-tête du rapport
$sql .= " WHERE f.fk_statut = 1"; if ($modecompta=="CREANCES-DETTES")
if ($conf->compta->mode != 'CREANCES-DETTES') {
$sql .= " AND f.paye = 1";
}
if ($socidp)
{ {
$sql .= " AND f.fk_soc = $socidp"; $nom="Chiffre d'affaire par utilisateur, auteur de la facture";
$nom.=' (Voir le rapport <a href="'.$_SERVER["PHP_SELF"].'?year='.($year).'&modecompta=RECETTES-DEPENSES">recettes-dépenses</a> pour n\'inclure que les factures effectivement payées)';
$period="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
$description=$langs->trans("RulesCADue");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
} }
$result = $db->query($sql); else {
if ($result) $nom="Chiffre d'affaire par utilisateur, auteur de la facture";
$nom.=' (Voir le rapport en <a href="'.$_SERVER["PHP_SELF"].'?year='.($year).'&modecompta=CREANCES-DETTES">créances-dettes</a> pour inclure les factures non encore payée)';
$period="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
$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')
{ {
if ($db->num_rows() > 0) $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";
$objp = $db->fetch_object($result); $sql .= " WHERE f.fk_statut = 1 AND f.fk_user_author = u.rowid";
$catotal = $objp->ca; if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
}
print "<br><b>Cumul : ".price($catotal)."</b>";
if ($catotal == 0) { $catotal = 1; };
$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)
{
$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)
{
$i = 0;
print "<p><table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print "<td>Utilisateur</td>";
print '<td align="right">Montant</TD><td align="right">Pourcentage</td>';
print "</tr>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
print "<td>$objp->firstname $objp->name</td>\n";
print '<td align="right">'.price($objp->ca).'</td>';
print '<td align="right">'.price(100 / $catotal * $objp->ca).'%</td>';
print "</tr>\n";
$i++;
}
print "</table>";
}
$db->free();
} }
else else
{ {
print $db->error(); /*
* 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)
{
$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);
}
// 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);
}
} }
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print "<td>".$langs->trans("User")."</td>";
print '<td align="right">'.$langs->trans("AmountTTC").'</td><td align="right">'.$langs->trans("Percentage").'</td>';
print "</tr>\n";
$var=true;
if (sizeof($amount))
{
foreach($amount as $key=>$value)
{
$var=!$var;
print "<tr $bc[$var]>";
$fullname=$name[$key];
if ($key >= 0) {
$linkname='<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$key.'">'.img_object($langs->trans("ShowUser"),'user').' '.$fullname.'</a>';
}
else {
$linkname=$langs->trans("Paiements liés à aucune facture");
}
print "<td>".$linkname."</td>\n";
print '<td align="right">'.price($value).'</td>';
print '<td align="right">'.($catotal > 0 ? price(100 / $catotal * $value).'%' : '&nbsp;').'</td>';
print "</tr>\n";
$i++;
}
// Total
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$catotal.'</td><td>&nbsp;</td></tr>';
$db->free($result);
}
print "</table>";
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,6 +20,13 @@
* $Source$ * $Source$
* *
*/ */
/**
\file htdocs/compta/stats/cassoc.php
\brief Page reporting CA par société
\version $Revision$
*/
require("./pre.inc.php"); require("./pre.inc.php");
/* /*

View File

@ -79,27 +79,21 @@ $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$
if ($modecompta == 'CREANCES-DETTES') { 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 .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.fk_statut = 1"; $sql .= " WHERE f.fk_statut = 1";
$sql .= " AND f.paye = 1";
} else { } else {
/* $sql = "SELECT sum(f.total) as amount, date_format(p.datep,'%Y-%m') as dm"; /*
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f "; * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
$sql .= "left join ".MAIN_DB_PREFIX."paiement as p "; * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin)
$sql .= "on f.rowid = p.fk_facture";*/ */
$sql = "SELECT sum(p.amount) as amount, date_format(p.datep,'%Y-%m') as dm"; $sql = "SELECT sum(pf.amount) as amount, date_format(p.datep,'%Y-%m') as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p "; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
$sql .= "left join ".MAIN_DB_PREFIX."facture as f "; $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid";
$sql .= "on f.rowid = p.fk_facture";
}
if ($socidp)
{
$sql .= " AND f.fk_soc = $socidp";
} }
if ($socidp) $sql .= " AND f.fk_soc = $socidp";
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
@ -122,6 +116,40 @@ else {
dolibarr_print_error($db); 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 '<table width="100%" class="noborder">'; print '<table width="100%" class="noborder">';
print '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>'; print '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>';

View File

@ -136,6 +136,7 @@ AmountTTC=Amount&nbsp;TTC
AmountVAT=Amount&nbsp;VAT AmountVAT=Amount&nbsp;VAT
AmountTotal=Total amount AmountTotal=Total amount
AmountAverage=Average amount AmountAverage=Average amount
Percentage=Pourcentage
Total=Total Total=Total
SubTotal=Subtotal SubTotal=Subtotal
TotalHT=Total HT TotalHT=Total HT

View File

@ -136,6 +136,7 @@ AmountTTC=Montant&nbsp;TTC
AmountVAT=Montant&nbsp;TVA AmountVAT=Montant&nbsp;TVA
AmountTotal=Montant total AmountTotal=Montant total
AmountAverage=Montant moyen AmountAverage=Montant moyen
Percentage=Pourcentage
Total=Total Total=Total
SubTotal=Sous total SubTotal=Sous total
TotalHT=Total HT TotalHT=Total HT