From 02f268ea4e233bac5ec4a4fbacb9ec4c9bec1014 Mon Sep 17 00:00:00 2001 From: John Botella Date: Tue, 11 Feb 2020 16:54:27 +0100 Subject: [PATCH] FIX - hasDelay for retained warranty --- htdocs/compta/facture/class/facture.class.php | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9172993acc7..9411f543f35 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4481,15 +4481,40 @@ class Facture extends CommonInvoice // Paid invoices have status STATUS_CLOSED if ($this->statut != Facture::STATUS_VALIDATED) return false; - return $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay); + $hasDelay = $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay); + if($hasDelay && !empty($this->retained_warranty) && !empty($this->retained_warranty_date_limit)) + { + $totalpaye = $this->getSommePaiement(); + $totalpaye = floatval($totalpaye); + $RetainedWarrantyAmount = $this->getRetainedWarrantyAmount(); + if($totalpaye >= 0 && $RetainedWarrantyAmount>= 0) + { + if( ($totalpaye < $this->total_ttc - $RetainedWarrantyAmount) && $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay) ) + { + $hasDelay = 1; + } + elseif($totalpaye < $this->total_ttc && $this->retained_warranty_date_limit < ($now - $conf->facture->client->warning_delay) ) + { + $hasDelay = 1; + } + else + { + $hasDelay = 0; + } + } + } + + return $hasDelay; } /** + * @param int $rounding Minimum number of decimal to show. If 0, no change, if -1, we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT) * @return number or -1 if not available */ - public function getRetainedWarrantyAmount() + public function getRetainedWarrantyAmount($rounding = -1) { + global $conf; if (empty($this->retained_warranty)) { return -1; } @@ -4533,6 +4558,11 @@ class Facture extends CommonInvoice $retainedWarrantyAmount = $this->total_ttc * $this->retained_warranty / 100; } + if ($rounding < 0){ + $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); + return round($retainedWarrantyAmount, 2); + } + return $retainedWarrantyAmount; }