From befdd967f79255c582b281389be6c9485f4b39cc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 Mar 2023 13:49:28 +0100 Subject: [PATCH] Fix margin calculation on credit not when price is 0 --- htdocs/core/class/html.formmargin.class.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.formmargin.class.php b/htdocs/core/class/html.formmargin.class.php index bf5233c0c6e..b4a24a94f9f 100644 --- a/htdocs/core/class/html.formmargin.class.php +++ b/htdocs/core/class/html.formmargin.class.php @@ -98,10 +98,15 @@ class FormMargin } $pv = $line->total_ht; - $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign - if (($object->element == 'facture' && $object->type == $object::TYPE_SITUATION) - || ($object->element == 'facture' && $object->type == $object::TYPE_CREDIT_NOTE && getDolGlobalInt('INVOICE_USE_SITUATION_CREDIT_NOTE') && $object->situation_counter > 0)) { - $pa = $line->qty * $pa_ht * ($line->situation_percent / 100); + $pa_ht = (($pv < 0 || ($pv == 0 && $object->type == $object::TYPE_CREDIT_NOTE)) ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign + if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { // Special case for old situation mode + if (($object->element == 'facture' && $object->type == $object::TYPE_SITUATION) + || ($object->element == 'facture' && $object->type == $object::TYPE_CREDIT_NOTE && getDolGlobalInt('INVOICE_USE_SITUATION_CREDIT_NOTE') && $object->situation_counter > 0)) { + // We need a compensation relative to $line->situation_percent + $pa = $line->qty * $pa_ht * ($line->situation_percent / 100); + } else { + $pa = $line->qty * $pa_ht; + } } else { $pa = $line->qty * $pa_ht; } @@ -213,7 +218,7 @@ class FormMargin $marginInfo = $this->getMarginInfosArray($object, $force_price); - $parameters=array('marginInfo'=>&$marginInfo); + $parameters=array('marginInfo' => &$marginInfo); $reshook = $hookmanager->executeHooks('displayMarginInfos', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -233,8 +238,8 @@ class FormMargin } } + print '' . "\n"; print '
'; - print '' . "\n"; print ''; print '';