[ 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/ -> envoi-emails-speciaux.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: envoi-emails-speciaux.php,v 1.2 2005/03/29 11:33:15 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/envoi-emails-speciaux.php,v $
  20   *
  21   *
  22   * Envoie les factures par emails pour un client special
  23   * Scrip non générique utilisé par Rodolphe pour un besoin spécifique
  24   *
  25   */
  26  
  27  require  ("../../master.inc.php");
  28  
  29  require_once  (DOL_DOCUMENT_ROOT."/bon-prelevement.class.php");
  30  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
  31  require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");
  32  require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php");
  33  require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php");
  34  require_once  (DOL_DOCUMENT_ROOT."/facture.class.php");
  35  require_once  (DOL_DOCUMENT_ROOT."/societe.class.php");
  36  require_once  (DOL_DOCUMENT_ROOT."/paiement.class.php");
  37  require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
  38  require_once (DOL_DOCUMENT_ROOT."/telephonie/pdfdetail_ibreizh.modules.php");
  39  require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php");
  40  
  41  dolibarr_syslog("Debut envoie de mail");
  42  
  43  $clientid = 52;
  44  $contactid = 151;
  45  
  46  $year = "2005";
  47  $month = "02";
  48  
  49  $emails = array();
  50  $factures_a_mailer = array();
  51  $factures_lignes = array();
  52  
  53  /*
  54   * Lecture de l'email
  55   */
  56  $sql = "SELECT sc.email FROM ";     
  57  $sql .= MAIN_DB_PREFIX."socpeople as sc";
  58  $sql .= " WHERE sc.idp = ".$contactid;
  59  
  60  $resql = $db->query($sql);
  61  
  62  if ($resql)
  63  {
  64    $row = $db->fetch_row($resql);
  65    dolibarr_syslog($row[0]);
  66  
  67    array_push($emails, $row[0]);
  68  
  69    $db->free($resql);
  70  }
  71  else
  72  {
  73    print $db->error();
  74  }
  75  /*
  76   * Lecture des factures
  77   *
  78   */
  79  $sql = "SELECT distinct(f.fk_facture) FROM ";     
  80  $sql .= MAIN_DB_PREFIX."telephonie_facture as f";
  81  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
  82  $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
  83  
  84  $sql .= " WHERE s.idp = l.fk_client_comm";
  85  $sql .= " AND f.fk_facture IS NOT NULL";
  86  $sql .= " AND l.rowid = f.fk_ligne";
  87  $sql .= " AND s.idp = ".$clientid;
  88  $sql .= " AND date_format(date,'%Y%m') = ".$year.$month;
  89  $sql .= " ORDER BY f.fk_facture ASC";
  90  
  91  $resql = $db->query($sql);
  92  
  93  if ($resql)
  94  {
  95    $num = $db->num_rows($resql);
  96    $i = 0;
  97    dolibarr_syslog($num . " Factures");
  98  
  99    while ($i < $num)
 100      {
 101        $row = $db->fetch_row($resql);
 102  
 103        $factures_a_mailer[$i] = $row[0];
 104  
 105        $i++;
 106      }
 107  
 108  }
 109  else
 110  {
 111    print $db->error();
 112  }
 113  
 114  /*
 115   * Association lignes / factures
 116   *
 117   */
 118  $sql = "SELECT f.fk_facture, f.fk_ligne FROM ";     
 119  $sql .= MAIN_DB_PREFIX."telephonie_facture as f";
 120  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 121  $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 122  
 123  $sql .= " WHERE s.idp = l.fk_client_comm";
 124  $sql .= " AND f.fk_facture IS NOT NULL";
 125  $sql .= " AND l.rowid = f.fk_ligne";
 126  $sql .= " AND s.idp = ".$clientid;
 127  $sql .= " AND date_format(date,'%Y%m') = ".$year.$month;
 128  $sql .= " ORDER BY f.fk_facture ASC";
 129  
 130  $resql = $db->query($sql);
 131  
 132  if ($resql)
 133  {
 134    $num = $db->num_rows($resql);
 135    $i = 0;
 136    dolibarr_syslog($num . " Factures");
 137  
 138    while ($i < $num)
 139      {
 140        $row = $db->fetch_row($resql);
 141  
 142        $factures_lignes[$row[0]] = $row[1];
 143        $i++;
 144      }
 145  }
 146  else
 147  {
 148    print $db->error();
 149  }
 150  
 151  
 152  
 153  /*
 154   *
 155   */
 156  
 157  if (sizeof($factures_a_mailer) > 0)
 158  {
 159    for ($i = 0 ; $i < sizeof($factures_a_mailer) ; $i++)
 160      {
 161        $fact = new Facture($db);
 162  
 163        dolibarr_syslog("Facture ".$factures_a_mailer[$i]);
 164        dolibarr_syslog("ligne ".$factures_lignes[$factures_a_mailer[$i]]);
 165  
 166        if ($fact->fetch($factures_a_mailer[$i]) == 1)
 167      {
 168  
 169        $ligne = new LigneTel($db);
 170        $ligne->fetch_by_id($factures_lignes[$factures_a_mailer[$i]]);
 171  
 172        if (sizeof($emails > 0))
 173          {
 174            $sendto = "";
 175            for ($k = 0 ; $k < sizeof($emails) ; $k++)
 176          {
 177            $sendto .= html_entity_decode($emails[$k]) . ",";
 178          }
 179            $sendto = substr($sendto,0,strlen($sendto) - 1);
 180            
 181            dolibarr_syslog("Envoi email à ".html_entity_decode($sendto) );
 182            
 183            
 184            $subject = "Facture ibreizh ";
 185            $subject .= "(".$ligne->code_analytique.") ";
 186            $subject .= "$fact->ref";
 187            
 188            $from = TELEPHONIE_EMAIL_FACTURATION_EMAIL;
 189            
 190            $message = "Bonjour,\n\n";
 191            $message .= "Code Agence : ".$ligne->code_analytique."\n";
 192            $message .= "Veuillez trouver ci-joint notre facture numéro $fact->ref du ".strftime("%d/%m/%Y",$fact->date).".";
 193            
 194            $message .= "\nEgalement joint à ce mail le détails de vos communications.";
 195            
 196            $message .= "\n\nCordialement,";
 197            $message .= "\n\n--";
 198            $message .= "\niBreizh";
 199            $message .= "\n106 Avenue de la Marne 56000 Vannes";
 200            $message .= "\nTél : 0811 60 23 13";
 201            $message .= "\nFax : 02 97 46 80 19";
 202            
 203            
 204            $mailfile = new DolibarrMail($subject,
 205                         $sendto,
 206                         $from,
 207                         $message);
 208            
 209            $mailfile->addr_bcc = TELEPHONIE_EMAIL_FACTURATION_EMAIL;
 210            
 211            $arr_file = array();          
 212            $arr_name = array();
 213            $arr_mime = array();
 214            
 215            $facfile = FAC_OUTPUTDIR . "/" . $fact->ref . "/" . $fact->ref . ".pdf";
 216            
 217            /*
 218             * Join la facture
 219             */
 220            array_push($arr_file, $facfile);
 221            array_push($arr_mime, "application/pdf");
 222            array_push($arr_name, $fact->ref.".pdf");
 223            
 224            
 225            
 226            $dir = FAC_OUTPUTDIR . "/" . $fact->ref . "/";
 227            
 228            $handle=opendir(FAC_OUTPUTDIR . "/" . $fact->ref . "/");
 229            /*
 230             * Joint les détails
 231             *
 232             */
 233            while (($file = readdir($handle))!==false)
 234          {
 235            if (is_readable($dir.$file) && substr($file, -11) == '-detail.pdf')
 236              {
 237                array_push($arr_file, $dir.$file);
 238                array_push($arr_mime, "application/pdf");
 239                array_push($arr_name, $file);          
 240              }
 241          }
 242            
 243            $mailfile->PrepareFile($arr_file, $arr_mime, $arr_name);
 244            
 245            if ( $mailfile->sendfile() )
 246          {
 247            
 248            for ($kj = 0 ; $kj < sizeof($emails) ; $kj++)
 249              {
 250                $sendtoid = $contactid;
 251                
 252                $sendtox = $emails[$kj];
 253                
 254                $actioncode=9;
 255                $actionmsg="Envoyée à $sendtox";
 256                $actionmsg2="Envoi Facture par mail";
 257                
 258                $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), '$actioncode' ,'$fact->socidp' ,'$actionmsg','$fact->id','$sendtoid','$user->id', '$actionmsg2',100);";
 259                
 260                if (! $db->query($sql) )
 261              {
 262                print $db->error();
 263              }
 264                else
 265              {
 266                //print "TOTO".$sendto. " ". $sendtoid ." \n";
 267              }
 268                
 269              }
 270            
 271          }
 272          }
 273        else
 274          {
 275            print  "Aucun email trouvé\n";
 276            dolibarr_syslog("import.php aucun email trouvé");
 277          }
 278      }
 279      }
 280  }
 281  
 282  
 283  ?>


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