2
0
forked from Wavyzz/dolibarr

Fix: Maxi debug of scripts

This commit is contained in:
Laurent Destailleur
2013-07-31 12:33:18 +02:00
parent 384e3812eb
commit fbd3f6e67f
10 changed files with 192 additions and 69 deletions

View File

@@ -87,8 +87,9 @@ ExpiredSince=Expiration date
RelatedContracts=Related contracts RelatedContracts=Related contracts
NoExpiredServices=No expired active services NoExpiredServices=No expired active services
ListOfServicesToExpireWithDuration=List of Services to expire in %s days 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 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 ##### ##### Types de contacts #####
TypeContact_contrat_internal_SALESREPSIGN=Sales representative signing contract TypeContact_contrat_internal_SALESREPSIGN=Sales representative signing contract

View File

@@ -86,9 +86,10 @@ PaymentRenewContractId=Renouvellement service (numéro %s)
ExpiredSince=Expiré le ExpiredSince=Expiré le
RelatedContracts=Contrats associés RelatedContracts=Contrats associés
NoExpiredServices=Pas de services actifs expirés NoExpiredServices=Pas de services actifs expirés
ListOfServicesToExpireWithDuration=Liste des services actifs pour expirer à %s days ListOfServicesToExpireWithDuration=Liste des services actifs expirant dans %s jours
ListOfServicesToExpire=Liste des services actifs pour expirer ListOfServicesToExpireWithDurationNeg=Liste des services actifs expiré depuis plus de %s jours
Service=Service 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 ##### ##### Types de contacts #####
TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat

0
scripts/company/export-contacts-xls-example.php Normal file → Executable file
View File

0
scripts/company/sync_contacts_dolibarr2ldap.php Normal file → Executable file
View File

View File

