';
diff --git a/htdocs/core/tpl/list_print_total.tpl.php b/htdocs/core/tpl/list_print_total.tpl.php
index 88aff7cce8242..15a9be6ebb131 100644
--- a/htdocs/core/tpl/list_print_total.tpl.php
+++ b/htdocs/core/tpl/list_print_total.tpl.php
@@ -9,37 +9,13 @@
}
// Show total line
if (isset($totalarray['pos'])) {
+ print '
';
print '
';
$i = 0;
while ($i < $totalarray['nbfield']) {
$i++;
if (!empty($totalarray['pos'][$i])) {
- // if $totalarray['type'] not present we consider it as number
- if (empty($totalarray['type'][$i])) {
- $totalarray['type'][$i] = 'real';
- }
- switch ($totalarray['type'][$i]) {
- case 'duration':
- print '
';
+ // Add VMA : add grand total if necessary
+ if (getDolGlobalString('MAIN_GRANDTOTAL_LIST_SHOW') && (true || !(is_null($limit) || $num < $limit))) { // we print grand total only if different of page total already printed above
+ if (isset($totalarray['pos']) && is_array($totalarray['pos']) && count($totalarray['pos']) > 0) {
+ $sumsarray = false;
+ $tbsumfields = [];
+ foreach ($totalarray['pos'] as $field) {
+ $tbsumfields[] = "sum($field) as `$field`";
+ }
+ if (isset($sqlfields)) { // In project, commande list, this var is defined
+ $sqlforgrandtotal = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT '. implode(",", $tbsumfields), $sql);
+ } else {
+ $sqlforgrandtotal = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT '. implode(",", $tbsumfields). ' FROM ', $sql);
+ }
+ $sqlforgrandtotal = preg_replace('/GROUP BY .*$/', '', $sqlforgrandtotal). '';
+ //echo $sqlforgrandtotal;
+ $resql = $db->query($sqlforgrandtotal);
+ if ($resql) {
+ $sumsarray = $db->fetch_array($resql);
+ } else {
+ //dol_print_error($db); // as we're not sure it's ok for ALL lists, we don't print sq errors, they'll be in logs
+ }
+ if (is_array($sumsarray) && count($sumsarray) >0) {
+ // Show grand total line
+ print '
';
+ }
+ }
+ }
+ print '';
}
+
+/** print a total cell value according to its type
+ *
+ * @param string $type of field (duration, string..)
+ * @param string $val the value to display
+ */
+function printTotalValCell($type, $val) {
+ // if $totalarray['type'] not present we consider it as number
+ if (empty($type)) {
+ $type = 'real';
+ }
+ switch ($type) {
+ case 'duration':
+ print '
';
+ break;
+ }
+}
\ No newline at end of file
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 627d2d08a1f4e..d2ca53d4aecec 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1201,6 +1201,7 @@ Skin=Skin theme
DefaultSkin=Default skin theme
MaxSizeList=Max length for list
DefaultMaxSizeList=Default max length for lists
+DisplayGrandTotalInList=Display grand total (for all pages) in lists footer
DefaultMaxSizeShortList=Default max length for short lists (i.e. in customer card)
MessageOfDay=Message of the day
MessageLogin=Login page message
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 8c40379b67b7b..bee41a827bdac 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -420,6 +420,8 @@ TotalTTCShort=Total (inc. tax)
TotalHT=Total (excl. tax)
TotalHTforthispage=Total (excl. tax) for this page
Totalforthispage=Total for this page
+GrandTotal=Grand total
+TotalforAllPages=Total for all pages
TotalTTC=Total (inc. tax)
TotalTTCToYourCredit=Total (inc. tax) to your credit
TotalVAT=Total tax
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 94a4878fb1193..1f6d6d9364464 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -1201,6 +1201,7 @@ Skin=Thème visuel
DefaultSkin=Thème visuel par défaut
MaxSizeList=Longueur maximale des listes
DefaultMaxSizeList=Longueur maximale par défaut des listes
+DisplayGrandTotalInList=Affiche le total général (de toutes les pages) en bas des listes
DefaultMaxSizeShortList=Longueur maximale par défaut des listes courtes (e.g. dans la fiche client)
MessageOfDay=Message du jour
MessageLogin=Message page de connexion
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index 9019201c1bbba..98e74d35cb794 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -420,6 +420,8 @@ TotalTTCShort=Total TTC
TotalHT=Total HT
TotalHTforthispage=Montant (HT) pour la page
Totalforthispage=Total pour cette page
+GrandTotal=Total général
+TotalforAllPages=Total général de toutes les pages
TotalTTC=Total TTC
TotalTTCToYourCredit=Total TTC à votre crédit
TotalVAT=Total TVA