| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
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: commande.text.class.php,v 1.5 2005/06/15 14:02:21 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/fournisseur/commande/commande.text.class.php,v $ 20 * 21 * Classe de commande de ligne au format Texte 22 * 23 * 24 */ 25 require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"; 26 require_once DOL_DOCUMENT_ROOT."/telephonie/fournisseur/commande/methode.commande.class.php"; 27 28 define ('COMMANDETEXT_NOEMAIL', -3); 29 30 class CommandeMethodeText extends CommandeMethode 31 { 32 33 function CommandeMethodeText ($DB, $USER=0, $fourn=0) 34 { 35 $this->nom = "Méthode texte"; 36 $this->db = $DB; 37 $this->user = $USER; 38 $this->fourn = $fourn; 39 } 40 41 function info() 42 { 43 return "Envoi un fichier texte contenant la liste des lignes à commander"; 44 } 45 46 function Create() 47 { 48 $this->date = time(); 49 50 $this->datef = "ndi-".strftime("%d%b%y-%HH%M", $this->date); 51 52 $this->filename = $this->datef.".txt"; 53 54 $fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/".$this->filename; 55 56 if (strlen(trim($this->fourn->email_commande)) == 0) 57 { 58 return -3; 59 } 60 61 if (file_exists($fname)) 62 { 63 return 2; 64 } 65 else 66 { 67 $res = $this->CreateFile($fname); 68 69 if ($res == 0) 70 { 71 $res = $res + $this->LogSql(); 72 $res = $res + $this->MailFile($fname); 73 } 74 75 return $res; 76 } 77 } 78 /** 79 * 80 * 81 */ 82 function MailFile($filename) 83 { 84 $sql = "SELECT l.ligne"; 85 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 86 $sql .= " WHERE l.statut = 2"; 87 $sql .= " AND l.fk_fournisseur =".$this->fourn->id; 88 89 $result = $this->db->query($sql); 90 91 if ($result) 92 { 93 $num = $this->db->num_rows(); 94 } 95 96 $subject = "Commande de Lignes N° ".$this->commande_id; 97 98 $sendto = $this->fourn->email_commande; 99 100 $from = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC; 101 102 $message = "Bonjour,\n\nVeuillez trouver ci-joint notre dernière commande.\n\n"; 103 $message .= "\n\nCordialement,\n\n"; 104 105 $message .= "-- \n"; 106 $message .= $this->user->fullname."\n"; 107 108 109 $mailfile = new DolibarrMail($subject, 110 $sendto, 111 $from, 112 $message); 113 114 $mailfile->addr_bcc = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC; 115 116 $mailfile->PrepareFile(array($filename), 117 array("plain/text"), 118 array($this->datef.".txt")); 119 120 if ( $mailfile->sendfile() ) 121 { 122 return 0; 123 } 124 125 } 126 127 /** 128 * Creation du fichier 129 * 130 */ 131 132 function CreateFile($fname) 133 { 134 $fp = fopen($fname, "w"); 135 136 if ($fp) 137 { 138 fwrite ($fp, "Numcli;"); 139 fwrite ($fp, "nomclient;"); 140 fwrite ($fp, "NDI\n"); 141 142 $this->ligneids = array(); 143 144 $sqlall = "SELECT s.nom, s.idp as socid, l.ligne, l.statut, l.rowid"; 145 $sqlall .= " , comm.name, comm.firstname"; 146 147 $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s"; 148 $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 149 $sqlall .= " , ".MAIN_DB_PREFIX."user as comm"; 150 $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f"; 151 152 $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid"; 153 154 $sqlall .= " AND l.fk_commercial = comm.rowid "; 155 $sqlall .= " AND f.rowid =".$this->fourn->id; 156 /* 157 * 158 */ 159 $sql = $sqlall; 160 161 $sql .= " AND l.statut in (1,4,8)"; 162 $sql .= " ORDER BY l.statut ASC"; 163 164 $result = $this->db->query($sql); 165 166 if ($result) 167 { 168 $i = 0; 169 $num = $this->db->num_rows(); 170 171 while ($i < $num) 172 { 173 $obj = $this->db->fetch_object(); 174 175 if (strlen($obj->ligne)== 10) 176 { 177 $soc = new Societe($this->db); 178 $soc->fetch($obj->socid); 179 180 fwrite ($fp, $this->fourn->num_client); 181 fwrite ($fp, ";"); 182 fwrite ($fp, $obj->nom); 183 fwrite ($fp, ";"); 184 fwrite ($fp, $obj->ligne); 185 fwrite ($fp, "\n"); 186 187 array_push($this->ligneids, $obj->rowid); 188 } 189 $i++; 190 } 191 192 $this->db->free(); 193 } 194 else 195 { 196 print $this->db->error() . ' ' . $sql; 197 } 198 199 fclose($fp); 200 201 /* 202 * 203 * 204 */ 205 206 foreach ($this->ligneids as $lid) 207 { 208 209 $lint = new LigneTel($this->db); 210 $lint->fetch_by_id($lid); 211 if ($lint->statut == 1) 212 { 213 $lint->set_statut($this->user, 2); 214 } 215 if ($lint->statut == 4) 216 { 217 $lint->set_statut($this->user, 5); 218 } 219 if ($lint->statut == 8) 220 { 221 $lint->set_statut($this->user, 2); 222 } 223 } 224 225 return 0; 226 227 } 228 else 229 { 230 return -1; 231 } 232 } 233 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|