diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 2bd7e49d86d..6878efcd6ab 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -535,7 +535,7 @@ if (! empty($conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN)) { } $newelementforplusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN); foreach($newelementforplusmargin as $value) { - $listofreferent[$value]['margin']='add'; + $listofreferent[trim($value)]['margin']='add'; } } if (! empty($conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN)) { @@ -546,7 +546,7 @@ if (! empty($conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN)) { } $newelementforminusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN); foreach($newelementforminusmargin as $value) { - $listofreferent[$value]['margin']='minus'; + $listofreferent[trim($value)]['margin']='minus'; } } @@ -651,6 +651,8 @@ print ''.$langs->trans("AmountHT").''; print ''.$langs->trans("AmountTTC").''; print ''; +$total_revenue_ht = 0; + foreach ($listofreferent as $key => $value) { $name = $langs->trans($value['name']); @@ -780,7 +782,11 @@ foreach ($listofreferent as $key => $value) // Calculate margin if ($qualifiedforfinalprofit) { - if ($margin != "add") + if ($margin == 'add') { + $total_revenue_ht += $total_ht; + } + + if ($margin != "add") // Revert sign { $total_ht = -$total_ht; $total_ttc = -$total_ttc; @@ -811,11 +817,20 @@ foreach ($listofreferent as $key => $value) } // and the final balance print ''; -print ''.$langs->trans("Profit").''; -print ''.price(price2num($balance_ht, 'MT')).''; -print ''.price(price2num($balance_ttc, 'MT')).''; +print ''.$langs->trans("Profit").''; +print ''.price(price2num($balance_ht, 'MT')).''; +print ''.price(price2num($balance_ttc, 'MT')).''; print ''; +// and the margin (profit / revenues) +if ($total_revenue_ht) { + print ''; + print ''.$langs->trans("Margin").''; + print ''.price(price2num($balance_ht / $total_revenue_ht, 'MT')).''; + print ''; + print ''; +} + print "";