From 1b925ec53f152585ffba83cab3ca387f4e60c034 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 Feb 2023 17:57:19 +0100 Subject: [PATCH] FIX Profit calculation on project preview tab. --- htdocs/projet/element.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 16b67dd4876..858e64cfced 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -584,9 +584,9 @@ $listofreferent = array( 'name'=>"MouvementStockAssociated", 'title'=>"ListMouvementStockProject", 'class'=>'MouvementStock', - 'margin'=>'minus', 'table'=>'stock_mouvement', 'datefieldname'=>'datem', + 'margin'=>'minus', 'disableamount'=>0, 'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && !empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))), 'salaries'=>array( @@ -752,6 +752,7 @@ $total_revenue_ht = 0; $balance_ht = 0; $balance_ttc = 0; +// Loop on each element type (proposal, sale order, invoices, ...) foreach ($listofreferent as $key => $value) { $parameters = array( 'total_revenue_ht' =>& $total_revenue_ht, @@ -787,6 +788,7 @@ foreach ($listofreferent as $key => $value) { $total_ht = 0; $total_ttc = 0; + // Loop on each object for the current element type $num = count($elementarray); for ($i = 0; $i < $num; $i++) { $tmp = explode('_', $elementarray[$i]); @@ -871,7 +873,7 @@ foreach ($listofreferent as $key => $value) { $defaultvat = get_default_tva($mysoc, $mysoc); $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT'); } elseif ($key == 'loan') { - $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr + $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr } else { $total_ttc_by_line = $element->total_ttc; } @@ -892,19 +894,14 @@ foreach ($listofreferent as $key => $value) { } // Each element with at least one line is output - $qualifiedforfinalprofit = true; - if ($key == 'intervention' && empty($conf->global->PROJECT_INCLUDE_INTERVENTION_AMOUNT_IN_PROFIT)) { - $qualifiedforfinalprofit = false; - } - //var_dump($key.' '.$qualifiedforfinalprofit); // Calculate margin - if ($qualifiedforfinalprofit) { - if ($margin == 'add') { + if ($margin) { + if ($margin === 'add') { $total_revenue_ht += $total_ht; } - if ($margin != "add") { // Revert sign + if ($margin === "minus") { // Revert sign $total_ht = -$total_ht; $total_ttc = -$total_ttc; } @@ -923,10 +920,10 @@ foreach ($listofreferent as $key => $value) { if ($key == 'intervention' && !$qualifiedforfinalprofit) { print ''.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).''; } else { - print price($total_ht); if ($key == 'propal') { print ''.$form->textwithpicto('', $langs->trans("SignedOnly")).''; } + print price($total_ht); } print ''; // Amount TTC @@ -934,10 +931,10 @@ foreach ($listofreferent as $key => $value) { if ($key == 'intervention' && !$qualifiedforfinalprofit) { print ''.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).''; } else { - print price($total_ttc); if ($key == 'propal') { print ''.$form->textwithpicto('', $langs->trans("SignedOnly")).''; } + print price($total_ttc); } print ''; print '';