From 116ff4a985a088e43fe75855adf44408987fe807 Mon Sep 17 00:00:00 2001 From: Kamel Khelifa Date: Mon, 27 Nov 2023 16:54:52 +0100 Subject: [PATCH] FIX: Fix when options FAC_FORCE_DATE_VALIDATION and INVOICE_CHECK_POSTERIOR_DATE enabled. The date is forced after the test and not before --- htdocs/compta/facture/card.php | 6 ++++++ htdocs/compta/facture/class/facture.class.php | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 2ccb6828f16..e9be3761efa 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -315,6 +315,12 @@ if (empty($reshook)) { // Validation $object->fetch($id); + if ((preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) && // empty should not happened, but when it occurs, the test save life + !empty($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date + ) { + $object->date = dol_now(); + } + if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) { $last_of_type = $object->willBeLastOfSameType(true); if (empty($object->date_validation) && !$last_of_type[0]) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d9e9bef3f73..869af987017 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3228,6 +3228,12 @@ class Facture extends CommonInvoice dol_syslog(get_class($this)."::validate ".$this->error.' MAIN_USE_ADVANCED_PERMS='.$conf->global->MAIN_USE_ADVANCED_PERMS, LOG_ERR); return -1; } + if ((preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) && // empty should not happened, but when it occurs, the test save life + !empty($conf->global->FAC_FORCE_DATE_VALIDATION) // If option enabled, we force invoice date + ) { + $this->date = dol_now(); + $this->date_lim_reglement = $this->calculate_date_lim_reglement(); + } if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) { $last_of_type = $this->willBeLastOfSameType(true); if (!$last_of_type[0]) { @@ -3340,10 +3346,6 @@ class Facture extends CommonInvoice if ($force_number) { $num = $force_number; } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life - if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) { // If option enabled, we force invoice date - $this->date = dol_now(); - $this->date_lim_reglement = $this->calculate_date_lim_reglement(); - } $num = $this->getNextNumRef($this->thirdparty); } else { $num = $this->ref;