-% my $row;
-% while ($row=$sth->fetchrow_hashref) {
-<tr> <td><% $row->{'archipelago'} %>
- <td><% $row->{'islandname'} %>
- <td><% $row->{'stallname'} %>
- <td><% $row->{'price'} %>
- <td><% $row->{'qty'} %>
+% }
+% my $islandid= $island->{'islandid'};
+% $offers->execute($cmid, $islandid);
+% my ($offer, $bestprice, $marginal, @beststalls);
+% my $tqty= $island->{'tqty'};
+% my $cqty= '';
+% my $bestqty= '';
+% my $approxqty= '';
+% my $median= '-';
+% while ($offer= $offers->fetchrow_hashref) {
+% my $price= $offer->{'price'};
+% my $qty= $offer->{'qty'};
+% length $bestqty or $bestprice= $price;
+% if ($price == $bestprice) {
+% $bestqty += $qty;
+% push @beststalls, $offer->{'stallname'};
+% }
+% $cqty += $qty;
+% if ($cqty*2 >= $tqty && $median eq '-') {
+% $median= $price;
+% }
+% if ($bestprice*9 <= $price*10 and
+% $price*10 <= $bestprice*11) {
+% $approxqty += $qty;
+% }
+% }
+% my $stallname;
+%
+% my $rowid= "id_${bs}_$islandid";
+% my $s= [ ];
+%
+% $s->[2]= sprintf "%06d", scalar @beststalls;
+% if (!@beststalls) {
+% $stallname= '-';
+% } elsif (@beststalls==1) {
+% $stallname= $beststalls[0];
+% $s->[2] .= " $stallname";
+% } else {
+% $stallname= sprintf "%d offers", scalar @beststalls;
+% }
+%
+% $cqty == $tqty or die "$bs $cqty $tqty $cmid $islandid ";
+<tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>">
+ <td><% $s->[0]= $island->{'archipelago'} |h %>
+ <td><% $s->[1]= $island->{'islandname'} |h %>
+ <td><% $stallname |h %>
+ <td align=right><% $s->[3]= (length $bestqty ? $bestprice : '-') %>
+ <td align=right><% $s->[4]= $median %>
+ <td align=right><% $s->[5]= $bestqty %>
+ <td align=right><% $s->[6]= $approxqty %>
+ <td align=right><% $s->[7]= $cqty %>