@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | $langs->loadLangs(array("companies", "compta", "main", "accountancy")); |
33 | 33 | |
34 | 34 | // Security check |
35 | -if (!$user->admin) |
|
35 | +if (!$user->admin) { |
|
36 | 36 | accessforbidden(); |
37 | +} |
|
37 | 38 | |
38 | 39 | // Date range |
39 | 40 | $year = GETPOST("year"); |
@@ -50,9 +51,11 @@ discard block |
||
50 | 51 | $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); |
51 | 52 | |
52 | 53 | // Quarter |
53 | -if (empty($date_start) || empty($date_end)) // We define date_start and date_end |
|
54 | +if (empty($date_start) || empty($date_end)) { |
|
55 | + // We define date_start and date_end |
|
54 | 56 | { |
55 | 57 | $q = GETPOST("q") ? GETPOST("q") : 0; |
58 | +} |
|
56 | 59 | if ($q == 0) { |
57 | 60 | // We define date_start and date_end |
58 | 61 | $year_end = $year_start; |
@@ -63,12 +66,14 @@ discard block |
||
63 | 66 | $year_end --; |
64 | 67 | } |
65 | 68 | $month_end = $month_start - 1; |
66 | - if ($month_end < 1) |
|
67 | - $month_end = 12; |
|
68 | - else |
|
69 | - $year_end ++; |
|
70 | - } else |
|
71 | - $month_end = $month_start; |
|
69 | + if ($month_end < 1) { |
|
70 | + $month_end = 12; |
|
71 | + } else { |
|
72 | + $year_end ++; |
|
73 | + } |
|
74 | + } else { |
|
75 | + $month_end = $month_start; |
|
76 | + } |
|
72 | 77 | $date_start = dol_get_first_day($year_start, $month_start, false); |
73 | 78 | $date_end = dol_get_last_day($year_end, $month_end, false); |
74 | 79 | } |
@@ -126,11 +131,13 @@ discard block |
||
126 | 131 | $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp"; |
127 | 132 | $sql .= " WHERE f.fk_soc = s.rowid"; |
128 | 133 | $sql .= " AND s.fk_pays = cp.rowid"; |
129 | -if (! empty($date_start) && ! empty($date_end)) |
|
134 | +if (! empty($date_start) && ! empty($date_end)) { |
|
130 | 135 | $sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'"; |
136 | +} |
|
131 | 137 | $sql .= " AND f.entity = " . $conf->entity; |
132 | -if ($socid) |
|
138 | +if ($socid) { |
|
133 | 139 | $sql .= " AND f.fk_soc = " . $socid; |
140 | +} |
|
134 | 141 | $sql .= " GROUP BY name"; |
135 | 142 | $sql .= ")"; |
136 | 143 | $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , "; |
@@ -140,11 +147,13 @@ discard block |
||
140 | 147 | $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp"; |
141 | 148 | $sql .= " WHERE ff.fk_soc = s.rowid"; |
142 | 149 | $sql .= " AND s.fk_pays = cp.rowid"; |
143 | -if (! empty($date_start) && ! empty($date_end)) |
|
150 | +if (! empty($date_start) && ! empty($date_end)) { |
|
144 | 151 | $sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'"; |
152 | +} |
|
145 | 153 | $sql .= " AND ff.entity = " . $conf->entity; |
146 | -if ($socid) |
|
154 | +if ($socid) { |
|
147 | 155 | $sql .= " AND f.fk_soc = " . $socid; |
156 | +} |
|
148 | 157 | $sql .= " GROUP BY name"; |
149 | 158 | $sql .= ")"; |
150 | 159 |
@@ -23,11 +23,22 @@ discard block |
||
23 | 23 | * \ingroup cron |
24 | 24 | * \brief Execute pendings jobs |
25 | 25 | */ |
26 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal |
|
27 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); |
|
28 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); |
|
29 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
30 | -if (! defined('NOLOGIN')) define('NOLOGIN','1'); |
|
26 | +if (! defined('NOTOKENRENEWAL')) { |
|
27 | + define('NOTOKENRENEWAL','1'); |
|
28 | +} |
|
29 | +// Disables token renewal |
|
30 | +if (! defined('NOREQUIREMENU')) { |
|
31 | + define('NOREQUIREMENU','1'); |
|
32 | +} |
|
33 | +if (! defined('NOREQUIREHTML')) { |
|
34 | + define('NOREQUIREHTML','1'); |
|
35 | +} |
|
36 | +if (! defined('NOREQUIREAJAX')) { |
|
37 | + define('NOREQUIREAJAX','1'); |
|
38 | +} |
|
39 | +if (! defined('NOLOGIN')) { |
|
40 | + define('NOLOGIN','1'); |
|
41 | +} |
|
31 | 42 | //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); |
32 | 43 | |
33 | 44 | |
@@ -109,9 +120,10 @@ discard block |
||
109 | 120 | $userlogin = $obj->login; |
110 | 121 | echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n"; |
111 | 122 | } |
123 | + } else { |
|
124 | + dol_print_error($db); |
|
125 | + } |
|
112 | 126 | } |
113 | - else dol_print_error($db); |
|
114 | -} |
|
115 | 127 | |
116 | 128 | // Check user login |
117 | 129 | $user=new User($db); |
@@ -121,8 +133,7 @@ discard block |
||
121 | 133 | echo "User Error: ".$user->error; |
122 | 134 | dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR); |
123 | 135 | exit(-1); |
124 | -} |
|
125 | -else |
|
136 | +} else |
|
126 | 137 | { |
127 | 138 | if (empty($user->id)) |
128 | 139 | { |
@@ -164,7 +175,9 @@ discard block |
||
164 | 175 | $qualifiedjobs = array(); |
165 | 176 | foreach($object->lines as $val) |
166 | 177 | { |
167 | - if (! verifCond($val->test)) continue; |
|
178 | + if (! verifCond($val->test)) { |
|
179 | + continue; |
|
180 | + } |
|
168 | 181 | $qualifiedjobs[] = $val; |
169 | 182 | } |
170 | 183 | |
@@ -208,8 +221,7 @@ discard block |
||
208 | 221 | echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n"; |
209 | 222 | dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR); |
210 | 223 | $nbofjobslaunchedko++; |
211 | - } |
|
212 | - else |
|
224 | + } else |
|
213 | 225 | { |
214 | 226 | $nbofjobslaunchedok++; |
215 | 227 | } |
@@ -227,23 +239,23 @@ discard block |
||
227 | 239 | } |
228 | 240 | |
229 | 241 | echo " - reprogrammed\n"; |
230 | - } |
|
231 | - else |
|
242 | + } else |
|
232 | 243 | { |
233 | 244 | echo " - not qualified\n"; |
234 | 245 | |
235 | 246 | dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc')); |
236 | 247 | } |
237 | 248 | } |
238 | -} |
|
239 | -else |
|
249 | +} else |
|
240 | 250 | { |
241 | 251 | echo "cron_run_jobs.php no qualified job found\n"; |
242 | 252 | } |
243 | 253 | |
244 | 254 | $db->close(); |
245 | 255 | |
246 | -if ($nbofjobslaunchedko) exit(1); |
|
256 | +if ($nbofjobslaunchedko) { |
|
257 | + exit(1); |
|
258 | +} |
|
247 | 259 | exit(0); |
248 | 260 | |
249 | 261 |
@@ -61,8 +61,10 @@ discard block |
||
61 | 61 | |
62 | 62 | foreach($argv as $key => $val) |
63 | 63 | { |
64 | - if (preg_match('/-y$/',$val,$reg)) $confirmed=1; |
|
65 | -} |
|
64 | + if (preg_match('/-y$/',$val,$reg)) { |
|
65 | + $confirmed=1; |
|
66 | + } |
|
67 | + } |
|
66 | 68 | |
67 | 69 | $now=$argv[1]; |
68 | 70 | |
@@ -140,8 +142,7 @@ discard block |
||
140 | 142 | if ($result > 0) |
141 | 143 | { |
142 | 144 | print " - ".$langs->trans("OK"); |
143 | - } |
|
144 | - else |
|
145 | + } else |
|
145 | 146 | { |
146 | 147 | $error++; |
147 | 148 | print " - ".$langs->trans("KO").' - '.$ldap->error; |
@@ -153,8 +154,7 @@ discard block |
||
153 | 154 | |
154 | 155 | $ldap->unbind(); |
155 | 156 | $ldap->close(); |
156 | -} |
|
157 | -else |
|
157 | +} else |
|
158 | 158 | { |
159 | 159 | dol_print_error($db); |
160 | 160 | } |
@@ -78,11 +78,15 @@ |
||
78 | 78 | |
79 | 79 | $now=dol_now(); |
80 | 80 | $newmask = 0; |
81 | -if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
82 | -if (empty($newmask)) // This should no happen |
|
81 | +if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) { |
|
82 | + $newmask=$conf->global->MAIN_UMASK; |
|
83 | +} |
|
84 | +if (empty($newmask)) { |
|
85 | + // This should no happen |
|
83 | 86 | { |
84 | 87 | $newmask='0664'; |
85 | 88 | } |
89 | +} |
|
86 | 90 | |
87 | 91 | |
88 | 92 | /* |
@@ -73,11 +73,15 @@ discard block |
||
73 | 73 | |
74 | 74 | $now=dol_now(); |
75 | 75 | $newmask = 0; |
76 | -if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
77 | -if (empty($newmask)) // This should no happen |
|
76 | +if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) { |
|
77 | + $newmask=$conf->global->MAIN_UMASK; |
|
78 | +} |
|
79 | +if (empty($newmask)) { |
|
80 | + // This should no happen |
|
78 | 81 | { |
79 | 82 | $newmask='0664'; |
80 | 83 | } |
84 | +} |
|
81 | 85 | |
82 | 86 | |
83 | 87 | /* |
@@ -116,8 +120,7 @@ discard block |
||
116 | 120 | $langs->load("errors"); |
117 | 121 | print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n"; |
118 | 122 | exit(2); |
119 | - } |
|
120 | - else // $result == 0 |
|
123 | + } else // $result == 0 |
|
121 | 124 | { |
122 | 125 | print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n"; |
123 | 126 | } |
@@ -118,8 +118,7 @@ discard block |
||
118 | 118 | { |
119 | 119 | print "Failed to find bank account with ref ".$bankref.".\n"; |
120 | 120 | exit(-1); |
121 | -} |
|
122 | -else |
|
121 | +} else |
|
123 | 122 | { |
124 | 123 | print "Export for bank account ".$acct->ref." (".$acct->label.").\n"; |
125 | 124 | } |
@@ -177,7 +176,9 @@ discard block |
||
177 | 176 | $arraynum=explode(',',$num); |
178 | 177 | foreach($arraynum as $val) |
179 | 178 | { |
180 | - if ($listofnum != "'") $listofnum.="','"; |
|
179 | + if ($listofnum != "'") { |
|
180 | + $listofnum.="','"; |
|
181 | + } |
|
181 | 182 | $listofnum.=$val; |
182 | 183 | } |
183 | 184 | $listofnum.="'"; |
@@ -188,8 +189,12 @@ discard block |
||
188 | 189 | $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; |
189 | 190 | $sql.= ", ".MAIN_DB_PREFIX."bank as b"; |
190 | 191 | $sql.= " WHERE b.fk_account = ".$acct->id; |
191 | -if ($listofnum) $sql.= " AND b.num_releve IN (".$listofnum.")"; |
|
192 | -if (!isset($num)) $sql.= " OR b.num_releve is null"; |
|
192 | +if ($listofnum) { |
|
193 | + $sql.= " AND b.num_releve IN (".$listofnum.")"; |
|
194 | +} |
|
195 | +if (!isset($num)) { |
|
196 | + $sql.= " OR b.num_releve is null"; |
|
197 | +} |
|
193 | 198 | $sql.= " AND b.fk_account = ba.rowid"; |
194 | 199 | $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 |
195 | 200 | //print $sql; |
@@ -245,8 +250,7 @@ discard block |
||
245 | 250 | $obj2=$db->fetch_object($resql2); |
246 | 251 | $balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0); |
247 | 252 | $db->free($resql2); |
248 | - } |
|
249 | - else |
|
253 | + } else |
|
250 | 254 | { |
251 | 255 | dol_print_error($db); |
252 | 256 | exit(-1); |
@@ -272,8 +276,11 @@ discard block |
||
272 | 276 | // Libelle |
273 | 277 | $reg=array(); |
274 | 278 | preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction |
275 | - if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]); |
|
276 | - else $description=$objp->label; |
|
279 | + if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) { |
|
280 | + $description=$langs->transnoentitiesnoconv($reg[1]); |
|
281 | + } else { |
|
282 | + $description=$objp->label; |
|
283 | + } |
|
277 | 284 | |
278 | 285 | /* |
279 | 286 | * Ajout les liens (societe, company...) |
@@ -290,12 +297,13 @@ discard block |
||
290 | 297 | foreach($tmparray as $key => $val) |
291 | 298 | { |
292 | 299 | $invoicestatic->fetch($val); |
293 | - if ($accountelem) $accountelem.= ', '; |
|
300 | + if ($accountelem) { |
|
301 | + $accountelem.= ', '; |
|
302 | + } |
|
294 | 303 | $accountelem.=$invoicestatic->ref; |
295 | 304 | } |
296 | 305 | } |
297 | - } |
|
298 | - elseif ($links[$key]['type']=='payment_supplier') |
|
306 | + } elseif ($links[$key]['type']=='payment_supplier') |
|
299 | 307 | { |
300 | 308 | $paymentsupplierstatic->fetch($links[$key]['url_id']); |
301 | 309 | $tmparray=$paymentsupplierstatic->getBillsArray(''); |
@@ -304,29 +312,34 @@ discard block |
||
304 | 312 | foreach($tmparray as $key => $val) |
305 | 313 | { |
306 | 314 | $invoicesupplierstatic->fetch($val); |
307 | - if ($accountelem) $accountelem.= ', '; |
|
315 | + if ($accountelem) { |
|
316 | + $accountelem.= ', '; |
|
317 | + } |
|
308 | 318 | $accountelem.=$invoicesupplierstatic->ref; |
309 | 319 | } |
310 | 320 | } |
311 | - } |
|
312 | - elseif ($links[$key]['type']=='payment_sc') |
|
321 | + } elseif ($links[$key]['type']=='payment_sc') |
|
313 | 322 | { |
314 | 323 | $paymentsocialcontributionstatic->fetch($links[$key]['url_id']); |
315 | - if ($accountelem) $accountelem.= ', '; |
|
324 | + if ($accountelem) { |
|
325 | + $accountelem.= ', '; |
|
326 | + } |
|
316 | 327 | $accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref; |
317 | - } |
|
318 | - elseif ($links[$key]['type']=='payment_vat') |
|
328 | + } elseif ($links[$key]['type']=='payment_vat') |
|
319 | 329 | { |
320 | 330 | $paymentvatstatic->fetch($links[$key]['url_id']); |
321 | - if ($accountelem) $accountelem.= ', '; |
|
331 | + if ($accountelem) { |
|
332 | + $accountelem.= ', '; |
|
333 | + } |
|
322 | 334 | $accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref; |
323 | - } |
|
324 | - elseif ($links[$key]['type']=='banktransfert') |
|
335 | + } elseif ($links[$key]['type']=='banktransfert') |
|
325 | 336 | { |
326 | 337 | $comment=$outputlangs->transnoentitiesnoconv("Transfer"); |
327 | 338 | if ($objp->amount > 0) |
328 | 339 | { |
329 | - if ($comment) $comment.= ' '; |
|
340 | + if ($comment) { |
|
341 | + $comment.= ' '; |
|
342 | + } |
|
330 | 343 | $banklinestatic->fetch($links[$key]['url_id']); |
331 | 344 | $bankstatic->id=$banklinestatic->fk_account; |
332 | 345 | $bankstatic->label=$banklinestatic->bank_account_label; |
@@ -337,10 +350,11 @@ discard block |
||
337 | 350 | $bankstatic->label=$objp->bankref; |
338 | 351 | $comment.= $bankstatic->getNomUrl(1,''); |
339 | 352 | $comment.= ')'; |
340 | - } |
|
341 | - else |
|
353 | + } else |
|
342 | 354 | { |
343 | - if ($comment) $comment.= ' '; |
|
355 | + if ($comment) { |
|
356 | + $comment.= ' '; |
|
357 | + } |
|
344 | 358 | $bankstatic->id=$objp->bankid; |
345 | 359 | $bankstatic->label=$objp->bankref; |
346 | 360 | $comment.= ' ('.$langs->transnoentitiesnoconv("from").' '; |
@@ -352,16 +366,18 @@ discard block |
||
352 | 366 | $comment.= $bankstatic->getNomUrl(1,'transactions'); |
353 | 367 | $comment.= ')'; |
354 | 368 | } |
355 | - } |
|
356 | - elseif ($links[$key]['type']=='company') |
|
369 | + } elseif ($links[$key]['type']=='company') |
|
357 | 370 | { |
358 | - if ($thirdparty) $thirdparty.= ', '; |
|
371 | + if ($thirdparty) { |
|
372 | + $thirdparty.= ', '; |
|
373 | + } |
|
359 | 374 | $thirdparty.= dol_trunc($links[$key]['label'],24); |
360 | 375 | $newline=0; |
361 | - } |
|
362 | - elseif ($links[$key]['type']=='member') |
|
376 | + } elseif ($links[$key]['type']=='member') |
|
363 | 377 | { |
364 | - if ($thirdparty) $accountelem.= ', '; |
|
378 | + if ($thirdparty) { |
|
379 | + $accountelem.= ', '; |
|
380 | + } |
|
365 | 381 | $thirdparty.= $links[$key]['label']; |
366 | 382 | $newline=0; |
367 | 383 | } |
@@ -389,8 +405,7 @@ discard block |
||
389 | 405 | { |
390 | 406 | $totald = $totald + abs($objp->amount); |
391 | 407 | $debit=price2num($objp->amount * -1); |
392 | - } |
|
393 | - else |
|
408 | + } else |
|
394 | 409 | { |
395 | 410 | $totalc = $totalc + abs($objp->amount); |
396 | 411 | $credit=price2num($objp->amount); |
@@ -430,15 +445,13 @@ discard block |
||
430 | 445 | print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n"; |
431 | 446 | |
432 | 447 | $ret=0; |
433 | - } |
|
434 | - else |
|
448 | + } else |
|
435 | 449 | { |
436 | 450 | print "No records found for receipt ".$num."\n"; |
437 | 451 | |
438 | 452 | $ret=0; |
439 | 453 | } |
440 | -} |
|
441 | -else |
|
454 | +} else |
|
442 | 455 | { |
443 | 456 | dol_print_error($db); |
444 | 457 | $ret=-1; |
@@ -75,22 +75,36 @@ discard block |
||
75 | 75 | $error = 0; |
76 | 76 | 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"; |
77 | 77 | |
78 | -if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
78 | +if ($mode != 'confirm') { |
|
79 | + $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
80 | +} |
|
79 | 81 | |
80 | 82 | $sql = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,"; |
81 | 83 | $sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang"; |
82 | -if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail"; |
|
84 | +if ($targettype == 'contacts') { |
|
85 | + $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail"; |
|
86 | +} |
|
83 | 87 | $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s"; |
84 | -if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp"; |
|
88 | +if ($targettype == 'contacts') { |
|
89 | + $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp"; |
|
90 | +} |
|
85 | 91 | $sql .= ", ".MAIN_DB_PREFIX."contrat AS c"; |
86 | 92 | $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd"; |
87 | 93 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product"; |
88 | 94 | $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5"; |
89 | -if (is_numeric($duration_value2)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'"; |
|
90 | -if (is_numeric($duration_value)) $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; |
|
91 | -if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc"; |
|
95 | +if (is_numeric($duration_value2)) { |
|
96 | + $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'"; |
|
97 | +} |
|
98 | +if (is_numeric($duration_value)) { |
|
99 | + $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; |
|
100 | +} |
|
101 | +if ($targettype == 'contacts') { |
|
102 | + $sql.= " AND s.rowid = sp.fk_soc"; |
|
103 | +} |
|
92 | 104 | $sql.= " ORDER BY"; |
93 | -if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,"; |
|
105 | +if ($targettype == 'contacts') { |
|
106 | + $sql.= " sp.email, sp.rowid,"; |
|
107 | +} |
|
94 | 108 | $sql.= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email |
95 | 109 | |
96 | 110 | //print $sql; |
@@ -117,9 +131,15 @@ discard block |
||
117 | 131 | |
118 | 132 | // Check if this record is a break after previous one |
119 | 133 | $startbreak=false; |
120 | - if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true; |
|
121 | - if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true; |
|
122 | - if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true; |
|
134 | + if ($newemail <> $oldemail || $oldemail == 'none') { |
|
135 | + $startbreak=true; |
|
136 | + } |
|
137 | + if ($obj->sid && $obj->sid <> $oldsid) { |
|
138 | + $startbreak=true; |
|
139 | + } |
|
140 | + if ($obj->cid && $obj->cid <> $oldcid) { |
|
141 | + $startbreak=true; |
|
142 | + } |
|
123 | 143 | |
124 | 144 | if ($startbreak) |
125 | 145 | { |
@@ -128,13 +148,15 @@ discard block |
||
128 | 148 | { |
129 | 149 | envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value); |
130 | 150 | $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; |
131 | - } |
|
132 | - else |
|
151 | + } else |
|
133 | 152 | { |
134 | 153 | if ($oldemail != 'none') |
135 | 154 | { |
136 | - if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n"; |
|
137 | - else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; |
|
155 | + if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { |
|
156 | + print "- No email sent for '".$oldtarget."', total: ".$total."\n"; |
|
157 | + } else { |
|
158 | + print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; |
|
159 | + } |
|
138 | 160 | } |
139 | 161 | } |
140 | 162 | $oldemail = $newemail; |
@@ -163,8 +185,11 @@ discard block |
||
163 | 185 | $foundtoprocess++; |
164 | 186 | } |
165 | 187 | 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.": "; |
166 | - if (dol_strlen($newemail)) print "qualified."; |
|
167 | - else print "disqualified (no email)."; |
|
188 | + if (dol_strlen($newemail)) { |
|
189 | + print "qualified."; |
|
190 | + } else { |
|
191 | + print "disqualified (no email)."; |
|
192 | + } |
|
168 | 193 | print "\n"; |
169 | 194 | |
170 | 195 | unset($outputlangs); |
@@ -177,29 +202,31 @@ discard block |
||
177 | 202 | // Si il reste des envois en buffer |
178 | 203 | if ($foundtoprocess) |
179 | 204 | { |
180 | - if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email) |
|
205 | + if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { |
|
206 | + // Break onto email (new email) |
|
181 | 207 | { |
182 | 208 | envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value); |
183 | - $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; |
|
184 | 209 | } |
185 | - else |
|
210 | + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; |
|
211 | + } else |
|
186 | 212 | { |
187 | 213 | if ($oldemail != 'none') |
188 | 214 | { |
189 | - if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n"; |
|
190 | - else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; |
|
215 | + if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { |
|
216 | + print "- No email sent for '".$oldtarget."', total: ".$total."\n"; |
|
217 | + } else { |
|
218 | + print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; |
|
219 | + } |
|
191 | 220 | } |
192 | 221 | } |
193 | 222 | } |
194 | - } |
|
195 | - else |
|
223 | + } else |
|
196 | 224 | { |
197 | 225 | print "No services to expire found\n"; |
198 | 226 | } |
199 | 227 | |
200 | 228 | exit(0); |
201 | -} |
|
202 | -else |
|
229 | +} else |
|
203 | 230 | { |
204 | 231 | dol_print_error($db); |
205 | 232 | dol_syslog("email_expire_services_to_customers.php: Error"); |
@@ -224,7 +251,9 @@ discard block |
||
224 | 251 | { |
225 | 252 | global $conf,$langs; |
226 | 253 | |
227 | - if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO'); |
|
254 | + if (getenv('DOL_FORCE_EMAIL_TO')) { |
|
255 | + $oldemail=getenv('DOL_FORCE_EMAIL_TO'); |
|
256 | + } |
|
228 | 257 | |
229 | 258 | $newlangs=new Translate('',$conf); |
230 | 259 | $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); |
@@ -233,11 +262,14 @@ discard block |
||
233 | 262 | |
234 | 263 | if ($duration_value) |
235 | 264 | { |
236 | - if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); |
|
237 | - else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); |
|
265 | + if ($duration_value > 0) { |
|
266 | + $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); |
|
267 | + } else { |
|
268 | + $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); |
|
269 | + } |
|
270 | + } else { |
|
271 | + $title= $newlangs->transnoentities("ListOfServicesToExpire"); |
|
238 | 272 | } |
239 | - else |
|
240 | - $title= $newlangs->transnoentities("ListOfServicesToExpire"); |
|
241 | 273 | |
242 | 274 | $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT); |
243 | 275 | $sendto = $oldemail; |
@@ -249,15 +281,18 @@ discard block |
||
249 | 281 | dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail); |
250 | 282 | |
251 | 283 | $usehtml=0; |
252 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1; |
|
253 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml+=1; |
|
284 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) { |
|
285 | + $usehtml+=1; |
|
286 | + } |
|
287 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) { |
|
288 | + $usehtml+=1; |
|
289 | + } |
|
254 | 290 | |
255 | 291 | $allmessage=''; |
256 | 292 | if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) |
257 | 293 | { |
258 | 294 | $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER; |
259 | - } |
|
260 | - else |
|
295 | + } else |
|
261 | 296 | { |
262 | 297 | $allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); |
263 | 298 | $allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); |
@@ -267,7 +302,9 @@ discard block |
||
267 | 302 | if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) |
268 | 303 | { |
269 | 304 | $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER; |
270 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1; |
|
305 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) { |
|
306 | + $usehtml+=1; |
|
307 | + } |
|
271 | 308 | } |
272 | 309 | |
273 | 310 | $mail = new CMailFile( |
@@ -295,8 +332,7 @@ discard block |
||
295 | 332 | print "Error sending email ".$mail->error."\n"; |
296 | 333 | dol_syslog("Error sending email ".$mail->error."\n"); |
297 | 334 | } |
298 | - } |
|
299 | - else |
|
335 | + } else |
|
300 | 336 | { |
301 | 337 | print "No email sent (test mode)\n"; |
302 | 338 | dol_syslog("No email sent (test mode)"); |
@@ -308,8 +344,7 @@ discard block |
||
308 | 344 | if ($result) |
309 | 345 | { |
310 | 346 | return 1; |
311 | - } |
|
312 | - else |
|
347 | + } else |
|
313 | 348 | { |
314 | 349 | return -1; |
315 | 350 | } |
@@ -71,14 +71,18 @@ discard block |
||
71 | 71 | |
72 | 72 | print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n"; |
73 | 73 | |
74 | -if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
74 | +if ($mode != 'confirm') { |
|
75 | + $conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
76 | +} |
|
75 | 77 | |
76 | 78 | $sql = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,"; |
77 | 79 | $sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; |
78 | 80 | $sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd"; |
79 | 81 | $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"; |
80 | 82 | $sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5"; |
81 | -if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; |
|
83 | +if (is_numeric($duration_value)) { |
|
84 | + $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; |
|
85 | +} |
|
82 | 86 | $sql.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid"; |
83 | 87 | $sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email |
84 | 88 | |
@@ -106,10 +110,11 @@ discard block |
||
106 | 110 | if (dol_strlen($oldemail) && $oldemail != 'none') |
107 | 111 | { |
108 | 112 | envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value); |
109 | - } |
|
110 | - else |
|
113 | + } else |
|
111 | 114 | { |
112 | - if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; |
|
115 | + if ($oldemail != 'none') { |
|
116 | + print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; |
|
117 | + } |
|
113 | 118 | } |
114 | 119 | $oldemail = $obj->email; |
115 | 120 | $olduid = $obj->uid; |
@@ -119,7 +124,9 @@ discard block |
||
119 | 124 | $total = 0; |
120 | 125 | $foundtoprocess = 0; |
121 | 126 | $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname); |
122 | - if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n"; |
|
127 | + if (empty($obj->email)) { |
|
128 | + print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n"; |
|
129 | + } |
|
123 | 130 | } |
124 | 131 | |
125 | 132 | // Define line content |
@@ -136,8 +143,11 @@ discard block |
||
136 | 143 | $foundtoprocess++; |
137 | 144 | } |
138 | 145 | 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."): "; |
139 | - if (dol_strlen($obj->email)) print "qualified."; |
|
140 | - else print "disqualified (no email)."; |
|
146 | + if (dol_strlen($obj->email)) { |
|
147 | + print "qualified."; |
|
148 | + } else { |
|
149 | + print "disqualified (no email)."; |
|
150 | + } |
|
141 | 151 | print "\n"; |
142 | 152 | |
143 | 153 | unset($outputlangs); |
@@ -149,24 +159,25 @@ discard block |
||
149 | 159 | // Si il reste des envois en buffer |
150 | 160 | if ($foundtoprocess) |
151 | 161 | { |
152 | - if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email) |
|
162 | + if (dol_strlen($oldemail) && $oldemail != 'none') { |
|
163 | + // Break onto email (new email) |
|
153 | 164 | { |
154 | 165 | envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value); |
155 | 166 | } |
156 | - else |
|
167 | + } else |
|
157 | 168 | { |
158 | - if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; |
|
169 | + if ($oldemail != 'none') { |
|
170 | + print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; |
|
171 | + } |
|
159 | 172 | } |
160 | 173 | } |
161 | - } |
|
162 | - else |
|
174 | + } else |
|
163 | 175 | { |
164 | 176 | print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n"; |
165 | 177 | } |
166 | 178 | |
167 | 179 | exit(0); |
168 | -} |
|
169 | -else |
|
180 | +} else |
|
170 | 181 | { |
171 | 182 | dol_print_error($db); |
172 | 183 | dol_syslog("email_expire_services_to_representatives.php: Error"); |
@@ -191,7 +202,9 @@ discard block |
||
191 | 202 | { |
192 | 203 | global $conf,$langs; |
193 | 204 | |
194 | - if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO'); |
|
205 | + if (getenv('DOL_FORCE_EMAIL_TO')) { |
|
206 | + $oldemail=getenv('DOL_FORCE_EMAIL_TO'); |
|
207 | + } |
|
195 | 208 | |
196 | 209 | $newlangs=new Translate('',$conf); |
197 | 210 | $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); |
@@ -200,11 +213,14 @@ discard block |
||
200 | 213 | |
201 | 214 | if ($duration_value) |
202 | 215 | { |
203 | - if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); |
|
204 | - else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); |
|
216 | + if ($duration_value > 0) { |
|
217 | + $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); |
|
218 | + } else { |
|
219 | + $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value); |
|
220 | + } |
|
221 | + } else { |
|
222 | + $title= $newlangs->transnoentities("ListOfServicesToExpire"); |
|
205 | 223 | } |
206 | - else |
|
207 | - $title= $newlangs->transnoentities("ListOfServicesToExpire"); |
|
208 | 224 | |
209 | 225 | $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT); |
210 | 226 | $sendto = $oldemail; |
@@ -216,15 +232,18 @@ discard block |
||
216 | 232 | dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail); |
217 | 233 | |
218 | 234 | $usehtml=0; |
219 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1; |
|
220 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1; |
|
235 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) { |
|
236 | + $usehtml+=1; |
|
237 | + } |
|
238 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) { |
|
239 | + $usehtml+=1; |
|
240 | + } |
|
221 | 241 | |
222 | 242 | $allmessage=''; |
223 | 243 | if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) |
224 | 244 | { |
225 | 245 | $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER; |
226 | - } |
|
227 | - else |
|
246 | + } else |
|
228 | 247 | { |
229 | 248 | $allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); |
230 | 249 | $allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n"); |
@@ -234,7 +253,9 @@ discard block |
||
234 | 253 | if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) |
235 | 254 | { |
236 | 255 | $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER; |
237 | - if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1; |
|
256 | + if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) { |
|
257 | + $usehtml+=1; |
|
258 | + } |
|
238 | 259 | } |
239 | 260 | |
240 | 261 | $mail = new CMailFile( |
@@ -262,8 +283,7 @@ discard block |
||
262 | 283 | print "Error sending email ".$mail->error."\n"; |
263 | 284 | dol_syslog("Error sending email ".$mail->error."\n"); |
264 | 285 | } |
265 | - } |
|
266 | - else |
|
286 | + } else |
|
267 | 287 | { |
268 | 288 | print "No email sent (test mode)\n"; |
269 | 289 | dol_syslog("No email sent (test mode)"); |
@@ -274,8 +294,7 @@ discard block |
||
274 | 294 | if ($result) |
275 | 295 | { |
276 | 296 | return 1; |
277 | - } |
|
278 | - else |
|
297 | + } else |
|
279 | 298 | { |
280 | 299 | return -1; |
281 | 300 | } |
@@ -250,8 +250,7 @@ |
||
250 | 250 | { |
251 | 251 | $error=0; |
252 | 252 | print '--- end ok'."\n"; |
253 | -} |
|
254 | -else |
|
253 | +} else |
|
255 | 254 | { |
256 | 255 | $error=$result; |
257 | 256 | print '--- end error code='.$error."\n"; |