diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php
index e4cc6a37c1c..3e790bf6448 100644
--- a/htdocs/comm/propal/list.php
+++ b/htdocs/comm/propal/list.php
@@ -1486,8 +1486,11 @@ if ($resql) {
) {
$with_margin_info = true;
}
+ $total_ht = 0;
+ $total_margin = 0;
- while ($i < min($num, $limit)) {
+ $last_num = min($num, $limit);
+ while ($i < $last_num) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->rowid;
@@ -1541,6 +1544,8 @@ if ($resql) {
if ($with_margin_info === true) {
$objectstatic->fetch_lines();
$marginInfo = $formmargin->getMarginInfosArray($objectstatic);
+ $total_ht += $obj->total_ht;
+ $total_margin += $marginInfo['total_margin'];
}
print '
';
@@ -1959,7 +1964,7 @@ if ($resql) {
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
}
- $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
+ $totalarray['val']['total_margin'] = $total_margin;
}
// Total margin rate
if (!empty($arrayfields['total_margin_rate']['checked'])) {
@@ -1974,6 +1979,16 @@ if ($resql) {
if (!$i) {
$totalarray['nbfield']++;
}
+ if (!$i) {
+ $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
+ }
+ if ($i >= $last_num - 1) {
+ if (!empty($total_ht)) {
+ $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
+ } else {
+ $totalarray['val']['total_mark_rate'] = '';
+ }
+ }
}
// Extra fields
diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index 35abd34728a..27391d7a901 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -1463,8 +1463,11 @@ if ($resql) {
) {
$with_margin_info = true;
}
+ $total_ht = 0;
+ $total_margin = 0;
- while ($i < min($num, $limit)) {
+ $last_num = min($num, $limit);
+ while ($i < $last_num) {
$obj = $db->fetch_object($resql);
$notshippable = 0;
@@ -1510,6 +1513,8 @@ if ($resql) {
if ($with_margin_info === true) {
$generic_commande->fetch_lines();
$marginInfo = $formmargin->getMarginInfosArray($generic_commande);
+ $total_ht += $obj->total_ht;
+ $total_margin += $marginInfo['total_margin'];
}
print '
';
@@ -1879,6 +1884,16 @@ if ($resql) {
if (!$i) {
$totalarray['nbfield']++;
}
+ if (!$i) {
+ $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
+ }
+ if ($i >= $last_num - 1) {
+ if (!empty($total_ht)) {
+ $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
+ } else {
+ $totalarray['val']['total_mark_rate'] = '';
+ }
+ }
}
// Extra fields
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 3e28fd05932..5914e37e425 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -1651,8 +1651,11 @@ if ($resql) {
) {
$with_margin_info = true;
}
+ $total_ht = 0;
+ $total_margin = 0;
- while ($i < min($num, $limit)) {
+ $last_num = min($num, $limit);
+ while ($i < $last_num) {
$obj = $db->fetch_object($resql);
$datelimit = $db->jdate($obj->datelimite);
@@ -1740,6 +1743,8 @@ if ($resql) {
if ($with_margin_info === true) {
$facturestatic->fetch_lines();
$marginInfo = $formmargin->getMarginInfosArray($facturestatic);
+ $total_ht += $obj->total_ht;
+ $total_margin += $marginInfo['total_margin'];
}
print '
= $last_num - 1) {
+ if (!empty($total_ht)) {
+ $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
+ } else {
+ $totalarray['val']['total_mark_rate'] = '';
+ }
+ }
}
// Extra fields