[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: index.php,v 1.27 2005/06/11 11:58:53 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/stats/index.php,v $ 21 * 22 */ 23 24 /** 25 \file htdocs/compta/stats/index.php 26 \brief Page reporting CA 27 \version $Revision: 1.27 $ 28 */ 29 30 require ("./pre.inc.php"); 31 32 $year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"]; 33 $year_current = strftime("%Y",time()); 34 if (! $year_start) { 35 $year_start = $year_current - 4; 36 $year_end = $year_current; 37 } 38 else { 39 $year_end=$year_start + 4; 40 } 41 42 /* 43 * Sécurité accés client 44 */ 45 if ($user->societe_id > 0) 46 { 47 $socidp = $user->societe_id; 48 } 49 50 $modecompta = $conf->compta->mode; 51 if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; 52 53 54 55 llxHeader(); 56 57 58 $html=new Form($db); 59 60 // Affiche en-tête du rapport 61 if ($modecompta=="CREANCES-DETTES") 62 { 63 $nom="Chiffre d'affaire"; 64 $nom.=' (Voir le rapport <a href="index.php?year_start='.($year_start).'&modecompta=RECETTES-DEPENSES">recettes-dépenses</a> pour n\'inclure que les factures effectivement payées)'; 65 $period="$year_start - $year_end"; 66 $periodlink=($year_start?"<a href='index.php?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='index.php?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":""); 67 $description=$langs->trans("RulesCADue"); 68 $builddate=time(); 69 $exportlink=$langs->trans("NotYetAvailable"); 70 } 71 else { 72 $nom="Chiffre d'affaire"; 73 $nom.=' (Voir le rapport en <a href="index.php?year_start='.($year_start).'&modecompta=CREANCES-DETTES">créances-dettes</a> pour inclure les factures non encore payée)'; 74 $period="$year_start - $year_end"; 75 $periodlink=($year_start?"<a href='index.php?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='index.php?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":""); 76 $description=$langs->trans("RulesCAIn"); 77 $builddate=time(); 78 $exportlink=$langs->trans("NotYetAvailable"); 79 } 80 $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); 81 82 83 if ($modecompta == 'CREANCES-DETTES') { 84 $sql = "SELECT sum(f.total) as amount, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; 85 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; 86 $sql .= " WHERE f.fk_statut = 1"; 87 } else { 88 /* 89 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les 90 * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) 91 */ 92 $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; 93 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; 94 $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid"; 95 } 96 if ($socidp) $sql .= " AND f.fk_soc = $socidp"; 97 $sql .= " GROUP BY dm DESC"; 98 99 $result = $db->query($sql); 100 if ($result) 101 { 102 $num = $db->num_rows($result); 103 $i = 0; 104 while ($i < $num) 105 { 106 $obj = $db->fetch_object($result); 107 $cum[$obj->dm] = $obj->amount_ttc; 108 if ($obj->amount_ttc) 109 { 110 $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); 111 $maxyearmonth=max($maxyearmonth,$obj->dm); 112 } 113 $i++; 114 } 115 $db->free($result); 116 } 117 else { 118 dolibarr_print_error($db); 119 } 120 121 // On ajoute les paiements anciennes version, non liés par paiement_facture 122 if ($modecompta != 'CREANCES-DETTES') { 123 $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; 124 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; 125 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; 126 $sql .= " WHERE pf.rowid IS NULL"; 127 $sql .= " GROUP BY dm"; 128 $sql .= " ORDER BY dm"; 129 130 $result = $db->query($sql); 131 if ($result) { 132 $num = $db->num_rows($result); 133 $i = 0; 134 while ($i < $num) 135 { 136 $obj = $db->fetch_object($result); 137 $cum[$obj->dm] += $obj->amount_ttc; 138 if ($obj->amount_ttc) 139 { 140 $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); 141 $maxyearmonth=max($maxyearmonth,$obj->dm); 142 } 143 $i++; 144 } 145 } 146 else { 147 dolibarr_print_error($db); 148 } 149 } 150 151 152 153 154 155 print '<table width="100%" class="noborder">'; 156 print '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>'; 157 158 for ($annee = $year_start ; $annee <= $year_end ; $annee++) 159 { 160 print '<td align="center" width="10%" colspan="2"><a href="casoc.php?year='.$annee.'">'.$annee.'</a></td>'; 161 if ($annee != $year_end) print '<td width="15"> </td>'; 162 } 163 print '</tr>'; 164 165 print '<tr class="liste_titre">'; 166 for ($annee = $year_start ; $annee <= $year_end ; $annee++) 167 { 168 print '<td align="right">'.$langs->trans("AmountTTC").'</td>'; 169 print '<td align="right">'.$langs->trans("Delta").'</td>'; 170 if ($annee != $year_end) print '<td width="15"> </td>'; 171 } 172 print '</tr>'; 173 174 175 $total_CA=0; 176 $now_show_delta=0; 177 $minyear=substr($minyearmonth,0,4); 178 $maxyear=substr($maxyearmonth,0,4); 179 $nowyear=strftime("%Y",mktime()); 180 $nowyearmonth=strftime("%Y-%m",mktime()); 181 182 for ($mois = 1 ; $mois < 13 ; $mois++) 183 { 184 $var=!$var; 185 print "<tr $bc[$var]>"; 186 187 print "<td>".strftime("%B",mktime(1,1,1,$mois,1,2000))."</td>"; 188 for ($annee = $year_start ; $annee <= $year_end ; $annee++) 189 { 190 $casenow = strftime("%Y-%m",mktime()); 191 $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); 192 $caseprev = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee-1)); 193 194 if ($annee == $year_current) { 195 $total_CA += $cum[$case]; 196 } 197 198 // Valeur CA du mois 199 print '<td align="right">'; 200 if ($cum[$case]) 201 { 202 $now_show_delta=1; // On a trouvé le premier mois de la première année générant du chiffre. 203 print price($cum[$case],1); 204 } 205 else 206 { 207 if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; } 208 else { print ' '; } 209 } 210 print "</td>"; 211 212 // Pourcentage du mois 213 if ($annee > $minyear && $case <= $casenow) { 214 if ($cum[$caseprev] && $cum[$case]) 215 { 216 $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); 217 //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; 218 print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>'; 219 220 } 221 if ($cum[$caseprev] && ! $cum[$case]) 222 { 223 print '<td align="right">-100%</td>'; 224 } 225 if (! $cum[$caseprev] && $cum[$case]) 226 { 227 print '<td align="right">+Inf%</td>'; 228 } 229 if (! $cum[$caseprev] && ! $cum[$case]) 230 { 231 print '<td align="right">+0%</td>'; 232 } 233 } 234 else 235 { 236 print '<td align="right">'; 237 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } 238 else { print ' '; } 239 print '</td>'; 240 } 241 242 $total[$annee]+=$cum[$case]; 243 if ($annee != $year_end) print '<td width="15"> </td>'; 244 } 245 246 print '</tr>'; 247 } 248 249 // Affiche total 250 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>'; 251 for ($annee = $year_start ; $annee <= $year_end ; $annee++) 252 { 253 // Montant total 254 if ($annee >= $minyear && $annee <= max($nowyear,$maxyear)) 255 { 256 print "<td align=\"right\" nowrap>".($total[$annee]?price($total[$annee]):"0")."</td>"; 257 } 258 else 259 { 260 print '<td> </td>'; 261 } 262 263 // Pourcentage total 264 if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) { 265 if ($total[$annee-1] && $total[$annee]) { 266 $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); 267 print '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>'; 268 } 269 if ($total[$annee-1] && ! $total[$annee]) 270 { 271 print '<td align="right">-100%</td>'; 272 } 273 if (! $total[$annee-1] && $total[$annee]) 274 { 275 print '<td align="right">+Inf%</td>'; 276 } 277 if (! $total[$annee-1] && ! $total[$annee]) 278 { 279 print '<td align="right">+0%</td>'; 280 } 281 } 282 else 283 { 284 print '<td align="right">'; 285 if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; } 286 else { print ' '; } 287 print '</td>'; 288 } 289 290 if ($annee != $year_end) print '<td width="15"> </td>'; 291 } 292 print "</tr>\n"; 293 print "</table>"; 294 295 296 /* 297 * En mode recettes/dépenses, on complète avec les montants facturés non réglés 298 * et les propales signées mais pas facturées. En effet, en recettes-dépenses, 299 * on comptabilise lorsque le montant est sur le compte donc il est intéressant 300 * d'avoir une vision de ce qui va arriver. 301 */ 302 303 /* 304 Je commente toute cette partie car les chiffres affichées sont faux - Eldy. 305 En attendant correction. 306 307 if ($modecompta != 'CREANCES-DETTES') 308 { 309 310 print '<br><table width="100%" class="noborder">'; 311 312 // Factures non réglées 313 // \todo Y a bug ici. Il faut prendre le reste à payer et non le total des factures non réglèes ! 314 315 $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc, sum(pf.amount) as am"; 316 $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"; 317 $sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; 318 if ($socidp) 319 { 320 $sql .= " AND f.fk_soc = $socidp"; 321 } 322 $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.idp, f.total_ttc"; 323 324 if ( $db->query($sql) ) 325 { 326 $num = $db->num_rows(); 327 $i = 0; 328 329 if ($num) 330 { 331 $var = True; 332 $total_ttc_Rac = $totalam_Rac = $total_Rac = 0; 333 while ($i < $num) 334 { 335 $obj = $db->fetch_object(); 336 $total_ttc_Rac += $obj->total_ttc; 337 $totalam_Rac += $obj->am; 338 $i++; 339 } 340 $var=!$var; 341 print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Facturé à encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja réglé des factures partiellement réglées</td></tr>"; 342 $total_CA +=$total_ttc_Rac; 343 } 344 $db->free(); 345 } 346 else 347 { 348 dolibarr_print_error($db); 349 } 350 */ 351 352 /* 353 * 354 * Propales signées, et non facturées 355 * 356 */ 357 358 /* 359 Je commente toute cette partie car les chiffres affichées sont faux - Eldy. 360 En attendant correction. 361 362 $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 363 FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s 364 LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid 365 LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid 366 WHERE p.fk_soc = s.idp 367 AND p.fk_statut >=1 368 AND p.facture =0"; 369 if ($socidp) 370 { 371 $sql .= " AND f.fk_soc = $socidp"; 372 } 373 $sql .= " GROUP BY p.rowid"; 374 375 if ( $db->query($sql) ) 376 { 377 $num = $db->num_rows(); 378 $i = 0; 379 380 if ($num) 381 { 382 $var = True; 383 $total_pr = 0; 384 while ($i < $num) 385 { 386 $obj = $db->fetch_object(); 387 $total_pr += $obj->total_ttc-$obj->tot_fttc; 388 $i++; 389 } 390 $var=!$var; 391 print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Signé et non facturé:</i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le déjà facturé</td></tr>"; 392 $total_CA += $total_pr; 393 } 394 $db->free(); 395 } 396 else 397 { 398 dolibarr_print_error($db); 399 } 400 print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Total CA prévisionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 précédents</td></tr>"; 401 } 402 print "</table>"; 403 404 */ 405 406 $db->close(); 407 408 llxFooter('$Date: 2005/06/11 11:58:53 $ - $Revision: 1.27 $'); 409 410 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |