chiark / gitweb /
Turn @columns=qw(..) into @cols=( {Name=>...}... )
[ypp-sc-tools.db-test.git] / yarrg / web / routetrade
index e200aa5cfd78e7643297dfb350f73f2320b0b640..ee15afbc1e98e6aa82f88f5bac22cda24d57d6c7 100644 (file)
@@ -142,16 +142,33 @@ 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
+       ));
 }
-push @columns,              qw(commodname
-                               org_price org_qty dst_price dst_qty
-                               unitprofit PctProfit
-                               MaxQty MaxCapital MaxProfit);
+$addcols->({ Text => 1 }, qw(commodname));
+$addcols->({},
+       qw(     org_qty org_price dst_qty dst_price
+               Margin unitprofit MaxQty
+       ));
+$addcols->({ Total => 1 }, qw(
+               MaxCapital MaxProfit
+       ));
 
 </%perl>
 
@@ -176,7 +193,7 @@ push @columns,                   qw(commodname
        $f->{MaxProfit}= $f->{MaxQty} * $f->{'unitprofit'};
        $f->{MaxCapital}= $f->{MaxQty} * $f->{'org_price'};
 
-       $f->{PctProfit}= sprintf "%3.1f%%",
+       $f->{Margin}= sprintf "%3.1f%%",
                $f->{'dst_price'} * 100.0 / $f->{'org_price'} - 100.0;
 
        $f->{"org_stallid"}= $f->{"dst_stallid"}= 'all'
@@ -364,7 +381,12 @@ if ($qa->{'debug'}) {
        die unless $found_section;
 };
 
-push @columns, qw(OptQty OptCapital OptProfit);
+$addcols->({}, qw(
+               OptQty
+       ));
+$addcols->({ Total => 1 }, qw(
+               OptCapital OptProfit
+       ));
 
 </%perl>
 
@@ -373,7 +395,18 @@ push @columns, qw(OptQty OptCapital OptProfit);
 % {
 %      my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';
 %      my $cdstall= $qa->{ShowStalls} ? '<th>Stall</th>' : '';
-<table>
+<table rules=groups>
+<colgroup span=1>
+<colgroup span=2>
+<% $qa->{ShowStalls} ? '<colgroup span=2>' : '' %>
+<colgroup span=1>
+<colgroup span=2>
+<colgroup span=2>
+<colgroup span=2>
+<colgroup span=3>
+%      if ($optimise) {
+<colgroup span=3>
+%      }
 <tr>
 <th>
 <th<% $cdspan %>>Collect
@@ -392,12 +425,12 @@ push @columns, qw(OptQty OptCapital OptProfit);
 <th>Island <% $cdstall %>
 <th>Island <% $cdstall %>
 <th>Commodity
-<th>Price
 <th>Qty
 <th>Price
 <th>Qty
-<th>Unit
+<th>Price
 <th>Margin
+<th>Unit
 <th>Qty
 <th>Capital
 <th>Profit
@@ -413,8 +446,11 @@ 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 $col (@columns) {
-<td><% $flow->{$col} |h %>
+%      foreach my $ci (0..$#cols) {
+%              my $col= $cols[$ci];
+%              my $v= $flow->{$col->{Name}};
+%              $v='' if !$col->{Text} && !$v;
+<td <% $col->{Text} ? '' : 'align=right' %>><% $v |h %>
 %      }
 % }
 </table>