From 23b11491d2729c1013c32622ac852bf5947332e1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Apr 2021 11:11:01 +0200 Subject: [PATCH] Can filter also on payment mode --- htdocs/compta/facture/class/facture.class.php | 23 ++++++++++++------- htdocs/core/modules/modFacture.class.php | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index fab7241b09f..7e0a8ff63b4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5610,11 +5610,12 @@ class FactureLigne extends CommonInvoiceLine * Send reminders by emails for ivoices that are due * CAN BE A CRON TASK * - * @param int $nbdays Delay after due date (or before if delay is negative) - * @param int $idtemplate Id or name of of email template (Must be a template of type 'invoice') - * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK) + * @param int $nbdays Delay after due date (or before if delay is negative) + * @param string $paymentmode '' or 'all' by default (no filter), or 'LIQ', 'CHQ', CB', ... + * @param int|string $idtemplate Id or name of of email template (Must be a template of type 'invoice') + * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK) */ - public function sendEmailsReminderOnDueDate($nbdays = 0, $idtemplate = 0) + public function sendEmailsReminderOnDueDate($nbdays = 0, $paymentmode = 'all', $idtemplate = '') { global $conf, $langs, $user; @@ -5653,10 +5654,16 @@ class FactureLigne extends CommonInvoiceLine $this->db->begin(); //Select all action comm reminder - $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE paye = 0"; - $sql .= " AND date_lim_reglement = '".$this->db->idate(dol_time_plus_duree($now, -1 * $nbdays, 'd'))."'"; // TODO Remove hours into filter - $sql .= " AND entity IN (".getEntity('facture').")"; + $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."facture as f"; + if (!empty($paymentmode) && $paymentmode != 'all') { + $sql .= ", ".MAIN_DB_PREFIX."c_paiement as cp"; + } + $sql .= " WHERE f.paye = 0"; + $sql .= " AND f.date_lim_reglement = '".$this->db->idate(dol_time_plus_duree($now, -1 * $nbdays, 'd'))."'"; // TODO Remove hours into filter + $sql .= " AND f.entity IN (".getEntity('facture').")"; + if (!empty($paymentmode) && $paymentmode != 'all') { + $sql .= " AND f.fk_mode_reglement = cp.id AND cp.code = '".$this->db->escape($paymentmode)."'"; + } // TODO Add filter to check there is no payment started $sql .= $this->db->order("date_lim_reglement", "ASC"); $resql = $this->db->query($sql); diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 49deaf598af..9b576e292e2 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -121,7 +121,7 @@ class modFacture extends DolibarrModules $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); $this->cronjobs = array( 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), - 1=>array('label'=>'SendEmailsRemindersOnDueDate', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture.class.php', 'objectname'=>'Facture', 'method'=>'sendEmailsReminderOnDueDate', 'parameters'=>'10,0', 'comment'=>'Send an emails when an unpaid invoice reach a due date + n days', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), + 1=>array('label'=>'SendEmailsRemindersOnDueDate', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture.class.php', 'objectname'=>'Facture', 'method'=>'sendEmailsReminderOnDueDate', 'parameters'=>"10,all,0", 'comment'=>'Send an emails when the unpaid invoices reach a due date + n days', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), ); // Permissions