chiark / gitweb /
WIP trade plan
[ypp-sc-tools.db-live.git] / yarrg / web / routetrade
index ee15afbc1e98e6aa82f88f5bac22cda24d57d6c7..6bc7277d341a69049358dbb40176700657674187 100644 (file)
@@ -165,8 +165,6 @@ $addcols->({ Text => 1 }, qw(commodname));
 $addcols->({},
        qw(     org_qty org_price dst_qty dst_price
                Margin unitprofit MaxQty
-       ));
-$addcols->({ Total => 1 }, qw(
                MaxCapital MaxProfit
        ));
 
@@ -384,7 +382,7 @@ if ($qa->{'debug'}) {
 $addcols->({}, qw(
                OptQty
        ));
-$addcols->({ Total => 1 }, qw(
+$addcols->({ Total => 0 }, qw(
                OptCapital OptProfit
        ));
 
@@ -449,14 +447,60 @@ $addcols->({ Total => 1 }, qw(
 %      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>
 
 <input type=submit name=update value="Update">
 
+% if ($optimise) { # ========== TRADING PLAN ==========
+%
+% my $iquery= $dbh->prepare('SELECT islandname FROM islands
+%                              WHERE islandid = ?');
+%
+<h1>Voyage trading plan</h1>
+<table>
+% foreach my $i (0..$#islandids) {
+<tr><td colspan=4><strong>
+%      $iquery->execute($islandids[$i]);
+%      my ($islandname) = $iquery->fetchrow_array();
+%      if (!$i) {
+Start at <% $islandname |h %>
+%      } else {
+Sail to <% $islandname |h %>
+%      }
+</strong>
+%    foreach my $od (qw(dst org)) {
+%      my $sign= $od eq 'dst' ? -1 : +1;
+%      foreach my $f (sort {
+%                      $a->{'commodname'} cmp $b->{'commodname'}
+%              or $sign * ($a->{"${od}_price"} <=> $b->{"${od}_price"})
+%              or      $a->{"${od}_stallname"} cmp $b->{"${od}_stallname"}
+%              } @flows) {
+%              next if $f->{Suppress};
+%              next unless $f->{"${od}_id"} == $islandids[$i];
+%              next unless $f->{OptQty};
+<tr>Buy or sell flow 
+%      }
+%    }
+% }
+</table>
+%
+% } # ========== TRADING PLAN ==========
+
 <%init>
 use CommodsWeb;
 use Commods;