24'@phan-var-force array{nbfield:int,type?:array<int,string>,pos?:array<int,int>,val?:array<int,float>} $totalarray';
25'@phan-var-force ?int $limit';
27if (!function_exists(
'printTotalValCell')) {
36 function printTotalValCell($type, $val)
44 print
'<td class="right">';
49 print
'<td class="left">';
50 print(!empty($val) ? $val :
'');
54 print
'<td class="right">';
55 print
price2num(!empty($val) ? $val : 0,
'MS');
59 print
'<td class="right">';
60 print
price(!empty($val) ? $val : 0);
68if (!empty($totalarray[
'totalizable']) && is_array($totalarray[
'totalizable'])) {
69 foreach ($totalarray[
'totalizable'] as $keytotalizable => $valtotalizable) {
70 $totalarray[
'pos'][$valtotalizable[
'pos']] = $keytotalizable;
71 $totalarray[
'val'][$keytotalizable] = isset($valtotalizable[
'total']) ? $valtotalizable[
'total'] : 0;
75if (isset($totalarray[
'pos'])) {
77 print
'<tr class="liste_total">';
79 while ($i < $totalarray[
'nbfield']) {
81 if (!empty($totalarray[
'pos'][$i])) {
82 printTotalValCell($totalarray[
'type'][$i] ??
'', empty($totalarray[
'val'][$totalarray[
'pos'][$i]]) ? 0 : $totalarray[
'val'][$totalarray[
'pos'][$i]]);
85 if ((!isset($limit) || $num < $limit) && empty($offset)) {
86 print
'<td>'.$langs->trans(
"Total").
'</td>';
89 if (is_object($form)) {
90 print $form->textwithpicto($langs->trans(
"Total"), $langs->transnoentitiesnoconv(
"Totalforthispage"));
92 print $langs->trans(
"Totalforthispage");
103 if (
getDolGlobalString(
'MAIN_GRANDTOTAL_LIST_SHOW') && (!(is_null($limit) || $num < $limit))) {
104 if (isset($totalarray[
'pos']) && is_array($totalarray[
'pos']) && count($totalarray[
'pos']) > 0) {
107 foreach ($totalarray[
'pos'] as $field) {
108 $fieldforsum = preg_replace(
'/[^a-z0-9]/',
'', $field);
109 $tbsumfields[] =
"sum($field) as $fieldforsum";
111 if (isset($sqlfields)) {
112 $sqlforgrandtotal = preg_replace(
'/^'.preg_quote($sqlfields,
'/').
'/',
'SELECT '. implode(
",", $tbsumfields), $sql);
114 $sqlforgrandtotal = preg_replace(
'/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/',
'SELECT '. implode(
",", $tbsumfields).
' FROM ', $sql);
116 $sqlforgrandtotal = preg_replace(
'/GROUP BY .*$/',
'', $sqlforgrandtotal).
'';
117 $resql = $db->query($sqlforgrandtotal);
119 $sumsarray = $db->fetch_array($resql);
123 if (is_array($sumsarray) && count($sumsarray) > 0) {
124 print
'<tr class="liste_grandtotal">';
126 while ($i < $totalarray[
'nbfield']) {
128 if (!empty($totalarray[
'pos'][$i])) {
129 $fieldname = preg_replace(
'/[^a-z0-9]/',
'', $totalarray[
'pos'][$i]);
130 printTotalValCell($totalarray[
'type'][$i], $sumsarray[$fieldname]);
134 if (is_object($form)) {
135 print $form->textwithpicto($langs->trans(
"GrandTotal"), $langs->transnoentitiesnoconv(
"TotalforAllPages"));
137 print $langs->trans(
"GrandTotal");
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.