chiark / gitweb /
Do not break if no trades found
[ypp-sc-tools.main.git] / yarrg / web / routetrade
index 6fe34fee16d382e0eb0e954a2e9fa6f174f04e23..074069d2b71b38a64d68897e9d5868f0b156dced 100644 (file)
@@ -239,6 +239,12 @@ $addcols->({ DoReverse => 1 },
 % }
 
 <%perl>
+
+if (!@flows) {
+       print 'No profitable trading opportunities were found.';
+       return;
+}
+
 foreach my $f (@flows) {
 
        $f->{MaxQty}= $f->{'org_qty_agg'} < $f->{'dst_qty_agg'}
@@ -551,6 +557,7 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 % my $iquery= $dbh->prepare('SELECT islandname FROM islands
 %                              WHERE islandid = ?');
 % my %da_ages;
+% my $total_total= 0;
 %
 <h1>Voyage trading plan</h1>
 <table rules=groups>
@@ -647,25 +654,32 @@ Sail to <% $islandname |h %>
 %      }
 %    };
 %    my $show_total= sub {
-%      my ($totaldesc)= @_;
+%      my ($totaldesc, $sign)= @_;
 %      if (defined $total) {
 <tr>
 <td colspan=3>
 <td colspan=2 align=right><% $totaldesc %>
 <td align=right><% $total |h %> total
+%              $total_total += $sign * $total;
 %      }
 %      $total= undef;
 %      $dline= 0;
 <%perl>
      };
 
-     $show_flows->('dst',0,'Deliver');  $show_total->('Proceeds');
-     $show_flows->('org',1,'Collect');  $show_total->('(Arbitrage) outlay');
-     $show_flows->('dst',1,'Deliver');  $show_total->('(Arbitrage) proceeds');
-     $show_flows->('org',0,'Collect');  $show_total->('Outlay');
+     $show_flows->('dst',0,'Deliver'); $show_total->('Proceeds',1);
+     $show_flows->('org',1,'Collect'); $show_total->('(Arbitrage) outlay',-1);
+     $show_flows->('dst',1,'Deliver'); $show_total->('(Arbitrage) proceeds',1);
+     $show_flows->('org',0,'Collect'); $show_total->('Outlay',-1);
 
 }
 </%perl>
+<tbody><tr>
+<td colspan=2>
+<td colspan=3 align=right>Overall net cash flow
+<td align=right><strong><%
+  $total_total < 0 ? -$total_total." loss" : $total_total." gain"
+ %></strong>
 </table>
 <& query_age:dataages, id2age => \%da_ages &>
 %