[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2004 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: commandetableur.class.php,v 1.4 2005/04/08 07:39:02 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/ligne/commande/commandetableur.class.php,v $ 20 * 21 */ 22 23 require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php"; 24 require_once DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php"; 25 require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"; 26 27 define ('COMMANDETABLEUR_NOEMAIL', -3); 28 29 class CommandeTableur 30 { 31 32 function CommandeTableur ($DB, $USER, $fourn) 33 { 34 $this->db = $DB; 35 $this->user = $USER; 36 $this->fournisseur = $fourn; 37 } 38 39 function Create() 40 { 41 42 $this->date = time(); 43 44 $this->datef = "commande-".strftime("%d%b%y-%HH%M", $this->date); 45 46 $fname = $conf->telephonie->dir_output . "/ligne/commande/".$this->datef.".xls"; 47 48 if (strlen(trim($this->fournisseur->email_commande)) == 0) 49 { 50 return -3; 51 } 52 53 if (file_exists($fname)) 54 { 55 return 2; 56 } 57 else 58 { 59 $res = $this->CreateFile($fname); 60 $res = $res + $this->LogSql(); 61 $res = $res + $this->MailFile($fname); 62 63 return $res; 64 } 65 } 66 /** 67 * 68 * 69 * 70 * 71 */ 72 function MailFile($filename) 73 { 74 $sql = "SELECT l.ligne"; 75 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 76 $sql .= " WHERE l.statut = 2"; 77 78 $result = $this->db->query($sql); 79 80 if ($result) 81 { 82 $num = $this->db->num_rows(); 83 } 84 85 $subject = "Commande de Lignes"; 86 87 $sendto = $this->fournisseur->email_commande; 88 89 $from = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC; 90 91 $message = "Bonjour,\n\nVeuillez trouver ci-joint notre dernière commande.\n\n"; 92 $message .= "Nous avons à ce jour $num ligne(s) commandée(s) pour lesquelles nous attendons la confirmation de présélection.\n\n\n"; 93 $message .= "\n\nCordialement,\n\n"; 94 95 $message .= "-- \n"; 96 $message .= $this->user->fullname."\n"; 97 98 99 $mailfile = new DolibarrMail($subject, 100 $sendto, 101 $from, 102 $message); 103 104 $mailfile->addr_bcc = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC; 105 106 $mailfile->PrepareFile(array($filename), 107 array("application/msexcel"), 108 array($this->datef.".xls")); 109 110 if ( $mailfile->sendfile() ) 111 { 112 return 0; 113 } 114 115 } 116 117 function LogSql() 118 { 119 120 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_commande"; 121 $sql .= " (datec, fk_user_creat, fk_fournisseur, filename)"; 122 $sql .= " VALUES (now(),".$this->user->id.",".$this->fournisseur->id.",'".$this->datef.".xls')"; 123 124 $result = $this->db->query($sql); 125 126 if ($result) 127 { 128 return 0; 129 } 130 131 } 132 133 134 function CreateFile($fname) 135 { 136 137 $ligne = new LigneTel($db); 138 139 $workbook = &new writeexcel_workbook($fname); 140 141 $worksheet = &$workbook->addworksheet(); 142 143 $worksheet->write(0, 0, "Commande du ".strftime("%d %B %Y %HH%M", $this->date)); 144 145 $worksheet->set_column('A:A', 20); 146 $worksheet->set_column('B:B', 40); 147 $worksheet->set_column('C:C', 15); 148 $worksheet->set_column('D:D', 9); 149 $worksheet->set_column('E:E', 16); 150 $worksheet->set_column('F:F', 18); 151 $worksheet->set_column('G:G', 20); 152 153 $formatcc =& $workbook->addformat(); 154 $formatcc->set_align('center'); 155 $formatcc->set_align('vcenter'); 156 157 $formatccb =& $workbook->addformat(); 158 $formatccb->set_align('center'); 159 $formatccb->set_align('vcenter'); 160 $formatccb->set_bold(); 161 162 $formatccbr =& $workbook->addformat(); 163 $formatccbr->set_align('center'); 164 $formatccbr->set_align('vcenter'); 165 $formatccbr->set_color('red'); 166 $formatccbr->set_bold(); 167 168 $formatc =& $workbook->addformat(); 169 $formatc->set_align('vcenter'); 170 171 $formatcb =& $workbook->addformat(); 172 $formatcb->set_align('vcenter'); 173 $formatcb->set_bold(); 174 175 $i = 0; 176 177 $ligneids = array(); 178 179 $sqlall = "SELECT s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid"; 180 $sqlall .= " , comm.name, comm.firstname, l.remise"; 181 $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s"; 182 $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 183 $sqlall .= " , ".MAIN_DB_PREFIX."societe as r"; 184 $sqlall .= " , ".MAIN_DB_PREFIX."user as comm"; 185 $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f"; 186 $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid"; 187 $sqlall .= " AND l.fk_soc_facture = r.idp "; 188 $sqlall .= " AND l.fk_commercial = comm.rowid "; 189 /* 190 * 191 */ 192 193 $sql = $sqlall; 194 195 $sql .= " AND l.statut in (1,4)"; 196 $sql .= " ORDER BY l.statut ASC"; 197 198 $result = $this->db->query($sql); 199 200 if ($result) 201 { 202 $num = $this->db->num_rows(); 203 204 $worksheet->write(1, 0, "Clients", $formatc); 205 $worksheet->write(1, 1, "Adresses", $formatc); 206 $worksheet->write(1, 2, "CLI", $formatcc); 207 $worksheet->write(1, 3, "Préfixe", $formatcc); 208 $worksheet->write(1, 4, "Présélection", $formatcc); 209 $worksheet->write(1, 5, "Connexion", $formatcc); 210 $worksheet->write(1, 6, "Date de la demande", $formatcc); 211 212 while ($i < $num) 213 { 214 $obj = $this->db->fetch_object(); 215 216 if (strlen($obj->ligne)== 10) 217 { 218 219 $j = $i + 2; 220 $k = $j + 1; 221 222 $soc = new Societe($this->db); 223 $soc->fetch($obj->socid); 224 225 $worksheet->write($j, 0, $obj->nom, $formatc); 226 $worksheet->write($j, 1, $soc->adresse. " " . $soc->cp . " " . $soc->ville, $formatc); 227 228 $worksheet->write_string($j, 2, "$obj->ligne", $formatcc); 229 230 $worksheet->write_string($j, 3, "Non", $formatcc); 231 $worksheet->write_string($j, 4, "Oui", $formatcc); 232 233 if ($obj->statut == 1) 234 { 235 $worksheet->write($j, 5, "Ajouter", $formatccb); 236 $worksheet->write($j, 6, strftime("%d/%m/%y",$this->date), $formatcc); 237 } 238 elseif($obj->statut == 4) 239 { 240 $worksheet->write($j, 5, "A Résilier", $formatccbr); 241 $worksheet->write($j, 6, strftime("%d/%m/%y",$this->date), $formatcc); 242 } 243 else 244 { 245 $worksheet->write($j, 5, "", $formatccb); 246 $worksheet->write($j, 6, "", $formatccb); 247 } 248 249 250 array_push($ligneids, $obj->rowid); 251 } 252 $i++; 253 } 254 255 $this->db->free(); 256 } 257 else 258 { 259 print $this->db->error() . ' ' . $sql; 260 } 261 262 /* 263 * Archives 264 * Insertion des anciennes lignes dans le fichier Excell 265 */ 266 267 $sql = $sqlall; 268 269 $sql .= "AND l.statut > 0 AND l.statut <> 1 AND l.statut <> 4"; 270 $sql .= " ORDER BY l.statut ASC"; 271 272 $result = $this->db->query($sql); 273 274 if ($result) 275 { 276 $num = $this->db->num_rows(); 277 $i = 0; 278 while ($i < $num) 279 { 280 $obj = $this->db->fetch_object($i); 281 282 $jj = $i + $j + 2; 283 $k = $jj + 1; 284 285 $soc = new Societe($this->db); 286 $soc->fetch($obj->socid); 287 288 $worksheet->write($jj, 0, $obj->nom, $formatc); 289 $worksheet->write($jj, 1, $soc->adresse. " " . $soc->cp . " " . $soc->ville, $formatc); 290 291 $worksheet->write_string($jj, 2, "$obj->ligne", $formatcc); 292 293 $worksheet->write_string($jj, 3, "Non", $formatcc); 294 $worksheet->write_string($jj, 4, "Oui", $formatcc); 295 296 $worksheet->write($jj, 5, "", $formatccb); 297 $worksheet->write($jj, 6, "", $formatccb); 298 299 array_push($ligneids, $obj->rowid); 300 301 $i++; 302 } 303 304 $this->db->free(); 305 } 306 else 307 { 308 print $this->db->error() . ' ' . $sql; 309 } 310 311 312 /* 313 * 314 * 315 */ 316 317 foreach ($ligneids as $lid) 318 { 319 320 $lint = new LigneTel($this->db); 321 $lint->fetch_by_id($lid); 322 if ($lint->statut == 1) 323 { 324 $lint->set_statut($this->user, 2); 325 } 326 if ($lint->statut == 4) 327 { 328 $lint->set_statut($this->user, 5); 329 } 330 } 331 332 333 $workbook->close(); 334 335 336 return 0; 337 338 } 339 }
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 |
![]() |