FIX Profit calculation on project preview tab.

This commit is contained in:
Laurent Destailleur 2023-02-15 17:57:19 +01:00
parent 3278b7bc86
commit b57d1ed263

View File

@ -581,9 +581,9 @@ $listofreferent = array(
'name'=>"MouvementStockAssociated", 'name'=>"MouvementStockAssociated",
'title'=>"ListMouvementStockProject", 'title'=>"ListMouvementStockProject",
'class'=>'MouvementStock', 'class'=>'MouvementStock',
'margin'=>'minus',
'table'=>'stock_mouvement', 'table'=>'stock_mouvement',
'datefieldname'=>'datem', 'datefieldname'=>'datem',
'margin'=>'minus',
'disableamount'=>0, 'disableamount'=>0,
'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && !empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))), 'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && !empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))),
'salaries'=>array( 'salaries'=>array(
@ -749,6 +749,7 @@ $total_revenue_ht = 0;
$balance_ht = 0; $balance_ht = 0;
$balance_ttc = 0; $balance_ttc = 0;
// Loop on each element type (proposal, sale order, invoices, ...)
foreach ($listofreferent as $key => $value) { foreach ($listofreferent as $key => $value) {
$parameters = array( $parameters = array(
'total_revenue_ht' =>& $total_revenue_ht, 'total_revenue_ht' =>& $total_revenue_ht,
@ -784,6 +785,7 @@ foreach ($listofreferent as $key => $value) {
$total_ht = 0; $total_ht = 0;
$total_ttc = 0; $total_ttc = 0;
// Loop on each object for the current element type
$num = count($elementarray); $num = count($elementarray);
for ($i = 0; $i < $num; $i++) { for ($i = 0; $i < $num; $i++) {
$tmp = explode('_', $elementarray[$i]); $tmp = explode('_', $elementarray[$i]);
@ -889,19 +891,14 @@ foreach ($listofreferent as $key => $value) {
} }
// Each element with at least one line is output // 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 // Calculate margin
if ($qualifiedforfinalprofit) { if ($margin) {
if ($margin == 'add') { if ($margin === 'add') {
$total_revenue_ht += $total_ht; $total_revenue_ht += $total_ht;
} }
if ($margin != "add") { // Revert sign if ($margin === "minus") { // Revert sign
$total_ht = -$total_ht; $total_ht = -$total_ht;
$total_ttc = -$total_ttc; $total_ttc = -$total_ttc;
} }
@ -920,10 +917,10 @@ foreach ($listofreferent as $key => $value) {
if ($key == 'intervention' && !$qualifiedforfinalprofit) { if ($key == 'intervention' && !$qualifiedforfinalprofit) {
print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>'; print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
} else { } else {
print price($total_ht);
if ($key == 'propal') { if ($key == 'propal') {
print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>'; print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
} }
print price($total_ht);
} }
print '</td>'; print '</td>';
// Amount TTC // Amount TTC
@ -931,10 +928,10 @@ foreach ($listofreferent as $key => $value) {
if ($key == 'intervention' && !$qualifiedforfinalprofit) { if ($key == 'intervention' && !$qualifiedforfinalprofit) {
print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>'; print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
} else { } else {
print price($total_ttc);
if ($key == 'propal') { if ($key == 'propal') {
print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>'; print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
} }
print price($total_ttc);
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';