[ 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/ -> cabyuser.php (source)

   1  <?php
   2  /* Copyright (C) 2001-2003 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: cabyuser.php,v 1.13 2005/09/05 19:27:58 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/stats/cabyuser.php,v $
  21   */
  22  
  23  /**
  24          \file        htdocs/compta/stats/cabyuser.php
  25          \brief       Page reporting CA par utilisateur
  26          \version     $Revision: 1.13 $
  27  */
  28  
  29  require ("./pre.inc.php");
  30  
  31  
  32  $year=$_GET["year"];
  33  if (! $year) { $year = strftime("%Y", time()); }
  34  $modecompta = $conf->compta->mode;
  35  if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
  36  
  37  $sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
  38  $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
  39  if (! $sortorder) $sortorder="asc";
  40  if (! $sortfield) $sortfield="name";
  41  
  42  // Sécurité accés client
  43  if ($user->societe_id > 0) $socidp = $user->societe_id;
  44  
  45  
  46  llxHeader();
  47  
  48  
  49  $html=new Form($db);
  50  
  51  // Affiche en-tête du rapport
  52  if ($modecompta=="CREANCES-DETTES")
  53  {
  54      $nom="Chiffre d'affaire par utilisateur, auteur de la facture";
  55      $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)';
  56      $period=$langs->trans("Year")." $year";
  57      $periodlink="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
  58      $description=$langs->trans("RulesCADue");
  59      $builddate=time();
  60      $exportlink=$langs->trans("NotYetAvailable");
  61  }
  62  else {
  63      $nom="Chiffre d'affaire par utilisateur, auteur de la facture";
  64      $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)';
  65      $period=$langs->trans("Year")." $year";
  66      $periodlink="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
  67      $description=$langs->trans("RulesCAIn");
  68      $builddate=time();
  69      $exportlink=$langs->trans("NotYetAvailable");
  70  }
  71  $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
  72  
  73  
  74  // Charge tableau
  75  $catotal=0;
  76  if ($modecompta == 'CREANCES-DETTES')
  77  {
  78      $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";
  79      $sql .= " FROM ".MAIN_DB_PREFIX."user as u,".MAIN_DB_PREFIX."facture as f";
  80      $sql .= " WHERE f.fk_statut = 1 AND f.fk_user_author = u.rowid";
  81      if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
  82  }
  83  else
  84  {
  85      /*
  86       * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
  87       * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin)
  88       */
  89      $sql = "SELECT u.rowid as rowid, u.name as name, u.firstname as firstname, sum(pf.amount) as amount_ttc";
  90      $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";
  91      $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_user_author = u.rowid";
  92      if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
  93  }
  94  if ($socidp) $sql .= " AND f.fk_soc = $socidp";
  95  $sql .= " GROUP BY rowid";
  96  $sql .= " ORDER BY rowid";
  97  
  98  $result = $db->query($sql);
  99  if ($result)
 100  {
 101      $num = $db->num_rows($result);
 102      $i=0;
 103      while ($i < $num)
 104      {
 105           $obj = $db->fetch_object($result);
 106           $amount[$obj->rowid] = $obj->amount_ttc;
 107           $name[$obj->rowid] = $obj->name.' '.$obj->firstname;
 108           $catotal+=$obj->amount_ttc;
 109           $i++;
 110      }
 111  }
 112  else {
 113      dolibarr_print_error($db);   
 114  }
 115  
 116  // On ajoute les paiements anciennes version, non liés par paiement_facture
 117  if ($modecompta != 'CREANCES-DETTES')
 118  {
 119      $sql = "SELECT -1 as rowid, '' as name, '' as firstname, sum(p.amount) as amount_ttc";
 120      $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
 121      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
 122      $sql .= " WHERE pf.rowid IS NULL";
 123      if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 124      $sql .= " GROUP BY rowid";
 125      $sql .= " ORDER BY rowid";
 126  
 127      $result = $db->query($sql);
 128      if ($result)
 129      {
 130          $num = $db->num_rows($result);
 131          $i=0;
 132          while ($i < $num)
 133          {
 134              $obj = $db->fetch_object($result);
 135              $amount[$obj->rowid] = $obj->amount_ttc;
 136              $name[$obj->rowid] = $obj->name.' '.$obj->firstname;
 137              $catotal+=$obj->amount_ttc;
 138              $i++;
 139          }
 140      }
 141      else {
 142          dolibarr_print_error($db);   
 143      }
 144  }
 145  
 146  
 147  $i = 0;
 148  print "<table class=\"noborder\" width=\"100%\">";
 149  print "<tr class=\"liste_titre\">";
 150  print_liste_field_titre($langs->trans("User"),$_SERVER["PHP_SELF"],"name","",'&amp;year='.($year).'&modecompta='.$modecompta,"",$sortfield);
 151  print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"amount_ttc","",'&amp;year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield);
 152  print_liste_field_titre($langs->trans("Percentage"),$_SERVER["PHP_SELF"],"amount_ttc","",'&amp;year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield);
 153  print "</tr>\n";
 154  $var=true;
 155  
 156  if (sizeof($amount))
 157  {
 158      $arrayforsort=$name;
 159      
 160      // On définit tableau arrayforsort
 161      if ($sortfield == 'name' && $sortorder == 'asc') {
 162          asort($name);
 163          $arrayforsort=$name;
 164      }
 165      if ($sortfield == 'name' && $sortorder == 'desc') {
 166          arsort($name);
 167          $arrayforsort=$name;
 168      }
 169      if ($sortfield == 'amount_ttc' && $sortorder == 'asc') {
 170          asort($amount);
 171          $arrayforsort=$amount;
 172      }
 173      if ($sortfield == 'amount_ttc' && $sortorder == 'desc') {
 174          arsort($amount);
 175          $arrayforsort=$amount;
 176      }
 177  
 178      foreach($arrayforsort as $key=>$value)
 179      {
 180          $var=!$var;
 181          print "<tr $bc[$var]>";
 182  
 183          $fullname=$name[$key];
 184          if ($key >= 0) {
 185              $linkname='<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$key.'">'.img_object($langs->trans("ShowUser"),'user').' '.$fullname.'</a>';
 186          }
 187          else {
 188              $linkname=$langs->trans("Paiements liés à aucune facture");
 189          }
 190          print "<td>".$linkname."</td>\n";
 191          print '<td align="right">'.price($amount[$key]).'</td>';
 192          print '<td align="right">'.($catotal > 0 ? price(100 / $catotal * $amount[$key]).'%' : '&nbsp;').'</td>';
 193          print "</tr>\n";
 194          $i++;
 195      }
 196  
 197      // Total
 198      print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.price($catotal).'</td><td>&nbsp;</td></tr>';
 199  
 200      $db->free($result);
 201  }
 202  
 203  print "</table>";
 204  
 205  $db->close();
 206  
 207  llxFooter('$Date: 2005/09/05 19:27:58 $ - $Revision: 1.13 $');
 208  ?>


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