|
@@ -25,7 +25,9 @@
|
|
|
* \brief Script to send a mail to customers with services to expire
|
|
|
*/
|
|
|
|
|
|
-if (!defined('NOSESSION')) define('NOSESSION', '1');
|
|
|
+if (!defined('NOSESSION')) {
|
|
|
+ define('NOSESSION', '1');
|
|
|
+}
|
|
|
|
|
|
$sapi_type = php_sapi_name();
|
|
|
$script_file = basename(__FILE__);
|
|
@@ -80,24 +82,30 @@ if ($mode != 'confirm') {
|
|
|
|
|
|
$sql = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,";
|
|
|
$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
|
|
|
-if ($targettype == 'contacts')
|
|
|
+if ($targettype == 'contacts') {
|
|
|
$sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
|
|
|
+}
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
|
|
|
-if ($targettype == 'contacts')
|
|
|
+if ($targettype == 'contacts') {
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
|
|
|
+}
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
|
|
|
$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5";
|
|
|
-if (is_numeric($duration_value2))
|
|
|
+if (is_numeric($duration_value2)) {
|
|
|
$sql .= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
|
|
|
-if (is_numeric($duration_value))
|
|
|
+}
|
|
|
+if (is_numeric($duration_value)) {
|
|
|
$sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
|
|
|
-if ($targettype == 'contacts')
|
|
|
+}
|
|
|
+if ($targettype == 'contacts') {
|
|
|
$sql .= " AND s.rowid = sp.fk_soc";
|
|
|
+}
|
|
|
$sql .= " ORDER BY";
|
|
|
-if ($targettype == 'contacts')
|
|
|
+if ($targettype == 'contacts') {
|
|
|
$sql .= " sp.email, sp.rowid,";
|
|
|
+}
|
|
|
$sql .= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email
|
|
|
|
|
|
// print $sql;
|
|
@@ -145,9 +153,11 @@ if ($resql) {
|
|
|
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
|
|
|
} else {
|
|
|
if ($oldemail != 'none') {
|
|
|
- if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
|
|
+ if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
|
|
|
print "- No email sent for '".$oldtarget."', total: ".$total."\n";
|
|
|
- else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
|
|
+ } else {
|
|
|
+ print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$oldemail = $newemail;
|
|
@@ -176,9 +186,11 @@ if ($resql) {
|
|
|
$foundtoprocess++;
|
|
|
}
|
|
|
print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".(isset($obj->cid) ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
|
|
|
- if (dol_strlen($newemail))
|
|
|
+ if (dol_strlen($newemail)) {
|
|
|
print "qualified.";
|
|
|
- else print "disqualified (no email).";
|
|
|
+ } else {
|
|
|
+ print "disqualified (no email).";
|
|
|
+ }
|
|
|
print "\n";
|
|
|
|
|
|
unset($outputlangs);
|
|
@@ -190,15 +202,16 @@ if ($resql) {
|
|
|
|
|
|
// Si il reste des envois en buffer
|
|
|
if ($foundtoprocess) {
|
|
|
- if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email)
|
|
|
- {
|
|
|
+ if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { // Break onto email (new email)
|
|
|
envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
|
|
|
$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
|
|
|
} else {
|
|
|
if ($oldemail != 'none') {
|
|
|
- if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
|
|
|
+ if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
|
|
|
print "- No email sent for '".$oldtarget."', total: ".$total."\n";
|
|
|
- else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
|
|
+ } else {
|
|
|
+ print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -230,8 +243,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
|
|
|
- if (getenv('DOL_FORCE_EMAIL_TO'))
|
|
|
+ if (getenv('DOL_FORCE_EMAIL_TO')) {
|
|
|
$oldemail = getenv('DOL_FORCE_EMAIL_TO');
|
|
|
+ }
|
|
|
|
|
|
$newlangs = new Translate('', $conf);
|
|
|
$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
|
|
@@ -239,10 +253,14 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
|
|
|
$newlangs->load("contracts");
|
|
|
|
|
|
if ($duration_value) {
|
|
|
- if ($duration_value > 0)
|
|
|
+ if ($duration_value > 0) {
|
|
|
$title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
|
|
|
- else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
|
|
- } else $title = $newlangs->transnoentities("ListOfServicesToExpire");
|
|
|
+ } else {
|
|
|
+ $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $title = $newlangs->transnoentities("ListOfServicesToExpire");
|
|
|
+ }
|
|
|
|
|
|
$subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
|
|
|
$sendto = $oldemail;
|
|
@@ -254,10 +272,12 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
|
|
|
dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
|
|
|
|
|
|
$usehtml = 0;
|
|
|
- if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
|
|
|
+ if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
|
|
|
$usehtml += 1;
|
|
|
- if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
|
|
|
+ }
|
|
|
+ if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
|
|
|
$usehtml += 1;
|
|
|
+ }
|
|
|
|
|
|
$allmessage = '';
|
|
|
if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
|
|
@@ -270,8 +290,9 @@ function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $
|
|
|
// $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
|
|
|
if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
|
|
|
$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
|
|
|
- if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
|
|
|
+ if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
|
|
|
$usehtml += 1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
|