chiark / gitweb /
Totals
[ypp-sc-tools.web-live.git] / yarrg / web / routetrade
index 45e0f8168703597babb20b9b2c7c5e1b8e75fa10..cb0ef9379e1a451ebbe3b5c3aff332794ada7850 100644 (file)
@@ -142,17 +142,31 @@ my $sth= $dbh->prepare($stmt);
 $sth->execute(@query_params);
 my @flows;
 
-my @columns;
+my @cols;
+
+my $addcols= sub {
+       my $base= shift @_;
+       foreach my $name (@_) {
+               push @cols, { Name => $name, %$base };
+       }
+};
+
 if ($qa->{ShowStalls}) {
-       push @columns,       qw(org_name org_stallname dst_name dst_stallname);
+       $addcols->({ Text => 1 }, qw(
+               org_name org_stallname
+               dst_name dst_stallname
+       ));
 } else {
-       push @columns,       qw(org_name dst_name);
+       $addcols->({Text => 1 }, qw(
+               org_name dst_name
+       ));
 }
-my $ntextcolumns= @columns+1;
-push @columns,              qw(commodname
-                               org_qty org_price dst_qty dst_price
-                               Margin unitprofit
-                               MaxQty MaxCapital MaxProfit);
+$addcols->({ Text => 1 }, qw(commodname));
+$addcols->({},
+       qw(     org_qty org_price dst_qty dst_price
+               Margin unitprofit MaxQty
+               MaxCapital MaxProfit
+       ));
 
 </%perl>
 
@@ -365,7 +379,12 @@ if ($qa->{'debug'}) {
        die unless $found_section;
 };
 
-push @columns, qw(OptQty OptCapital OptProfit);
+$addcols->({}, qw(
+               OptQty
+       ));
+$addcols->({ Total => 0 }, qw(
+               OptCapital OptProfit
+       ));
 
 </%perl>
 
@@ -425,12 +444,22 @@ push @columns, qw(OptQty OptCapital OptProfit);
 <td><input type=hidden   name=R<% $flow->{UidShort} %> value="">
     <input type=checkbox name=T<% $flow->{UidShort} %> value=""
        <% $flow->{Suppress} ? '' : 'checked' %> >
-%      foreach my $ci (0..$#columns) {
-%              my $col= $columns[$ci];
-%              my $v= $flow->{$col};
-%              my $isnum= $ci >= $ntextcolumns;
-%              $v='' if $isnum && !$v;
-<td <% $isnum ? 'align=right' : '' %>><% $v |h %>
+%      foreach my $ci (0..$#cols) {
+%              my $col= $cols[$ci];
+%              my $v= $flow->{$col->{Name}};
+%              $col->{Total} += $v if defined $col->{Total};
+%              $v='' if !$col->{Text} && !$v;
+<td <% $col->{Text} ? '' : 'align=right' %>><% $v |h %>
+%      }
+% }
+<tr>
+<th>
+<th colspan=2>Total
+% foreach my $ci (2..$#cols) {
+%      my $col= $cols[$ci];
+<td align=right>
+%      if (defined $col->{Total}) {
+<% $col->{Total} |h %>
 %      }
 % }
 </table>