diff --git a/htdocs/langs/en_US/contracts.lang b/htdocs/langs/en_US/contracts.lang index bab5a4451c4..eceac62999a 100644 --- a/htdocs/langs/en_US/contracts.lang +++ b/htdocs/langs/en_US/contracts.lang @@ -87,8 +87,9 @@ ExpiredSince=Expiration date RelatedContracts=Related contracts NoExpiredServices=No expired active services ListOfServicesToExpireWithDuration=List of Services to expire in %s days +ListOfServicesToExpireWithDurationNeg=List of Services expired from more than %s days ListOfServicesToExpire=List of Services to expire -Service=Service +NoteListOfYourExpiredServices=This list contains only services of contracts for third parties you are linked to as a sale representative. ##### Types de contacts ##### TypeContact_contrat_internal_SALESREPSIGN=Sales representative signing contract diff --git a/htdocs/langs/fr_FR/contracts.lang b/htdocs/langs/fr_FR/contracts.lang index 9cef9326f8e..36888df40b0 100644 --- a/htdocs/langs/fr_FR/contracts.lang +++ b/htdocs/langs/fr_FR/contracts.lang @@ -86,9 +86,10 @@ PaymentRenewContractId=Renouvellement service (numéro %s) ExpiredSince=Expiré le RelatedContracts=Contrats associés NoExpiredServices=Pas de services actifs expirés -ListOfServicesToExpireWithDuration=Liste des services actifs pour expirer à %s days -ListOfServicesToExpire=Liste des services actifs pour expirer -Service=Service +ListOfServicesToExpireWithDuration=Liste des services actifs expirant dans %s jours +ListOfServicesToExpireWithDurationNeg=Liste des services actifs expiré depuis plus de %s jours +ListOfServicesToExpire=Liste des services actifs en expiration +NoteListOfYourExpiredServices=Cette list ne contient que les contrats de services des tiers pour lesquels vous êtes liés comme représentant commercial. ##### Types de contacts ##### TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat diff --git a/scripts/company/export-contacts-xls-example.php b/scripts/company/export-contacts-xls-example.php old mode 100644 new mode 100755 diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php old mode 100644 new mode 100755 diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php index 611d614393a..83f71d7e65d 100755 --- a/scripts/contracts/email_expire_services_to_customers.php +++ b/scripts/contracts/email_expire_services_to_customers.php @@ -36,16 +36,18 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit(-1); } -if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm'))) +if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts'))) { - print "Usage: $script_file [test|confirm] [delay]\n"; + print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n"; print "\n"; - print "Send an email to customers to remind all all contracts services to expire.\n"; + print "Send an email to customers to remind all contracts services to expire or expired.\n"; print "If you choose 'test' mode, no emails are sent.\n"; - print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n"; + print "If you add param delay (nb of days), only services with expired date < today + delay are included.\n"; + print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n"; exit(-1); } $mode=$argv[1]; +$targettype=$argv[2]; require($path."../../htdocs/master.inc.php"); @@ -69,33 +71,42 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n"; dol_syslog($script_file." launched with arg ".join(',',$argv)); $now=dol_now('tzserver'); -$duration_value=isset($argv[2])?$argv[2]:'none'; +$duration_value=isset($argv[3])?$argv[3]:'none'; +$duration_value2=isset($argv[4])?$argv[4]:'none'; -print $script_file." launched with mode ".$mode.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n"; +$error = 0; +print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n"; if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1; -$sql = "SELECT DISTINCT s.nom as name, c.ref, cd.date_fin_validite, cd.total_ttc, p.label label, s.email, s.default_lang"; +$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') $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') $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"; +$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)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'"; +if (is_numeric($duration_value)) $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; +if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc"; +$sql.= " ORDER BY"; +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 -if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; - -$sql .= " ORDER BY cd.date_fin_validite ASC, s.rowid ASC"; - -print $sql; +//print $sql; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; - $oldemail = 'none'; $oldlang=''; + $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang=''; $total = 0; $foundtoprocess = 0; - print "We found ".$num." couples (services to expire - customer) qualified\n"; - dol_syslog("We found ".$num." couples (services to expire - customer) qualified"); + $trackthirdpartiessent = array(); + + print "We found ".$num." couples (services to expire-".$targettype.") qualified\n"; + dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified"); $message=''; if ($num) @@ -104,25 +115,40 @@ if ($resql) { $obj = $db->fetch_object($resql); - if (($obj->email <> $oldemail) || $oldemail == 'none') + $newemail=empty($obj->cemail)?$obj->email:$obj->cemail; + + // Check if this record is a break after previous one + $startbreak=false; + if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true; + if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true; + if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true; + + if ($startbreak) { - // Break onto sales representative (new email or uid) - if (dol_strlen($oldemail) && $oldemail != 'none') + // Break onto sales representative (new email or cid) + if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { - envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldcustomer,$duration_value); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + if ($oldemail != 'none') + { + 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"; + } } - $oldemail = $obj->email; + $oldemail = $newemail; + $oldsid = $obj->sid; + $oldcid = $obj->cid; $oldlang = $obj->lang; - $oldcustomer=$obj->name; + $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname); $message = ''; - $total = 0; + $total = 0; $foundtoprocess = 0; - $customer=$obj->name; - if (empty($obj->email)) print "Warning: Customer ".$customer." has no email. Notice disabled.\n"; + $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname); + //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n"; } // Define line content @@ -131,18 +157,21 @@ if ($resql) $outputlangs->load("bills"); $outputlangs->load("main"); $outputlangs->load("contracts"); + $outputlangs->load("products"); - if (dol_strlen($oldemail)) + if (dol_strlen($newemail)) { - $message .= $langs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".$obj->label." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$langs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n"; - dol_syslog("email_expire_services_to_customers.php: ".$obj->email); + $message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n"; + dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message); $foundtoprocess++; } - print "Service to expire ".$obj->ref.", label ".$obj->label.", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->nom.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): "; - if (dol_strlen($obj->email)) print "qualified."; + 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.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; + if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; print "\n"; + unset($outputlangs); + $total += $obj->total_ttc; $i++; @@ -151,13 +180,18 @@ if ($resql) // Si il reste des envois en buffer if ($foundtoprocess) { - if (dol_strlen($oldemail) && $oldemail != 'none') // 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,$oldcustomer,$duration_value); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + if ($oldemail != 'none') + { + 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"; + } } } } @@ -181,15 +215,15 @@ else * Send email * * @param string $mode Mode (test | confirm) - * @param string $oldemail Old email + * @param string $oldemail Target email * @param string $message Message to send * @param string $total Total amount of unpayed invoices * @param string $userlang Code lang to use for email output. - * @param string $oldcustomer Old customer + * @param string $oldtarget Target name * @param int $duration_value duration value * @return int <0 if KO, >0 if OK */ -function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$duration_value) +function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget,$duration_value) { global $conf,$langs; @@ -201,17 +235,20 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura $newlangs->load("contracts"); if ($duration_value) - $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); + { + if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); + else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); + } else $title= $newlangs->transnoentities("ListOfServicesToExpire"); - $subject = "[".(empty($conf->global->MAIN_APPLICATION_TITLE)?'Dolibarr':$conf->global->MAIN_APPLICATION_TITLE)."] ".$title; + $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT); $sendto = $oldemail; $from = $conf->global->MAIN_MAIL_EMAIL_FROM; $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; $msgishtml = -1; - print "- Send email for ".$oldcustomer."(".$oldemail."), total: ".$total."\n"; + print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n"; dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail); $usehtml=0; @@ -227,10 +264,9 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura { $allmessage.= "Dear customer".($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); $allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); - $allmessage.= "Note: This list contains only services to expire.".($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); } $allmessage.= $message.($usehtml?"
\n":"\n"); - $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"
\n":"\n"); + //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"
\n":"\n"); if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) { $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER; @@ -271,6 +307,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura $result=1; } + unset($newlangs); if ($result) { return 1; diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php index 7fded53a9f7..76489bebcf2 100755 --- a/scripts/contracts/email_expire_services_to_representatives.php +++ b/scripts/contracts/email_expire_services_to_representatives.php @@ -38,7 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') { if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm'))) { - print "Usage: $script_file [test|confirm] [delay]\n"; + print "Usage: $script_file (test|confirm) [delay]\n"; print "\n"; print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n"; print "If you choose 'test' mode, no emails are sent.\n"; @@ -71,20 +71,18 @@ dol_syslog($script_file." launched with arg ".join(',',$argv)); $now=dol_now('tzserver'); $duration_value=isset($argv[2])?$argv[2]:'none'; -print $script_file." launched with mode ".$mode.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n"; +print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n"; if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1; -$sql = "SELECT DISTINCT s.nom, c.ref, cd.date_fin_validite, cd.total_ttc, p.label label, c.fk_soc,u.rowid AS uid, u.lastname, u.firstname, u.email, u.lang"; -$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u"; - -$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5"; - +$sql = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.nom as name, s.email, s.default_lang,"; +$sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; +$sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u"; +$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_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; - -$sql .= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid"; -$sql .= " ORDER BY cd.date_fin_validite ASC, s.rowid ASC"; +$sql.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid"; +$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email //print $sql; $resql=$db->query($sql); @@ -131,19 +129,23 @@ if ($resql) $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang); // By default language of sale representative $outputlangs->load("bills"); $outputlangs->load("main"); + $outputlangs->load("contracts"); + $outputlangs->load("products"); if (dol_strlen($obj->email)) { - $message .= $langs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".$obj->label." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->nom.", ".$langs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n"; + $message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n"; dol_syslog("email_expire_services_to_representatives.php: ".$obj->email); $foundtoprocess++; } - print "Service to expire ".$obj->ref.", label ".$obj->label.", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->nom.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): "; + 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')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): "; if (dol_strlen($obj->email)) print "qualified."; else print "disqualified (no email)."; print "\n"; - $total += $obj->total_ttc; + unset($outputlangs); + + $total += $obj->total_ttc; $i++; } @@ -200,11 +202,14 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta $newlangs->load("contracts"); if ($duration_value) - $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); + { + if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); + else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); + } else $title= $newlangs->transnoentities("ListOfServicesToExpire"); - $subject = "[".(empty($conf->global->MAIN_APPLICATION_TITLE)?'Dolibarr':$conf->global->MAIN_APPLICATION_TITLE)."] ".$title; + $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT); $sendto = $oldemail; $from = $conf->global->MAIN_MAIL_EMAIL_FROM; $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; @@ -225,7 +230,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta else { $allmessage.= $title.($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); - $allmessage.= "Note: This list contains only services of contracts for third parties you are linked to as a sale representative.".($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); + $allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); } $allmessage.= $message.($usehtml?"
\n":"\n"); $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"
\n":"\n"); diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index fbd7bf7b466..52bc8bd1442 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -160,7 +160,7 @@ if ($resql) dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message); $foundtoprocess++; } - print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.",":"")." email ".$newemail." lang ".$outputlangs->defaultlang.": "; + print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": "; if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; print "\n"; diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index e3b23a932d5..e83dbe5b795 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -38,7 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') { if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm'))) { - print "Usage: $script_file [test|confirm] [delay]\n"; + print "Usage: $script_file (test|confirm) [delay]\n"; print "\n"; print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n"; print "If you choose 'test' mode, no emails are sent.\n"; @@ -125,7 +125,7 @@ if ($resql) $total = 0; $foundtoprocess = 0; $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname); - if (empty($obj->email)) print "Warning: Sal representative ".$salerepresentative." has no email. Notice disabled.\n"; + if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n"; } // Define line content @@ -140,7 +140,7 @@ if ($resql) dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email); $foundtoprocess++; } - print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email." lang ".$outputlangs->defaultlang."): "; + print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): "; if (dol_strlen($obj->email)) print "qualified."; else print "disqualified (no email)."; print "\n"; diff --git a/scripts/withdrawals/build_withdrawal_file.php b/scripts/withdrawals/build_withdrawal_file.php old mode 100644 new mode 100755 diff --git a/test/phpunit/ScriptsTest.php b/test/phpunit/ScriptsTest.php index 82d6a6c7240..19a10dc526b 100755 --- a/test/phpunit/ScriptsTest.php +++ b/test/phpunit/ScriptsTest.php @@ -151,9 +151,75 @@ class ScriptsTest extends PHPUnit_Framework_TestCase return $result; } + /** + * testCompany + * + * @depends testBank + * @return string + */ + public function testCompany() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + /* + $script=dirname(__FILE__).'/../../scripts/company/sync_contacts_dolibarr_2ldap now'; + $result=exec($script, $output, $returnvar); + + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($result,'Failed to find bank account with ref BANKDUMMY.'); + $this->assertEquals($returnvar,255); + */ + return $result; + } + + /** + * testContracts + * + * @depends testCompany + * @return string + */ + public function testContracts() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test thirdparties'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar,0,'email_expire_services_to_customers.php thirdparties'); + + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test contacts -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar,0,'email_expire_services_to_customers.php contacts'); + + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_representatives.php test -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar,0,'email_expire_services_to_representatives.php'); + + return $result; + } + /** * testInvoices * + * @depends testContracts * @return string */ public function testInvoices() @@ -166,11 +232,24 @@ class ScriptsTest extends PHPUnit_Framework_TestCase $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties'; $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; print __METHOD__." output=".join("\n",$output)."\n"; print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar,0); + $this->assertEquals($returnvar,0,'email_unpaid_invoices_to_customers.php thirdparties'); + + $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test contacts -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar,0,'email_unpaid_invoices_to_customers.php contacts'); + + $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_representatives.php test thirdparties'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n",$output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar,0,'email_unpaid_invoices_to_customers.php thirdparties'); return $result; }