From bf5ee25ee225e08ff4d4e5f58da48e0be45430ee Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 25 Jan 2005 12:56:16 +0000 Subject: [PATCH] Nouveau fichier --- scripts/factures-impayees-commerciaux.php | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 scripts/factures-impayees-commerciaux.php diff --git a/scripts/factures-impayees-commerciaux.php b/scripts/factures-impayees-commerciaux.php new file mode 100644 index 00000000000..2176e56aa72 --- /dev/null +++ b/scripts/factures-impayees-commerciaux.php @@ -0,0 +1,105 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + * Envois la liste des factures impayées aux commerciaux + * + */ + +require ("../htdocs/master.inc.php"); +require_once (DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php"); + +$error = 0; + +$sql = "SELECT f.facnumber, f.total_ttc, s.nom, u.name, u.firstname, u.email"; +$sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; +$sql .= " , ".MAIN_DB_PREFIX."societe as s"; +$sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +$sql .= " , ".MAIN_DB_PREFIX."user as u"; +$sql .= " WHERE f.paye = 0"; +$sql .= " AND f.fk_soc = s.idp"; +$sql .= " AND sc.fk_soc = s.idp"; +$sql .= " AND sc.fk_user = u.rowid"; +$sql .= " ORDER BY u.email"; + +if ( $db->query($sql) ) +{ + $num = $db->num_rows(); + $i = 0; + $oldemail = ''; + $message = ''; + $total = ''; + dolibarr_syslog("factures-impayees-commerciaux: "); + + while ($i < $num) + { + $obj = $db->fetch_object(); + + if ($obj->email <> $oldemail) + { + + if (strlen($oldemail)) + { + dolibarr_syslog("factures-impayees-commerciaux: send mail to $oldemail"); + $subject = "[Dolibarr] Liste des factures impayées"; + $sendto = $oldemail; + $from = $oldemail; + + $allmessage = "Liste des factures impayées à ce jour\n"; + $allmessage .= "Cette liste ne comporte que les factures des sociétés dont vous êtes référencés comme commercial.\n"; + $allmessage .= "\n"; + $allmessage .= $message; + $allmessage .= "\n"; + $allmessage .= "Total = ".price($total)."\n"; + + $mail = new DolibarrMail($subject, + $sendto, + $from, + $allmessage); + + $mail->errors_to = $errorsto; + + if ( $mail->sendfile() ) + { + + } + + + + } + $oldemail = $obj->email; + $message = ''; + $total = 0; + } + + + $message .= "Facture ".$obj->facnumber." : ".price($obj->total_ttc)." : ".$obj->nom."\n"; + $total += $obj->total_ttc; + + dolibarr_syslog("factures-impayees-commerciaux: ".$obj->email); + $i++; + + } +} +else +{ + dolibarr_syslog("factures-impayees-commerciaux: Error"); +} + +?>