[ 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/telephonie/script/ -> recap-commande-week.php (source)

   1  <?PHP
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * 
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: recap-commande-week.php,v 1.4 2005/02/28 13:05:54 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/recap-commande-week.php,v $
  20   *
  21   *
  22   * Génére un tableur des lignes commandées dans la semaine
  23   * On génère sur la semaine précédente, le script étant lancé le lundi
  24   *
  25   */
  26  require  "../../master.inc.php";
  27  require_once DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php";
  28  require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php";
  29  require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php";
  30  require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php";
  31  
  32  define ('COMMANDETABLEUR_NOEMAIL', -3);
  33  
  34  $opt = getopt("e:");
  35  
  36  $email = $opt['e'];
  37  
  38  $date = time();
  39  $date_now = $date;
  40  
  41  $dateg = $date - (86400 * 7) ; // On génére la semaine précédente
  42  
  43  Generate($dateg, $db, $date_now, $email);
  44  
  45  /*
  46   *
  47   *
  48   */
  49  
  50  function Generate($date_gen, $db, $date_now, $email)
  51  {
  52    $datef = strftime("%Y-%V", $date_gen);
  53  
  54    $shortname = "recap-semaine-".$datef.".xls";
  55    $fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/".$shortname;
  56    
  57    $ligne = new LigneTel($db);
  58    
  59    $workbook = &new writeexcel_workbook($fname);
  60    
  61    $worksheet = &$workbook->addworksheet();
  62    
  63    $worksheet->write(0, 0,  "Récapitulatif des commandes semaine ".strftime("%V/%Y",$date_gen)." (généré le ".strftime("%d %B %Y %HH%M", $date_now) . ")");
  64    
  65    $worksheet->set_column('A:A', 12);
  66    $worksheet->set_column('B:B', 42);
  67    $worksheet->set_column('C:C', 15);
  68    $worksheet->set_column('D:D', 14);
  69    $worksheet->set_column('E:E', 28);
  70  
  71    $formatcc =& $workbook->addformat();
  72    $formatcc->set_align('center');
  73    $formatcc->set_align('vcenter');
  74  
  75    $format[2] =& $workbook->addformat();
  76    $format[2]->set_align('center');
  77    $format[2]->set_align('vcenter');
  78    $format[2]->set_color('blue');
  79  
  80    $format[3] =& $workbook->addformat();
  81    $format[3]->set_align('center');
  82    $format[3]->set_align('vcenter');
  83    $format[3]->set_color('green');
  84  
  85    $format[4] =& $workbook->addformat();
  86    $format[4]->set_align('center');
  87    $format[4]->set_align('vcenter');
  88    $format[4]->set_color('pink');
  89  
  90    $format[5] =& $workbook->addformat();
  91    $format[5]->set_align('center');
  92    $format[5]->set_align('vcenter');
  93    $format[5]->set_color('orange');
  94  
  95    $format[6] =& $workbook->addformat();
  96    $format[6]->set_align('center');
  97    $format[6]->set_align('vcenter');
  98    $format[6]->set_color('red');
  99    $format[6]->set_bold();
 100  
 101    $format[7] =& $workbook->addformat();
 102    $format[7]->set_align('center');
 103    $format[7]->set_align('vcenter');
 104    $format[7]->set_color('red');
 105    $format[7]->set_bold();
 106  
 107    $format_left[2] =& $workbook->addformat();
 108    $format_left[2]->set_align('vcenter');
 109    $format_left[2]->set_color('blue');
 110  
 111    $format_left[3] =& $workbook->addformat();
 112    $format_left[3]->set_align('vcenter');
 113    $format_left[3]->set_color('green');
 114  
 115    $format_left[4] =& $workbook->addformat();
 116    $format_left[4]->set_align('vcenter');
 117    $format_left[4]->set_color('pink');
 118  
 119    $format_left[5] =& $workbook->addformat();
 120    $format_left[5]->set_align('vcenter');
 121    $format_left[5]->set_color('orange');
 122  
 123    $format_left[6] =& $workbook->addformat();
 124    $format_left[6]->set_align('vcenter');
 125    $format_left[6]->set_color('red');
 126    $format_left[6]->set_bold();
 127  
 128    $format_left[7] =& $workbook->addformat();
 129    $format_left[7]->set_align('vcenter');
 130    $format_left[7]->set_color('red');
 131    $format_left[7]->set_bold();
 132  
 133  
 134    $formatccb =& $workbook->addformat();
 135    $formatccb->set_align('center');
 136    $formatccb->set_align('vcenter');
 137    $formatccb->set_bold();
 138    
 139    $formatccbr =& $workbook->addformat();
 140    $formatccbr->set_align('center');
 141    $formatccbr->set_align('vcenter');
 142    $formatccbr->set_color('red');
 143    $formatccbr->set_bold();
 144  
 145    $formatc =& $workbook->addformat();
 146    $formatc->set_align('vcenter');
 147  
 148    $formatcb =& $workbook->addformat();
 149    $formatcb->set_align('vcenter');
 150    $formatcb->set_bold();
 151  
 152    $i = 0;
 153  
 154    $ligneids = array();
 155  
 156    $sqlall = "SELECT s.code_client, s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
 157    $sqlall .= " , comm.name, comm.firstname, l.remise";
 158    $sqlall .= " , ".$db->pdate("l.date_commande")." as date_commande";
 159    $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
 160    $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 161    $sqlall .= " , ".MAIN_DB_PREFIX."societe as r";
 162    $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
 163    $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 164    $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
 165    $sqlall .= " AND l.fk_soc_facture = r.idp ";
 166    $sqlall .= " AND l.fk_commercial = comm.rowid ";
 167    $sqlall .= " AND date_format(l.date_commande,'%Y%v') = '".strftime("%Y%V", $date_gen)."'";
 168    /*
 169     *
 170     */
 171  
 172    $sql = $sqlall;
 173  
 174    $sql .= " ORDER BY l.date_commande DESC";
 175  
 176    $result = $db->query($sql);
 177  
 178    if ($result)
 179      {
 180        $num = $db->num_rows();
 181    
 182        $worksheet->write(1, 0,  "Code", $formatc);
 183        $worksheet->write(1, 1,  "Client", $formatc);
 184        $worksheet->write(1, 2,  "Numéro", $formatcc);
 185        $worksheet->write(1, 3,  "Date commande", $formatcc);
 186        $worksheet->write(1, 4,  "Statut actuel", $formatcc);
 187    
 188        while ($i < $num)
 189      {
 190        $obj = $db->fetch_object();    
 191        
 192        $j = $i + 3;
 193        
 194        $soc = new Societe($db);
 195        $soc->fetch($obj->socid);
 196        
 197        $worksheet->write($j, 0,  $obj->code_client, $format_left[$obj->statut]);
 198  
 199        $worksheet->write($j, 1,  $obj->nom, $format_left[$obj->statut]);
 200        
 201        $worksheet->write_string($j, 2,  "$obj->ligne", $format[$obj->statut]);
 202        
 203        $worksheet->write($j, 3,  strftime("%d/%m/%y",$obj->date_commande), $format[$obj->statut]);
 204  
 205        $worksheet->write($j, 4,  $ligne->statuts[$obj->statut], $format[$obj->statut]);
 206    
 207        $i++;
 208      }
 209      
 210        $db->free();
 211      }
 212    else 
 213      {
 214        print $db->error() . ' ' . $sql;
 215      }
 216  
 217    /*
 218     *
 219     *
 220     */
 221  
 222    $workbook->close();
 223    /*
 224     *
 225     */
 226    if (strlen($email))
 227      {
 228        MailFile($fname, $shortname, $email);
 229      }
 230    
 231  }
 232  
 233  
 234  
 235  function MailFile($filename, $shortname, $to)
 236  {
 237    $subject = "Recapitulatif hebdomadaire des commandes";
 238  
 239    $sendto = $to;
 240  
 241    $from = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC;
 242    
 243    $message = "Bonjour,\n\nVeuillez trouver ci-joint le dernier récapitulatif des commandes.\n\n";
 244    $message .= "\n\nCordialement,\n";
 245    
 246    $mailfile = new DolibarrMail($subject,
 247                     $sendto,
 248                     $from,
 249                     $message);
 250  
 251    $mailfile->PrepareFile(array($filename),
 252               array("application/msexcel"),
 253               array($shortname));
 254    
 255    if ( $mailfile->sendfile() )
 256      {
 257        return 0;
 258      }  
 259  }


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