Merge pull request #13084 from atm-john/11.0_fix_retained_warranty_hasdelay

FIX - hasDelay for retained warranty
This commit is contained in:
Laurent Destailleur 2020-02-12 18:22:53 +01:00 committed by GitHub
commit e9688e66c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}