Skip to content

Commit

Permalink
add new rule
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic34 committed Feb 28, 2021
1 parent 1b046f2 commit 63dad7f
Show file tree
Hide file tree
Showing 23 changed files with 354 additions and 192 deletions.
35 changes: 22 additions & 13 deletions scripts/accountancy/export-thirdpartyaccount.php
Expand Up @@ -25,7 +25,9 @@
* \brief Page to detect empty accounting account
*/

if (!defined('NOSESSION')) define('NOSESSION', '1');
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}

$path = __DIR__.'/';

Expand All @@ -36,8 +38,9 @@
$langs->loadLangs(array("companies", "compta", "main", "accountancy"));

// Security check
if (!$user->admin)
if (!$user->admin) {
accessforbidden();
}

// Date range
$year = GETPOST("year");
Expand All @@ -54,8 +57,7 @@
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);

// Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$q = GETPOST("q") ? GETPOST("q") : 0;
if ($q == 0) {
// We define date_start and date_end
Expand All @@ -67,10 +69,14 @@
$year_end--;
}
$month_end = $month_start - 1;
if ($month_end < 1)
if ($month_end < 1) {
$month_end = 12;
else $year_end++;
} else $month_end = $month_start;
} else {
$year_end++;
}
} else {
$month_end = $month_start;
}
$date_start = dol_get_first_day($year_start, $month_start, false);
$date_end = dol_get_last_day($year_end, $month_end, false);
}
Expand Down Expand Up @@ -128,11 +134,13 @@ function launch_export()
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid";
if (!empty($date_start) && !empty($date_end))
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
}
$sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
if ($socid)
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$sql .= " GROUP BY name";
$sql .= ")";
$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
Expand All @@ -142,11 +150,13 @@ function launch_export()
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
$sql .= " WHERE ff.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid";
if (!empty($date_start) && !empty($date_end))
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
}
$sql .= " AND ff.entity = ".$conf->entity;
if ($socid)
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$sql .= " GROUP BY name";
$sql .= ")";

Expand Down Expand Up @@ -200,8 +210,7 @@ function launch_export()
print '<td class="left">'.$langs->trans("Phone").'</td>';
print '<td class="left">'.$langs->trans("Fax").'</td></tr>';

while ($obj = $db->fetch_object($resql))
{
while ($obj = $db->fetch_object($resql)) {
print '<tr class="oddeven">';
print '<td>';
$thirdpartystatic->id = $obj->rowid;
Expand Down
19 changes: 13 additions & 6 deletions scripts/bank/export-bank-receipts.php
Expand Up @@ -23,7 +23,9 @@
* \brief Script file to export bank receipts into Excel files
*/

if (!defined('NOSESSION')) define('NOSESSION', '1');
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}

$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
Expand Down Expand Up @@ -154,8 +156,9 @@
$listofnum .= "'";
$arraynum = explode(',', $num);
foreach ($arraynum as $val) {
if ($listofnum != "'")
if ($listofnum != "'") {
$listofnum .= "','";
}
$listofnum .= $val;
}
$listofnum .= "'";
Expand All @@ -166,10 +169,12 @@
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= ", ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE b.fk_account = ".$acct->id;
if ($listofnum)
if ($listofnum) {
$sql .= " AND b.num_releve IN (".$listofnum.")";
if (!isset($num))
}
if (!isset($num)) {
$sql .= " OR b.num_releve is null";
}
$sql .= " AND b.fk_account = ba.rowid";
$sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
// print $sql;
Expand Down Expand Up @@ -242,9 +247,11 @@
// Libelle
$reg = array();
preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1])
if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) {
$description = $langs->transnoentitiesnoconv($reg[1]);
else $description = $objp->label;
} else {
$description = $objp->label;
}

/*
* Ajout les liens (societe, company...)
Expand Down
7 changes: 5 additions & 2 deletions scripts/company/sync_contacts_dolibarr2ldap.php
Expand Up @@ -24,7 +24,9 @@
* \brief Script to update all contacts from Dolibarr into a LDAP database
*/

if (!defined('NOSESSION')) define('NOSESSION', '1');
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}

$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
Expand Down Expand Up @@ -60,8 +62,9 @@
}

foreach ($argv as $key => $val) {
if (preg_match('/-y$/', $val, $reg))
if (preg_match('/-y$/', $val, $reg)) {
$confirmed = 1;
}
}

$now = $argv[1];
Expand Down
65 changes: 43 additions & 22 deletions scripts/contracts/email_expire_services_to_customers.php
Expand Up @@ -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__);
Expand Down Expand Up @@ -80,24 +82,30 @@

$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;
Expand Down Expand Up @@ -145,9 +153,11 @@
$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;
Expand Down Expand Up @@ -176,9 +186,11 @@
$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);
Expand All @@ -190,15 +202,16 @@

// 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";
}
}
}
}
Expand Down Expand Up @@ -230,19 +243,24 @@ 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);
$newlangs->load("main");
$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;
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down

0 comments on commit 63dad7f

Please sign in to comment.