Skip to content

Commit

Permalink
Fix Dolibarr#24031 add - if option seleced - grand total to lists
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaury committed Dec 29, 2023
1 parent bdaff37 commit d35b053
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 27 deletions.
9 changes: 8 additions & 1 deletion htdocs/admin/ihm.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);

dolibarr_set_const($db, "MAIN_SIZE_LISTE_LIMIT", GETPOST("MAIN_SIZE_LISTE_LIMIT", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_GRANDTOTAL_LIST_SHOW", GETPOST("MAIN_GRANDTOTAL_LIST_SHOW", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_SIZE_SHORTLIST_LIMIT", GETPOST("main_size_shortliste_limit", 'int'), 'chaine', 0, '', $conf->entity);


if (GETPOSTISSET("MAIN_CHECKBOX_LEFT_COLUMN")) {
dolibarr_set_const($db, "MAIN_CHECKBOX_LEFT_COLUMN", GETPOST("MAIN_CHECKBOX_LEFT_COLUMN", 'int'), 'chaine', 0, '', $conf->entity);
Expand Down Expand Up @@ -432,12 +434,17 @@
// Max size of lists
print '<tr class="oddeven"><td>' . $langs->trans("DefaultMaxSizeList") . '</td><td><input class="flat" name="MAIN_SIZE_LISTE_LIMIT" size="4" value="' . getDolGlobalString('MAIN_SIZE_LISTE_LIMIT') . '"></td>';
print '</tr>';

// Display grand total in list's footer
print '<tr class="oddeven"><td>' . $langs->trans("DisplayGrandTotalInList") . '</td><td>';
print ajax_constantonoff("MAIN_GRANDTOTAL_LIST_SHOW", array(), $conf->entity, 0, 0, 1, 0, 0, 0, '', 'other');
print '</td></tr>';

// Max size of short lists on customer card
print '<tr class="oddeven"><td>' . $langs->trans("DefaultMaxSizeShortList") . '</td><td><input class="flat" name="main_size_shortliste_limit" size="4" value="' . getDolGlobalString('MAIN_SIZE_SHORTLIST_LIMIT') . '"></td>';
print '</tr>';

// Max size of lists
// Display checkboxes and fields menu left / right
print '<tr class="oddeven"><td>' . $langs->trans("MAIN_CHECKBOX_LEFT_COLUMN") . '</td><td>';
print ajax_constantonoff("MAIN_CHECKBOX_LEFT_COLUMN", array(), $conf->entity, 0, 0, 1, 0, 0, 0, '', 'other');
print '</td>';
Expand Down
110 changes: 84 additions & 26 deletions htdocs/core/tpl/list_print_total.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,13 @@
}
// Show total line
if (isset($totalarray['pos'])) {
print '<tfoot>';
print '<tr class="liste_total">';
$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 '<td class="right">';
print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin') : 0);
print '</td>';
break;
case 'string': // This type is no more used. type is now varchar(x)
print '<td class="left">';
print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : '');
print '</td>';
break;
case 'stock':
print '<td class="right">';
print price2num(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0, 'MS');
print '</td>';
break;
default:
print '<td class="right">';
print price(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0);
print '</td>';
break;
}
printTotalValCell($totalarray['type'][$i], $totalarray['val'][$totalarray['pos'][$i]]);
} else {
if ($i == 1) {
if (is_null($limit) || $num < $limit) {
Expand All @@ -59,4 +35,86 @@
}
}
print '</tr>';
// 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 '<tr class="liste_grandtotal">';
$i = 0;
while ($i < $totalarray['nbfield']) {
$i++;
if (!empty($totalarray['pos'][$i])) {
printTotalValCell($totalarray['type'][$i], $sumsarray[$totalarray['pos'][$i]]);
} else {
if ($i == 1) {
print '<td>';
if (is_object($form)) {
print $form->textwithpicto($langs->trans("GrandTotal"), $langs->transnoentitiesnoconv("TotalforAllPages"));
} else {
print $langs->trans("GrandTotal");
}
print '</td>';
} else {
print '<td></td>';
}
}
}
print '</tr>';
}
}
}
print '</tfoot>';
}

/** 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 '<td class="right">';
print (!empty($val) ? convertSecondToTime($val, 'allhourmin') : 0);
print '</td>';
break;
case 'string': // This type is no more used. type is now varchar(x)
print '<td class="left">';
print (!empty($val) ? $val : '');
print '</td>';
break;
case 'stock':
print '<td class="right">';
print price2num(!empty($val) ? $val : 0, 'MS');
print '</td>';
break;
default:
print '<td class="right">';
print price(!empty($val) ? $val : 0);
print '</td>';
break;
}
}
1 change: 1 addition & 0 deletions htdocs/langs/en_US/admin.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/main.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/admin.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/fr_FR/main.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d35b053

Please sign in to comment.