@@ -36,16 +36,18 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
exit(-1); 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 "\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 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); exit(-1);
} }
$mode=$argv[1]; $mode=$argv[1];
$targettype=$argv[2];
require($path."../../htdocs/master.inc.php"); 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)); dol_syslog($script_file." launched with arg ".join(',',$argv));
$now=dol_now('tzserver'); $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; 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"; $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."contrat AS c";
$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd"; $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product"; $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 (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
$sql .= " ORDER BY cd.date_fin_validite ASC, s.rowid ASC"; //print $sql;
print $sql;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$oldemail = 'none'; $oldlang=''; $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
$total = 0; $foundtoprocess = 0; $total = 0; $foundtoprocess = 0;
print "We found ".$num." couples (services to expire - customer) qualified\n"; $trackthirdpartiessent = array();
dol_syslog("We found ".$num." couples (services to expire - customer) qualified");
print "We found ".$num." couples (services to expire-".$targettype.") qualified\n";
dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified");
$message=''; $message='';
if ($num) if ($num)
@@ -104,25 +115,40 @@ if ($resql)
{ {
$obj = $db->fetch_object($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) // Break onto sales representative (new email or cid)
if (dol_strlen($oldemail) && $oldemail != 'none') 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 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; $oldlang = $obj->lang;
$oldcustomer=$obj->name; $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
$message = ''; $message = '';
$total = 0; $total = 0;
$foundtoprocess = 0; $foundtoprocess = 0;
$customer=$obj->name; $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
if (empty($obj->email)) print "Warning: Customer ".$customer." has no email. Notice disabled.\n"; //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
} }
// Define line content // Define line content
@@ -131,18 +157,21 @@ if ($resql)
$outputlangs->load("bills"); $outputlangs->load("bills");
$outputlangs->load("main"); $outputlangs->load("main");
$outputlangs->load("contracts"); $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"; $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: ".$obj->email); dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
$foundtoprocess++; $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').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
if (dol_strlen($obj->email)) print "qualified."; if (dol_strlen($newemail)) print "qualified.";
else print "disqualified (no email)."; else print "disqualified (no email).";
print "\n"; print "\n";
unset($outputlangs);
$total += $obj->total_ttc; $total += $obj->total_ttc;
$i++; $i++;
@@ -151,13 +180,18 @@ if ($resql)
// Si il reste des envois en buffer // Si il reste des envois en buffer
if ($foundtoprocess) 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 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 * Send email
* *
* @param string $mode Mode (test | confirm) * @param string $mode Mode (test | confirm)
* @param string $oldemail Old email * @param string $oldemail Target email
* @param string $message Message to send * @param string $message Message to send
* @param string $total Total amount of unpayed invoices * @param string $total Total amount of unpayed invoices
* @param string $userlang Code lang to use for email output. * @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 * @param int $duration_value duration value
* @return int <0 if KO, >0 if OK * @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; global $conf,$langs;
@@ -201,17 +235,20 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
$newlangs->load("contracts"); $newlangs->load("contracts");
if ($duration_value) 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 else
$title= $newlangs->transnoentities("ListOfServicesToExpire"); $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; $sendto = $oldemail;
$from = $conf->global->MAIN_MAIL_EMAIL_FROM; $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
$msgishtml = -1; $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); dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
$usehtml=0; $usehtml=0;
@@ -227,10 +264,9 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
{ {
$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); $allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
$allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); $allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
$allmessage.= "Note: This list contains only services to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
} }
$allmessage.= $message.($usehtml?"<br>\n":"\n"); $allmessage.= $message.($usehtml?"<br>\n":"\n");
$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n"); //$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)) if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
{ {
$allmessage.=$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; $result=1;
} }
unset($newlangs);
if ($result) if ($result)
{ {
return 1; return 1;

View File

@@ -38,7 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
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')))
{ {
print "Usage: $script_file [test|confirm] [delay]\n"; print "Usage: $script_file (test|confirm) [delay]\n";
print "\n"; print "\n";
print "Send an email to remind all contracts services to expire, to users that are sale representative for.\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"; 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'); $now=dol_now('tzserver');
$duration_value=isset($argv[2])?$argv[2]:'none'; $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; 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 = "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.= " 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.= " 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.= " 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"))."'"; 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.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
$sql .= " ORDER BY cd.date_fin_validite ASC, s.rowid ASC"; $sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email
//print $sql; //print $sql;
$resql=$db->query($sql); $resql=$db->query($sql);
@@ -131,18 +129,22 @@ if ($resql)
$outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang); // By default language of sale representative $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang); // By default language of sale representative
$outputlangs->load("bills"); $outputlangs->load("bills");
$outputlangs->load("main"); $outputlangs->load("main");
$outputlangs->load("contracts");
$outputlangs->load("products");
if (dol_strlen($obj->email)) 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); dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
$foundtoprocess++; $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."; if (dol_strlen($obj->email)) print "qualified.";
else print "disqualified (no email)."; else print "disqualified (no email).";
print "\n"; print "\n";
unset($outputlangs);
$total += $obj->total_ttc; $total += $obj->total_ttc;
$i++; $i++;
} }
@@ -200,11 +202,14 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
$newlangs->load("contracts"); $newlangs->load("contracts");
if ($duration_value) 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 else
$title= $newlangs->transnoentities("ListOfServicesToExpire"); $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; $sendto = $oldemail;
$from = $conf->global->MAIN_MAIL_EMAIL_FROM; $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
$errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -225,7 +230,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
else else
{ {
$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); $allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
$allmessage.= "Note: This list contains only services of contracts for third parties you are linked to as a sale representative.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); $allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
} }
$allmessage.= $message.($usehtml?"<br>\n":"\n"); $allmessage.= $message.($usehtml?"<br>\n":"\n");
$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n"); $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");

View File

@@ -160,7 +160,7 @@ if ($resql)
dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message); dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
$foundtoprocess++; $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."; if (dol_strlen($newemail)) print "qualified.";
else print "disqualified (no email)."; else print "disqualified (no email).";
print "\n"; print "\n";

View File

@@ -38,7 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
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')))
{ {
print "Usage: $script_file [test|confirm] [delay]\n"; print "Usage: $script_file (test|confirm) [delay]\n";
print "\n"; print "\n";
print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\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"; print "If you choose 'test' mode, no emails are sent.\n";
@@ -125,7 +125,7 @@ if ($resql)
$total = 0; $total = 0;
$foundtoprocess = 0; $foundtoprocess = 0;
$salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname); $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 // Define line content
@@ -140,7 +140,7 @@ if ($resql)
dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email); dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
$foundtoprocess++; $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."; if (dol_strlen($obj->email)) print "qualified.";
else print "disqualified (no email)."; else print "disqualified (no email).";
print "\n"; print "\n";

0
scripts/withdrawals/build_withdrawal_file.php Normal file → Executable file
View File

View File

@@ -151,9 +151,75 @@ class ScriptsTest extends PHPUnit_Framework_TestCase
return $result; 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 * testInvoices
* *
* @depends testContracts
* @return string * @return string
*/ */
public function testInvoices() 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'; $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties';
$result=exec($script, $output, $returnvar); $result=exec($script, $output, $returnvar);
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
print __METHOD__." output=".join("\n",$output)."\n"; print __METHOD__." output=".join("\n",$output)."\n";
print __METHOD__." returnvar=".$returnvar."\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; return $result;
} }