From d3bd0ed5320e04264a36db713d5d2dc6e152848b Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 15 Mar 2005 09:24:03 +0000 Subject: [PATCH] =?UTF-8?q?Tableau=20de=20bord=20pour=20les=20entit=E9s=20?= =?UTF-8?q?en=20mode=20"recettes-d=E9penses"=20(les=20ind=E9pendants=20com?= =?UTF-8?q?me=20moi,=20ne=20concerne=20pas=20les=20SARL)=20:=20*=20le=20mo?= =?UTF-8?q?ntant=20apparaissant=20dans=20le=20tableau=20de=20synth=E8se=20?= =?UTF-8?q?mensuel=20est=20le=20montant=20en=20fonction=20de=20la=20date?= =?UTF-8?q?=20d'encaissement.=20*=203=20lignes=20ont=20=E9t=E9=20rajout=E9?= =?UTF-8?q?es=20:=20le=20"factur=E9=20=E0=20encaisser",=20le=20"sign=E9",?= =?UTF-8?q?=20et=20la=20somme=20des=203=20(encaiss=E9,=20factur=E9,=20sign?= =?UTF-8?q?=E9).=20Cela=20permet=20d'avoir=20une=20meilleure=20visibilit?= =?UTF-8?q?=E9=20sur=20sa=20comptabilit=E9=20et=20sa=20tr=E9sorerie.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Par exemple, actuellement, j'ai peu encaissé, mais plus de 10 000E facturé à encaisser et une somme rondellette de "signé". Ce tableau ne prend pas en compte les propales non signées, bien entendu. --- htdocs/compta/stats/index.php | 127 +++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 44b9266f5e5..f30ea664840 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -53,19 +53,32 @@ if ($user->societe_id > 0) $mode='recettes'; if ($conf->compta->mode == 'CREANCES-DETTES') { $mode='creances'; } - -$title="Chiffre d'affaire (".$conf->monnaie." HT, ".$mode.")"; +if ($mode=='creances') { + $title="Chiffre d'affaire (".$conf->monnaie." HT, ".$mode.")"; +} else { + $title="Chiffre d'affaire (".$conf->monnaie." TTC, ".$mode.")"; +} $lien=($year_start?"".img_previous()." ".img_next()."":""); print_fiche_titre($title,$lien); 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 = 1"; -if ($conf->compta->mode != 'CREANCES-DETTES') { +if ($conf->compta->mode == 'CREANCES-DETTES') { + $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 = 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"; @@ -101,7 +114,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) print 'Delta'; } print ''; - +$total_CA=0; for ($mois = 1 ; $mois < 13 ; $mois++) { $var=!$var; @@ -114,7 +127,9 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); $caseprev = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee-1)); - + if ($annee == $year_current) { + $total_CA += $cum[$case]; + } // Valeur CA print ''; @@ -162,7 +177,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) print "".$langs->trans("Total")." :"; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print "".($total[$annee]?$total[$annee]:" ").""; + print "".($total[$annee]?price($total[$annee]):" ").""; // Pourcentage evol if ($total[$annee-1]) { @@ -193,8 +208,100 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) } print "\n"; -print ""; +/* en mode recettes/dépenses, il faut compléter avec les montants facturés non réglés +* et les propales signées mais pas facturées +* en effet, en recettes-dépenses, on comptabilise lorsque le montant est sur le compte +* donc il est intéressant d'avoir une vision de ce qui va arriver +*/ +if ($conf->compta->mode != 'CREANCES-DETTES') { +/* +* +* Facture non réglées +* +*/ + $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc, sum(pf.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; + $sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; + if ($socidp) + { + $sql .= " AND f.fk_soc = $socidp"; + } + $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.idp, f.total_ttc"; + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + + if ($num) + { + $var = True; + $total_ttc_Rac = $totalam_Rac = $total_Rac = 0; + while ($i < $num) + { + $obj = $db->fetch_object(); + $total_ttc_Rac += $obj->total_ttc; + $totalam_Rac += $obj->am; + $i++; + } + $var=!$var; + print "Facturé à encaisser : ".price($total_ttc_Rac)." "; + $total_CA +=$total_ttc_Rac; + } + $db->free(); + } + else + { + dolibarr_print_error($db); + } + +/* +* +* Propales signées, et non facturées +* +*/ + $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.idp, p.total_ht, p.total_ttc + FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s + LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid + LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid + WHERE p.fk_soc = s.idp + AND p.fk_statut >=1 + AND p.facture =0"; + if ($socidp) + { + $sql .= " AND f.fk_soc = $socidp"; + } + $sql .= " GROUP BY p.rowid"; + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + + if ($num) + { + $var = True; + $total_pr = 0; + while ($i < $num) + { + $obj = $db->fetch_object(); + $total_pr += $obj->total_ttc-$obj->tot_fttc; + $i++; + } + $var=!$var; + print "Signé : ".price($total_pr)." "; + $total_CA += $total_pr; + } + $db->free(); + } + else + { + dolibarr_print_error($db); + } + print "Total CA prévisionnel : ".price($total_CA)." "; +} +print ""; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$");