Corrections mauvais rsultat du ca par socit et support des 2 modes comptables.
This commit is contained in:
parent
206a3ba78c
commit
c2efaf2cb8
@ -52,16 +52,16 @@ $html=new Form($db);
|
||||
if ($modecompta=="CREANCES-DETTES")
|
||||
{
|
||||
$nom="Bilan des recettes et dépenses, détail";
|
||||
$nom.=' (Voir le rapport en <a href="clientfourn.php?year='.$year.'&modecompta=RECETTES-DEPENSES">recettes-dépenses</a> pour n\'inclure que les factures effectivement payées)';
|
||||
$period="<a href='clientfourn.php?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='clientfourn.php?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
|
||||
$nom.=' (Voir le rapport en <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("RulesResultDue");
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
}
|
||||
else {
|
||||
$nom="Bilan des recettes et dépenses, détail";
|
||||
$nom.=' (Voir le rapport en <a href="clientfourn.php?year='.$year.'&modecompta=CREANCES-DETTES">créances-dettes</a> pour inclure les factures non encore payée)';
|
||||
$period="<a href='clientfourn.php?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> ".$langs->trans("Year")." $year <a href='clientfourn.php?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
|
||||
$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("RulesResultInOut");
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
|
||||
@ -29,6 +29,16 @@
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
$year=$_GET["year"];
|
||||
if (! $year) { $year = strftime("%Y", time()); }
|
||||
$modecompta = $conf->compta->mode;
|
||||
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
|
||||
|
||||
$sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
|
||||
$sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
|
||||
if (! $sortorder) $sortorder="desc";
|
||||
if (! $sortfield) $sortfield="amount_ttc";
|
||||
|
||||
/*
|
||||
* Sécurité accés client
|
||||
*/
|
||||
@ -36,94 +46,167 @@ if ($user->societe_id > 0)
|
||||
{
|
||||
$socidp = $user->societe_id;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
llxHeader();
|
||||
|
||||
print_titre("Chiffre d'affaire par société (euros HT)");
|
||||
$html=new Form($db);
|
||||
|
||||
/*
|
||||
* Ca total
|
||||
*
|
||||
*/
|
||||
|
||||
$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 de rapport
|
||||
if ($modecompta=="CREANCES-DETTES")
|
||||
{
|
||||
$sql .= " AND f.fk_soc = $socidp";
|
||||
$nom="Chiffre d'affaire par société";
|
||||
$nom.=' (Voir le rapport en <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");
|
||||
}
|
||||
else {
|
||||
$nom="Chiffre d'affaire par société";
|
||||
$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')
|
||||
{
|
||||
$sql = "SELECT s.idp as rowid, s.nom as name, sum(f.total) as amount, 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_statut = 1 AND f.fk_soc = s.idp";
|
||||
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 s.idp as rowid, s.nom as name, 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 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'";
|
||||
}
|
||||
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;
|
||||
$catotal+=$obj->amount_ttc;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
print $db->error() . "<br>" . $sql;
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print "<br><b>Cumul : ".price($catotal)."</b>";
|
||||
|
||||
if ($catotal == 0) { $catotal = 1; };
|
||||
|
||||
|
||||
$sql = "SELECT s.nom, s.idp, sum(f.total) as ca";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " WHERE f.fk_statut = 1 AND f.fk_soc = s.idp";
|
||||
if ($conf->compta->mode != 'CREANCES-DETTES') {
|
||||
$sql .= " AND f.paye = 1";
|
||||
}
|
||||
if ($socidp)
|
||||
// On ajoute les paiements anciennes version, non liés par paiement_facture
|
||||
if ($modecompta != 'CREANCES-DETTES')
|
||||
{
|
||||
$sql .= " AND f.fk_soc = $socidp";
|
||||
}
|
||||
$sql .= " GROUP BY s.nom, s.idp ORDER BY ca DESC";
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows();
|
||||
if ($num > 0)
|
||||
$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'";
|
||||
$sql .= " GROUP BY nom";
|
||||
$sql .= " ORDER BY nom";
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$i = 0;
|
||||
print "<p><table class=\"noborder\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print "<td>Société</td>";
|
||||
print '<td align="right">Montant</TD><td align="right">Pourcentage</td>';
|
||||
print "<td> </td></tr>\n";
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
print "<td><a href=\"../fiche.php?socid=$objp->idp\">$objp->nom</a></td>\n";
|
||||
print '<td align="right">'.price($objp->ca).'</td>';
|
||||
print '<td align="right">'.price(100 / $catotal * $objp->ca).'%</td>';
|
||||
print "<td align=\"center\"><a href=\"../facture.php?socidp=$objp->idp\">Voir les factures</a></td>\n";
|
||||
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
print "</table>";
|
||||
$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;
|
||||
$catotal+=$obj->amount_ttc;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
$db->free();
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
$i = 0;
|
||||
print "<table class=\"noborder\" width=\"100%\">";
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"nom","",'&year='.($year).'&modecompta='.$modecompta,"",$sortfield);
|
||||
print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"amount_ttc","",'&year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield);
|
||||
print_liste_field_titre($langs->trans("Percentage"),$_SERVER["PHP_SELF"],"amount_ttc","",'&year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield);
|
||||
print "</tr>\n";
|
||||
$var=true;
|
||||
|
||||
if (sizeof($amount))
|
||||
{
|
||||
print $db->error();
|
||||
$arrayforsort=$name;
|
||||
|
||||
// On définit tableau arrayforsort
|
||||
if ($sortfield == 'nom' && $sortorder == 'asc') {
|
||||
asort($name);
|
||||
$arrayforsort=$name;
|
||||
}
|
||||
if ($sortfield == 'nom' && $sortorder == 'desc') {
|
||||
arsort($name);
|
||||
$arrayforsort=$name;
|
||||
}
|
||||
if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
|
||||
asort($amount);
|
||||
$arrayforsort=$amount;
|
||||
}
|
||||
if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
|
||||
arsort($amount);
|
||||
$arrayforsort=$amount;
|
||||
}
|
||||
|
||||
foreach($arrayforsort as $key=>$value)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
$fullname=$name[$key];
|
||||
if ($key > 0) {
|
||||
$linkname='<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$key.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$fullname.'</a>';
|
||||
}
|
||||
else {
|
||||
$linkname=$langs->trans("Autres paiements liés à aucune facture, donc aucune société");
|
||||
}
|
||||
print "<td>".$linkname."</td>\n";
|
||||
print '<td align="right">'.price($amount[$key]).'</td>';
|
||||
print '<td align="right">'.($catotal > 0 ? price(100 / $catotal * $amount[$key]).'%' : ' ').'</td>';
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Total
|
||||
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$catotal.'</td><td> </td></tr>';
|
||||
|
||||
$db->free($result);
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
|
||||
$db->close();
|
||||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user