[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 #!/usr/bin/php 2 <?PHP 3 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 4 * Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * 20 * $Id: factures-impayees-commerciaux.php,v 1.4 2005/09/10 15:56:12 eldy Exp $ 21 * $Source: /cvsroot/dolibarr/dolibarr/scripts/factures-impayees-commerciaux.php,v $ 22 */ 23 24 /** 25 \file scripts/factures-impayees-commerciaux.php 26 \ingroup facture 27 \brief Script d'envoi de mails résumé des imapyées par commerciaux 28 */ 29 30 // Test si mode batch 31 $sapi_type = php_sapi_name(); 32 if (substr($sapi_type, 0, 3) == 'cgi') { 33 echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; 34 exit; 35 } 36 37 // Recupere root dolibarr 38 $path=eregi_replace('factures-impayees-commerciaux.php','',$_SERVER["PHP_SELF"]); 39 40 41 require ($path."../htdocs/master.inc.php"); 42 require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); 43 44 45 $error = 0; 46 47 $sql = "SELECT f.facnumber, f.total_ttc, s.nom, u.name, u.firstname, u.email"; 48 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; 49 $sql .= " , ".MAIN_DB_PREFIX."societe as s"; 50 $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 51 $sql .= " , ".MAIN_DB_PREFIX."user as u"; 52 $sql .= " WHERE f.paye = 0"; 53 $sql .= " AND f.fk_soc = s.idp"; 54 $sql .= " AND sc.fk_soc = s.idp"; 55 $sql .= " AND sc.fk_user = u.rowid"; 56 $sql .= " ORDER BY u.email ASC, s.idp ASC"; 57 58 if ( $db->query($sql) ) 59 { 60 $num = $db->num_rows(); 61 $i = 0; 62 $oldemail = ''; 63 $message = ''; 64 $total = ''; 65 dolibarr_syslog("factures-impayees-commerciaux: "); 66 67 if ($num) 68 { 69 while ($i < $num) 70 { 71 $obj = $db->fetch_object(); 72 73 if ($obj->email <> $oldemail) 74 { 75 if (strlen($oldemail)) 76 { 77 envoi_mail($oldemail,$message,$total); 78 } 79 $oldemail = $obj->email; 80 $message = ''; 81 $total = 0; 82 } 83 84 $message .= "Facture ".$obj->facnumber." : ".price($obj->total_ttc)." : ".$obj->nom."\n"; 85 $total += $obj->total_ttc; 86 87 dolibarr_syslog("factures-impayees-commerciaux: ".$obj->email); 88 $i++; 89 } 90 91 // Si il reste des envois en buffer 92 if ($total) 93 { 94 envoi_mail($oldemail,$message,$total); 95 } 96 } 97 else 98 { 99 print "Aucune facture impayée avec des commerciaux directement rattachés\n"; 100 } 101 } 102 else 103 { 104 dolibarr_print_error($db); 105 dolibarr_syslog("factures-impayees-commerciaux: Error"); 106 } 107 108 109 function envoi_mail($oldemail,$message,$total) 110 { 111 global $conf; 112 113 $subject = "[Dolibarr] Liste des factures impayées"; 114 $sendto = $oldemail; 115 $from = $conf->global->MAIN_EMAIL_FROM; 116 117 print "Envoi mail pour $oldemail, total: $total\n"; 118 dolibarr_syslog("factures-impayees-commerciaux: send mail to $oldemail"); 119 120 $allmessage = "Liste des factures impayées à ce jour\n"; 121 $allmessage .= "Cette liste ne comporte que les factures des sociétés dont vous êtes référencés comme commercial.\n"; 122 $allmessage .= "\n"; 123 $allmessage .= $message; 124 $allmessage .= "\n"; 125 $allmessage .= "Total = ".price($total)."\n"; 126 127 $mail = new CMailFile($subject, 128 $sendto, 129 $from, 130 $allmessage,array(),array(),array()); 131 132 $mail->errors_to = $errorsto; 133 134 $result=$mail->sendfile(); 135 if ($result) 136 { 137 138 } 139 140 } 141 142 143 ?>
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 |
![]() |