dolibarr icon indicating copy to clipboard operation
dolibarr copied to clipboard

CRON for unpaid invoice reminders: mismatch between description of nbdays and actual behavior

Open atm-florianm opened this issue 5 months ago • 0 comments

Bug

Current description of the CRON job:

Send an emails when the unpaid invoices reach a due date + n days = today. First param is the offset n of days, second parameter is "all" or a payment mode code, last parameter is the code of email template to use (an email template with EmailTemplateCode must exists. the version in the language of the thirdparty will be used in priority).

Excerpt from Dolibarr 17 (this part hasn't fundamentally changed since):

$now = dol_now();
$tmpidate = dol_get_first_hour(dol_time_plus_duree($now, $nbdays, 'd'), 'gmt');
//[…]
$sql .= " AND f.date_lim_reglement = '".$this->db->idate($tmpidate, 'gmt')."'";

The behavior of $nbdays is the opposite of what the description says. This means e-mails meant for long overdue payments (e.g. 60 days) will be sent 60 days before payment is due if Dolibarr was configured according to the CRON description.

If we wanted to do what the description says (which is more intuitive for users, I think), the code should be:

$now = dol_get_first_hour(dol_now(), 'gmt');
//[…]
$sql .= " AND DATE_ADD(f.date_lim_reglement, ".intval($nbdays).") = '".$this->db->idate($now, 'gmt')."'";

However, changing this would impact all users who have already configured Dolibarr to fit their needs (disregarding the description). So maybe we should just change the doc to say:

Send an emails when the unpaid invoices reach a due date = today + n days. First param is the offset n of days, second parameter is "all" or a payment mode code, last parameter is the code of email template to use (an email template with EmailTemplateCode must exists. the version in the language of the thirdparty will be used in priority).

Dolibarr Version

17.0 through develop (older versions too maybe)

Environment PHP

any

Environment Database

any

Steps to reproduce the behavior and expected behavior

Assuming today's date is 2024-08-26 (adjust dates to fit the current date).

Create an invoice due 2024-08-19 for a customer whose invoicing contact has your e-mail address Set up the CRON job for D+7 (parameters: 7,all). Run the CRON job manually.

  • expected: e-mail received saying your payment is 7 days overdue
  • actual: no e-mail sent

Now create an invoice due 2024-09-02 for the same customer. Run the CRON job manually.

  • expected: no e-mail sent (because the deadline is still 7 days ahead)
  • actual: e-mail received saying your payment is 7 days overdue

Attached files

No response

atm-florianm avatar Aug 26 '24 15:08 atm-florianm