chiark / gitweb /
Rationalise various ids
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 12:32:47 +0000 (13:32 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 23 Aug 2009 12:32:47 +0000 (13:32 +0100)
yarrg/web/routetrade

index 0edcca5..597f9ee 100644 (file)
@@ -162,14 +162,39 @@ push @columns,                 qw(commodname
 </pre>
 % }
 
-% {
 <& dumptable:start, qa => $qa, sth => $sth &>
-%   my $flow;
-%   while ($flow= $sth->fetchrow_hashref()) {
-%      $flow->{Ix}= @flows;
-%      $flow->{Var}= "f$flow->{Ix}";
-%      push @flows, $flow;
-<& dumptable:row, qa => $qa, sth => $sth, row => $flow &>
+% {
+%   my $f;
+%   while ($f= $sth->fetchrow_hashref()) {
+<%perl>
+
+       $f->{Ix}= @flows;
+       $f->{Var}= "f$f->{Ix}";
+
+       $f->{MaxQty}= $f->{'org_qty'} < $f->{'dst_qty'}
+               ? $f->{'org_qty'} : $f->{'dst_qty'};
+       $f->{MaxProfit}= $f->{MaxQty} * $f->{'unitprofit'};
+       $f->{MaxCapital}= $f->{MaxQty} * $f->{'org_price'};
+
+       $f->{PctProfit}= sprintf "%3.1f%%",
+               $f->{'dst_price'} * 100.0 / $f->{'org_price'} - 100.0;
+
+       $f->{"org_stallid"}= $f->{"dst_stallid"}= 'all'
+               if !$qa->{ShowStalls};
+
+       my @uid= $f->{commodid};
+       foreach my $od (qw(org dst)) {
+               push @uid,
+                       $f->{"${od}_id"},
+                       $f->{"${od}_price"},
+                       $f->{"${od}_stallid"};
+       }
+       $f->{Uid}= join '_', @uid;
+
+       push @flows, $f;
+
+</%perl>
+<& dumptable:row, qa => $qa, sth => $sth, row => $f &>
 %   }
 <& dumptable:end, qa => $qa &>
 % }
@@ -206,12 +231,15 @@ Subject To
 my %avail_csts;
 foreach my $flow (@flows) {
        foreach my $od (qw(org dst)) {
-               my $cstname= join '_',
+               my $cstname= join '_', (
                        'avail',
                        $flow->{'commodid'},
                        $od,
                        $flow->{"${od}_id"},
-                       $flow->{"${od}_price"};
+                       $flow->{"${od}_price"},
+                       $flow->{"${od}_stallid"},
+               );
+                       
                push @{ $avail_csts{$cstname}{Flows} }, $flow->{Var};
                $avail_csts{$cstname}{Qty}= $flow->{"${od}_qty"};
        }
@@ -319,13 +347,6 @@ push @columns, qw(OptQty OptCapital OptProfit);
 % foreach my $flow (@flows) {
 <tr>
 %      foreach my $col (@columns) {
-%              $flow->{MaxQty}= $flow->{'org_qty'} < $flow->{'dst_qty'}
-%                      ? $flow->{'org_qty'} : $flow->{'dst_qty'};
-%              $flow->{MaxProfit}= $flow->{MaxQty} * $flow->{'unitprofit'};
-%              $flow->{PctProfit}= sprintf "%3.1f%%",
-%                      $flow->{'dst_price'} * 100.0 / $flow->{'org_price'}
-%                      - 100.0;
-%              $flow->{MaxCapital}= $flow->{MaxQty} * $flow->{'org_price'};
 <td><% $flow->{$col} |h %>
 %      }
 % }