Fix "column totals" and "grand totals" in table reports

i18n
Vitaliy Filippov 2016-07-26 16:47:38 +03:00
parent d2646d08b5
commit 76be373f40
2 changed files with 12 additions and 4 deletions

View File

@ -262,7 +262,7 @@ foreach my $tbl (@tbl_names)
my @col_data; my @col_data;
foreach my $col (@col_names) foreach my $col (@col_names)
{ {
$data{$tbl}{$col}{$row} = $data{$tbl}{$col}{$row} || 0; $data{$tbl}{$col}{$row} ||= {};
push @col_data, $data{$tbl}{$col}{$row}; push @col_data, $data{$tbl}{$col}{$row};
if ($tbl ne "-total-") if ($tbl ne "-total-")
{ {
@ -270,7 +270,10 @@ foreach my $tbl (@tbl_names)
# building up the -total- data, and then last time round, # building up the -total- data, and then last time round,
# we process it as another tbl, and push() the total values # we process it as another tbl, and push() the total values
# into the image_data array. # into the image_data array.
$data{"-total-"}{$col}{$row} += $data{$tbl}{$col}{$row}; for my $m (keys %{$data{$tbl}{$col}{$row}})
{
$data{"-total-"}{$col}{$row}{$m} += $data{$tbl}{$col}{$row}{$m};
}
} }
} }
push @tbl_data, \@col_data; push @tbl_data, \@col_data;

View File

@ -99,10 +99,12 @@ END; %]
<td class="[% classes.$row_idx.$col_idx %]"> <td class="[% classes.$row_idx.$col_idx %]">
[% PROCESS value_display value = row field = row_field %] [% PROCESS value_display value = row field = row_field %]
</td> </td>
[% col_n = 0 %]
[% FOREACH col = col_names %] [% FOREACH col = col_names %]
[% col_idx = 1 - col_idx %] [% col_idx = 1 - col_idx %]
[% FOR m = mlist %] [% FOR m = mlist %]
[% col_totals.$col.$m = col_totals.$col.$m + data.$tbl.$col.$row.$m %] [%# Use numeric keys because fu*king Template::Stash produces double UTF-8 %]
[% col_totals.$col_n.$m = col_totals.$col_n.$m + data.$tbl.$col.$row.$m %]
[% row_total.$m = row_total.$m + data.$tbl.$col.$row.$m %] [% row_total.$m = row_total.$m + data.$tbl.$col.$row.$m %]
<td class="[% classes.$row_idx.$col_idx %]" align="center"> <td class="[% classes.$row_idx.$col_idx %]" align="center">
[% IF data.$tbl.$col.$row.$m AND data.$tbl.$col.$row.$m > 0 %] [% IF data.$tbl.$col.$row.$m AND data.$tbl.$col.$row.$m > 0 %]
@ -113,6 +115,7 @@ END; %]
[% END %] [% END %]
</td> </td>
[% END %] [% END %]
[% col_n = col_n + 1 %]
[% END %] [% END %]
[% IF col_names.size > 1 %] [% IF col_names.size > 1 %]
[% FOR m = mlist %] [% FOR m = mlist %]
@ -131,15 +134,17 @@ END; %]
<tr> <tr>
[% row_idx = 1 - row_idx %] [% row_idx = 1 - row_idx %]
<td class="ttotal">Total</td> <td class="ttotal">Total</td>
[% col_n = 0 %]
[% FOREACH col = col_names %] [% FOREACH col = col_names %]
[% FOR m = mlist %] [% FOR m = mlist %]
<td class="ttotal" align="center"> <td class="ttotal" align="center">
<a href="[% urlbase %]&amp; <a href="[% urlbase %]&amp;
[% PROCESS value_url value=col field=col_field %] [% PROCESS value_url value=col field=col_field %]
[% "&amp;$row_vals" IF row_vals %]"> [% "&amp;$row_vals" IF row_vals %]">
[% col_totals.$col.$m %]</a> [% col_totals.$col_n.$m %]</a>
</td> </td>
[% END %] [% END %]
[% col_n = col_n + 1 %]
[% END %] [% END %]
[% IF col_names.size > 1 %] [% IF col_names.size > 1 %]
[% FOR m = mlist %] [% FOR m = mlist %]