[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/compta/stats/ -> comp.php (source)

   1  <?php
   2  /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004      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: comp.php,v 1.29 2005/11/30 16:39:20 hregis Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/stats/comp.php,v $
  21   *
  22   */
  23  require ("./pre.inc.php");
  24  require ("./lib.inc.php");
  25  
  26  
  27  function propals ($db, $year, $month) {
  28    global $bc,$langs;
  29    $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
  30    $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
  31    $sql .= " AND c.id in (1,2,4)";
  32    $sql .= " AND date_format(p.datep, '%Y') = $year ";
  33    $sql .= " AND round(date_format(p.datep, '%m')) = $month ";
  34  
  35  
  36    $sql .= " ORDER BY p.fk_statut";
  37  
  38    $result = $db->query($sql);
  39    $num = $db->num_rows();
  40    $i = 0;
  41    print "<table class=\"noborder\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
  42    print "<tr class=\"liste_titre\"><td colspan=\"5\"><b>Propal</b></td></tr>";
  43  
  44    $oldstatut = -1;
  45    $subtotal = 0;
  46    while ($i < $num) {
  47      $objp = $db->fetch_object($result);
  48  
  49      if ($objp->statut <> $oldstatut ) {
  50        $oldstatut = $objp->statut;
  51        
  52        if ($i > 0) {
  53      print "<tr><td align=\"right\" colspan=\"4\">".$langs->trans("Total").": <b>".price($subtotal)."</b></td>\n";
  54      print "<td align=\"left\">".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
  55        }
  56        $subtotal = 0;
  57  
  58        print "<tr class=\"liste_titre\">";
  59        print "<td>Societe</td>";
  60        print "<td>".$langs->trans("Ref")."</td>";
  61        print "<td align=\"right\">Date</td>";
  62        print "<td align=\"right\">".$langs->trans("Price")."</td>";
  63        print "<td align=\"center\">".$langs->trans("Status")."</td>";
  64        print "</tr>\n";
  65        $var=True;
  66      }
  67    
  68      $var=!$var;
  69      print "<tr $bc[$var]>";
  70      
  71      print "<td><a href=\"comp.php?socidp=$objp->idp\">$objp->nom</a></td>\n";
  72      
  73      print "<td><a href=\"../../comm/propal.php?propalid=$objp->propalid\">$objp->ref</a></td>\n";
  74      
  75      print "<td align=\"right\">".dolibarr_print_date($objp->dp)."</td>\n";
  76      
  77      print "<td align=\"right\">".price($objp->price)."</td>\n";
  78      print "<td align=\"center\">$objp->statut</td>\n";
  79      print "</tr>\n";
  80      
  81      $total = $total + $objp->price;
  82      $subtotal = $subtotal + $objp->price;
  83      
  84      $i++;
  85    }
  86    print "<tr><td align=\"right\" colspan=\"4\">".$langs->trans("Total").": <b>".price($subtotal)."</b></td>\n";
  87    print "<td align=\"left\">".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
  88    print "<tr>";
  89    print "<td colspan=\"3\" align=\"right\"><b>".$langs->trans("Total").": ".price($total)."</b></td>";
  90    print "<td align=\"left\"><b>".$langs->trans("Currency".$conf->monnaie)."</b></td></tr>";
  91    print "</table>";
  92    $db->free();
  93  
  94  }
  95  
  96  
  97  function factures ($db, $year, $month, $paye) {
  98    global $bc,$conf;
  99  
 100    $sql = "SELECT s.nom, s.idp, f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid ";
 101    $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
 102    $sql .= " WHERE f.fk_statut = 1";
 103    if ($conf->compta->mode != 'CREANCES-DETTES') { 
 104      $sql .= " AND f.paye = $paye";
 105    }
 106    $sql .= " AND f.fk_soc = s.idp";
 107    $sql .= " AND date_format(f.datef, '%Y') = $year ";
 108    $sql .= " AND round(date_format(f.datef, '%m')) = $month ";
 109    $sql .= " ORDER BY f.datef DESC ";
 110  
 111    $result = $db->query($sql);
 112    if ($result)
 113      {
 114        $num = $db->num_rows();
 115        if ($num > 0)
 116      {
 117        $i = 0;
 118        print "<table class=\"noborder\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">";
 119        print "<tr class=\"liste_titre\"><td colspan=\"5\"><b>Factures</b></td></tr>";
 120        print "<tr class=\"liste_titre\">";
 121        print "<td>Societe</td>";
 122        print "<td>Num</td>";
 123        print "<td align=\"right\">Date</td>";
 124        print "<td align=\"right\">Montant</td>";
 125        print "<td align=\"right\">Payé</td>";
 126        print "</tr>\n";
 127        $var=True;
 128        while ($i < $num)
 129          {
 130            $objp = $db->fetch_object($result);
 131            $var=!$var;
 132            print "<tr $bc[$var]>";
 133            print "<td><a href=\"comp.php?socidp=$objp->idp\">$objp->nom</a></td>\n";
 134            print "<td><a href=\"../facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n";
 135            if ($objp->df > 0 )
 136          {
 137            print "<td align=\"right\">".dolibarr_print_date($objp->df)."</td>\n";
 138          }
 139            else
 140          {
 141            print "<td align=\"right\"><b>!!!</b></td>\n";
 142          }
 143            
 144            print "<td align=\"right\">".price($objp->total)."</td>\n";
 145            
 146            $payes[1] = "oui";
 147            $payes[0] = "<b>non</b>";
 148                      
 149            print "<td align=\"right\">".$payes[$objp->paye]."</td>\n";
 150            print "</tr>\n";
 151            
 152            $total = $total + $objp->total;
 153            
 154            $i++;
 155          }
 156        print "<tr><td colspan=\"4\" align=\"right\">";
 157        print "<b>Total : ".price($total)."</b></td><td></td></tr>";
 158        print "</table>";
 159        $db->free();
 160      }
 161      }
 162    else
 163      {
 164        print $db->error();
 165      }
 166  }
 167  
 168  
 169  function pt ($db, $sql, $year) {
 170    global $bc, $langs;
 171  
 172    $result = $db->query($sql);
 173    if ($result) {
 174      $num = $db->num_rows();
 175      $i = 0; $total = 0 ;
 176      print '<table class="border" width="100%" cellspacing="0" cellpadding="3">';
 177      print "<tr class=\"liste_titre\">";
 178      print '<td>'.$langs->trans("Month").'</td>';
 179      print "<td align=\"right\">Montant</td></tr>\n";
 180      $var=True;
 181      $month = 1 ;
 182  
 183      while ($i < $num) {
 184        $obj = $db->fetch_object($result);
 185        $var=!$var;
 186  
 187        if ($obj->dm > $month ) {
 188      for ($b = $month ; $b < $obj->dm ; $b++) {
 189        print "<tr $bc[$var]>";
 190        print "<td>".strftime("%B",mktime(12,0,0,$b, 1, $year))."</td>\n";
 191        print "<td align=\"right\">0</td>\n";      
 192        print "</tr>\n";
 193        $var=!$var;
 194        $ca[$b] = 0;
 195      }
 196        }
 197  
 198        if ($obj->sum > 0) {
 199      print "<tr $bc[$var]>";
 200      print "<td><a href=\"comp.php?details=1&year=$year&month=$obj->dm\">";
 201      print strftime("%B",mktime(12,0,0,$obj->dm, 1, $year))."</td>\n";
 202      print "<td align=\"right\">".price($obj->sum)."</td>\n";
 203      
 204      print "</TR>\n";
 205      $month = $obj->dm + 1;
 206      $ca[$obj->dm] = $obj->sum;
 207      $total = $total + $obj->sum;
 208        }
 209        $i++;
 210      }
 211  
 212      if ($num) {
 213        $beg = $obj->dm;
 214      } else {
 215        $beg = 0 ;
 216      }
 217  
 218      if ($beg <= 12 ) {
 219        for ($b = $beg + 1 ; $b < 13 ; $b++) {
 220      $var=!$var;
 221      print "<tr $bc[$var]>";
 222      print "<td>".strftime("%B",mktime(12,0,0,$b, 1, $year))."</td>\n";
 223      print "<td align=\"right\">0</td>\n";      
 224      print "</tr>\n";
 225      $ca[$b] = 0;
 226        }
 227      }
 228  
 229      print "<tr class=\"total\"><td align=\"right\">Total :</td><td align=\"right\"><b>".price($total)."</b></td></tr>";    
 230      print "</table>";
 231  
 232      $db->free();
 233      return $ca;
 234    } else {
 235      print $db->error();
 236    }
 237  }
 238  
 239  function ppt ($db, $year, $socidp)
 240  {
 241    global $bc,$conf,$langs;
 242    print "<table width=\"100%\">";
 243  
 244    print '<tr class="liste_titre"><td align="center" valign="top" width="30%">';
 245    print "CA Prévisionnel basé sur les propal $year";
 246    
 247    print "</td><td align=\"center\" valign=\"top\">CA Réalisé $year</td>";
 248    print "<td align=\"center\" valign=\"top\">Delta $year</td></tr>";
 249    
 250    print '<tr><td valign="top" align="center" width="30%">';
 251    
 252    $sql = "SELECT sum(f.price) as sum, round(date_format(f.datep,'%m')) as dm";
 253    $sql .= " FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in (1,2,4) AND date_format(f.datep,'%Y') = $year ";
 254  
 255    if ($socidp)
 256      {
 257        $sql .= " AND f.fk_soc = $socidp";
 258      }
 259  
 260    $sql .= " GROUP BY dm";
 261    
 262    $prev = pt($db, $sql, $year);
 263    
 264    print "</td><td valign=\"top\" width=\"30%\">";
 265    
 266    $sql = "SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm";
 267    $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
 268    $sql .= " WHERE f.fk_statut = 1";
 269    if ($conf->compta->mode != 'CREANCES-DETTES') { 
 270      $sql .= " AND f.paye = 1";
 271    }
 272    $sql .= " AND date_format(f.datef,'%Y') = $year ";
 273    if ($socidp)
 274      {
 275        $sql .= " AND f.fk_soc = $socidp";
 276      }
 277    $sql .= " GROUP BY dm";
 278    
 279    $ca = pt($db, $sql, $year);
 280    
 281    print "</td><td valign=\"top\" width=\"30%\">";
 282    
 283    print '<table class="border" width="100%" cellspacing="0" cellpadding="3">';
 284    print "<tr class=\"liste_titre\">";
 285    print '<td>'.$langs->trans("Month").'</td>';
 286    print '<td align="right">'.$langs->trans("Amount").'</td>';
 287    print "</tr>\n";
 288  
 289    $var = 1 ;
 290    for ($b = 1 ; $b <= 12 ; $b++)
 291      {
 292        $var=!$var;
 293  
 294        $delta = $ca[$b] - $prev[$b];
 295        $deltat = $deltat + $delta ;
 296        print "<tr $bc[$var]>";
 297        print "<td>".strftime("%B",mktime(12,0,0,$b, 1, $year))."</td>\n";
 298        print "<td align=\"right\">".price($delta)."</td>\n";      
 299        print "</tr>\n";
 300      }
 301    
 302    $ayear = $year - 1;
 303    $acat = get_ca($db, $ayear, $socidp) - get_ca_propal($db, $ayear, $socidp);
 304  
 305  
 306    print "<tr class=\"total\"><td align=\"right\">Total :</td><td align=\"right\">".price($deltat)."</td></tr>";
 307    print "<tr class=\"total\"><td align=\"right\">Rappel $ayear :</td><td align=\"right\">".price($acat)."</td></tr>";
 308    print "<tr class=\"total\"><td align=\"right\">Soit :</td><td align=\"right\"><b>".price($acat+$deltat)."</b></td></tr>";
 309  
 310    print "</table>";
 311    print "</td></tr></table>";
 312  
 313  }
 314  
 315  
 316  /*
 317   *
 318   */
 319  
 320  llxHeader();
 321  
 322  /*
 323   * Sécurité accés client
 324   */
 325  if ($user->societe_id > 0) 
 326  {
 327    $socidp = $user->societe_id;
 328  }
 329  
 330  $cyear = isset($_GET["year"])?$_GET["year"]:0;
 331  if (! $cyear) { $cyear = strftime ("%Y", time()); }
 332  
 333  print_fiche_titre("Chiffre d'Affaire transformé (prévu-réalisé)",($cyear?"<a href='comp.php?year=".($cyear-1)."'>".img_previous()."</a> Année $cyear <a href='comp.php?year=".($cyear+1)."'>".img_next()."</a>":""));
 334  
 335  ppt($db, $cyear, $socidp);
 336  
 337  if ($details == 1)
 338  {
 339    print "<TABLE border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"50%\">";
 340    factures ($db, $year, $month, 1);
 341    print "</td><td valign=\"top\" width=\"50%\">";
 342    propals ($db, $year, $month);
 343    print "</td></tr></table>";
 344  }
 345  $db->close();
 346  
 347  
 348  llxFooter("<em>Derni&egrave;re modification $Date: 2005/11/30 16:39:20 $ r&eacute;vision $Revision: 1.29 $</em>");
 349  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics