[ 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/ -> lignes-resiliees.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: lignes-resiliees.php,v 1.1 2005/09/22 10:11:36 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/lignes-resiliees.php,v $
  20   *
  21   * Calcul des commissions des distributeurs
  22   */
  23  
  24  require  ("../../master.inc.php");
  25  require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
  26  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
  27  
  28  $error = 0;
  29  $lignes = array();
  30  $resil  = array();
  31  $datetime = time();
  32  
  33  $datel = time() - (3600 * 24 * 7);
  34  
  35  /********************************************************
  36   *
  37   * Verification des données
  38   *
  39   *
  40   *********************************************************/
  41  
  42  $distributeurs = array();
  43  
  44  $sql = "SELECT fk_ligne, ".$db->pdate("tms");
  45  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne_statut";
  46  $sql .= " WHERE statut = 6";
  47  $sql .= " AND tms >= '".strftime("%Y-%m-%d",$datel)."';";
  48    
  49  $resql = $db->query($sql);
  50    
  51  if ( $resql )
  52  {
  53    $num = $db->num_rows($resql);
  54    $i = 0;
  55  
  56    while ($i < $num)
  57      {
  58        $row = $db->fetch_row($resql);
  59        array_push($lignes, $row[0]);
  60        $resil[$row[0]] = strftime("%d/%m/%y",$row[1]);
  61        $i++;
  62      }
  63    $db->free($resql);
  64  }
  65  else
  66  {
  67    $error = 1;
  68  }
  69  
  70  $llig = substr("Ligne".str_repeat(" ",10), 0, 10);
  71  $lsoc = substr("Societe".str_repeat(" ",40), 0, 40);
  72  $lca = substr(str_repeat(" ",10)."CA Moyen", -10);
  73  $lres = substr(str_repeat(" ",10)."Date Resil", -10);
  74  
  75  $message ="Bonjour,\n\n";
  76  $message .= "Veuillez trouver ci-joint la liste des lignes résiliées ces 7 derniers jours avec le chiffre d'affaire moyen.\n\n";
  77  
  78  $message .= "$llig $lsoc $lca $lres\n";
  79  $message .= str_repeat("-",73)."\n";
  80  
  81  foreach ($lignes as $lid)
  82  {
  83    //  print "$lid\n";
  84    $ligne = new LigneTel($db);
  85    $ligne->fetch_by_id($lid);
  86  
  87    $sql = "SELECT sum(cout_vente), count(cout_vente)";
  88    $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
  89    $sql .= " WHERE fk_ligne = ".$ligne->id;
  90  
  91    $resql = $db->query($sql);
  92    
  93    if ( $resql )
  94      {
  95        while ($row = $db->fetch_row($resql))
  96      {
  97        $sum = $row[0];
  98        $nb = $row[1];
  99      }
 100        $db->free($resql);
 101      }
 102    else
 103      {
 104        $error = 1;
 105      }
 106  
 107    $num = $ligne->numero;
 108  
 109    $societe = new Societe($db);
 110    $societe->fetch($ligne->client_comm_id);
 111    $socnom = $societe->nom;
 112  
 113    if (strlen($socnom) > 40)
 114      {
 115        $socnom = substr($socnom, 0, 37) . "...";
 116      }
 117  
 118    $socnom = substr($socnom.str_repeat(" ",40), 0, 40) ;
 119  
 120    if ($nb > 0)
 121      {
 122        $ca = $sum / $nb;
 123      }
 124    else
 125      {
 126        $ca = 0;
 127      }
 128  
 129    $pm = substr("          ".sprintf("%01.2f",$ca), -10);
 130  
 131    $message .= "$num $socnom $pm   ".$resil[$ligne->id]."\n";
 132  }
 133  
 134  
 135  $message .="\n--\n";
 136  $message .= "Ceci est un message automatique envoyé par dolibarr auquel vous ne pouvez pas répondre\n";
 137  
 138  $users = array(1, 32);
 139  
 140  foreach ($users as $xuser)
 141  {
 142    $cuser = new User($db, $xuser);
 143    $cuser->fetch();
 144  
 145    $subject ="Liste des lignes résiliées";
 146    $sendto = $cuser->prenom . " ".$cuser->nom . " <".$cuser->email.">";
 147    $from = "noreply@noreply.null";
 148    $message = wordwrap( $message, 76 );
 149    
 150    $mailfile = new CMailFile($subject,
 151                  $sendto,
 152                  $from,
 153                  $message, array(), array(), array());
 154    if ( $mailfile->sendfile() )
 155      {
 156        
 157      }
 158  }
 159  ?>


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