X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fquery_commod;h=153ea792c92e7f9abcc9eac7472d37c72bdb7fca;hp=052d019f998b137cd103f806c46bbbb0f3e0fd4a;hb=29010a75143814a91b4f5200454bea879280e7c1;hpb=2b6a88303ee81419e9583c4fc34e71f4e692a2e0 diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index 052d019..153ea79 100644 --- a/yarrg/web/query_commod +++ b/yarrg/web/query_commod @@ -36,6 +36,7 @@ <%args> $quri $dbh +$commodid => undef; $commodstring => ''; $prselector $someresults @@ -44,35 +45,23 @@ $emsgokorprint <%perl> my $emsg; -my ($commodname,$commodid); +my ($commodname,$cmid); my $qa= \%ARGS; +

Commodity enquiry

% $prselector->('BuySell'); % $prselector->('ShowBlank'); -%#---------- textbox, user enters route as string ---------- -% if (!$qa->{Dropdowns}) { - -Enter commodity (abbreviations are OK):
-
-<&| qtextstring, qa => $qa, dbh => $dbh, - thingstring => 'commodstring', emsgstore => \$emsg, - perresult => sub { ($commodname,$commodid)= @_; } +<& enter_commod, qa => $qa, dbh => $dbh, emsg_r => \$emsg, + commodname_r => \$commodname, + cmid_r => \$cmid &> - size=80 - - -% } else { #---------- dropdowns, user selects from menus ---------- - -Not yet implemented. - -% } #---------- end of dropdowns, now common middle of page code ---------- % my $ours= sub { $_[0] =~ m/^commodstring|^commodid/; }; @@ -81,30 +70,29 @@ Not yet implemented.
%#========== results ========== +
+
<%perl> -$emsgokorprint->($emsg) or $commodid=undef; -return unless defined $commodid; +$emsgokorprint->($emsg) or $cmid=undef; +return unless defined $cmid; $someresults->(); #---------- actually compute the results and print them ---------- -my $onloads= ""; - foreach my $bs (split /_/, $ARGS{BuySell}) { $bs =~ m/^(buy|sell)$/ or die; $bs= $1; my ($ascdesc) = ($bs eq 'buy') ? ('DESC') : ('ASC'); - my $joinkind= $ARGS{ShowBlank} eq 'show' - ? 'LEFT OUTER JOIN' : 'INNER JOIN'; + my $joinkind= $ARGS{ShowBlank} ? 'LEFT OUTER JOIN' : 'INNER JOIN'; my $islands= $dbh->prepare( "SELECT islands.islandid AS islandid, archipelago, islandname, sum(qty) as tqty FROM islands $joinkind $bs offers ON islands.islandid == offers.islandid AND commodid == ? - GROUP BY islands.islandid, + GROUP BY islands.islandid ORDER BY archipelago, islandname" ); @@ -114,15 +102,24 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { WHERE commodid = ? AND islandid = ? ORDER BY price $ascdesc" ); - # fixme this query is utterly wrong

Offers to <% uc $bs |h %> <% $commodname |h %>

- - +% $islands->execute($cmid); +% my $island; +% my %ts_sortkeys; +% my $rowix= 0; +% while ($island= $islands->fetchrow_hashref) { +% if (!$rowix) { +
++++ - @@ -135,12 +132,9 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { -% $islands->execute($commodid); -% my $island; -% my %ts_sortkeys; -% while ($island= $islands->fetchrow_hashref) { +% } % my $islandid= $island->{'islandid'}; -% $offers->execute($commodid, $islandid); +% $offers->execute($cmid, $islandid); % my ($offer, $bestprice, $marginal, @beststalls); % my $tqty= $island->{'tqty'}; % my $cqty= ''; @@ -179,25 +173,27 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { % $stallname= sprintf "%d offers", scalar @beststalls; % } % -% $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid "; - > +% $cqty == $tqty or die "$bs $cqty $tqty $cmid $islandid "; + class="<% 'datarow'.($rowix & 1) %>"> % for my $cix (0..$#$s) { % $ts_sortkeys{$cix}{$rowid}= $s->[$cix]; % } +% $rowix++; % } +% if ($rowix) {
+ + Prices Quantity at price
+/-10% Any
<% $s->[0]= $island->{'archipelago'} |h %> <% $s->[1]= $island->{'islandname'} |h %> <% $stallname |h %> - <% $s->[3]= (length $bestqty ? $bestprice : '-') %> - <% $s->[4]= $median %> - <% $s->[5]= $bestqty %> - <% $s->[6]= $approxqty %> - <% $s->[7]= $cqty %> + <% $s->[3]= (length $bestqty ? $bestprice : '-') %> + <% $s->[4]= $median %> + <% $s->[5]= $bestqty %> + <% $s->[6]= $approxqty %> + <% $s->[7]= $cqty %>
-<& tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys", - throw => "${bs}_table_thr", cols => [ +<&| tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys", + throw => "${bs}_table_thr", rowclass => 'datarow', cols => [ {}, {}, { DoReverse => 1 }, { DoReverse => 1, Numeric => 1, MapFn => "ts_Pricemap_${bs}" }, @@ -206,22 +202,16 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { { DoReverse => 1, Numeric => 1 }, { DoReverse => 1, Numeric => 1 }, ] &> -<&| script &> <% $bs %>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; function ts_Pricemap_<% $bs %>(price) { if (price=='-') { return <% $bs eq 'buy' ? '-1' : '99999999' %>; } return price; } - -% $onloads .= " ts_onload__${bs}_table();\n"; + +% } else { +No offers. +% } <%perl> } - -<&| script &> - function all_onload() { -<% $onloads %> - } - window.onload= all_onload; -