extend order list filtering
authorTony Cook <tony@develop-help.com>
Sun, 22 Jan 2012 03:23:00 +0000 (14:23 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 22 Jan 2012 04:01:17 +0000 (15:01 +1100)
userId billEmail billFirstName billLastName billOrganization
  - supply any of these and they're substring matched against the order field
    so userId => "on" will match an order by "tony"

supply stage=>somestage for an exact match on that stage

supply stage=>stage1,stage2 (etc) to match any of those stages

supply name=>whatever for a substring match against any of userId,
billEmail, billFirstName, billLastName

add stage_select tag

MANIFEST
site/cgi-bin/modules/BSE/UI/AdminShop.pm
site/templates/admin/include/order_list_filter.tmpl [new file with mode: 0644]
site/templates/admin/order_list.tmpl
site/templates/admin/order_list_filled.tmpl
site/templates/admin/order_list_incomplete.tmpl
site/templates/admin/order_list_unfilled.tmpl

index 8e28b5d..12cfe09 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -531,6 +531,7 @@ site/templates/admin/include/article_menu.tmpl
 site/templates/admin/include/auditentry.tmpl
 site/templates/admin/include/audithead.tmpl
 site/templates/admin/include/edit_common.tmpl
+site/templates/admin/include/order_list_filter.tmpl
 site/templates/admin/include/order_list_pages.tmpl
 site/templates/admin/include/site_menu.tmpl
 site/templates/admin/interestemail.tmpl
index 53dcf5a..ee7db42 100644 (file)
@@ -19,7 +19,7 @@ use BSE::Util::HTML qw(:default popup_menu);
 use BSE::Arrows;
 use BSE::Shop::Util qw(:payment order_item_opts nice_options);
 
-our $VERSION = "1.008";
+our $VERSION = "1.009";
 
 my %actions =
   (
@@ -493,6 +493,32 @@ sub order_list_low {
     push @$conds,
       [ between => 'orderDate', $from, $to." 23:59:59" ];
   }
+
+  my @simple_search_fields = qw/userId billEmail billFirstName billLastName billOrganization/;
+  for my $key (@simple_search_fields) {
+    my $value = $cgi->param($key);
+    if (defined $value && $value =~ /\S/) {
+      push @$conds, [ like => $key => '%' . $value . '%' ];
+    }
+  }
+
+  my @stage = grep /\S/, map split (",", $_), $cgi->param("stage");
+  if (@stage) {
+    push @$conds,
+      [ or =>
+       map [ stage => $_ ], @stage
+      ];
+  }
+
+  my $name = $cgi->param("name");
+  if (defined $name && $name =~ /\S/) {
+    push @$conds,
+      [ or =>
+       map [ like => $_ => '%' . $name . '%' ],
+       qw(billFirstName billLastName billEmail userId)
+      ];
+  }
+
   my @ids = BSE::TB::Orders->getColumnBy
     (
      "id",
@@ -503,9 +529,8 @@ sub order_list_low {
   my $search_param;
   {
     my @param;
-    for my $key (qw(from to)) {
-      my $value = $cgi->param($key);
-      if (defined $value) {
+    for my $key (qw(from to stage name), @simple_search_fields) {
+      for my $value (grep /\S/, $cgi->param($key)) {
        push @param, "$key=" . escape_uri($value);
       }
     }
@@ -539,10 +564,40 @@ sub order_list_low {
      ifError => 0,
      all_order_count => \&tag_all_order_count,
      search_param => $search_param,
+     query => sub {
+       require JSON;
+       my $json = JSON->new;
+       return $json->encode($conds);
+     },
+     stage_select => [ \&tag_stage_select_search, $req ],
     );
   $req->dyn_response("admin/$template", \%acts);
 }
 
+=item tag stage_select (search)
+
+stage_select for order list filtering.
+
+=cut
+
+sub tag_stage_select_search {
+  my ($req) = @_;
+
+  my @stages = BSE::TB::Orders->settable_stages;
+  unshift @stages, "";
+  
+  my %stage_labels = BSE::TB::Orders->stage_labels;
+  $stage_labels{""} = "(No stage filter)";
+  my $stage = $req->cgi->param("stage") || "";
+  return popup_menu
+    (
+     -name => "stage",
+     -values => \@stages,
+     -default => $stage,
+     -labels => \%stage_labels,
+    );
+}
+
 sub iter_orders {
   my ($orders, $args) = @_;
 
diff --git a/site/templates/admin/include/order_list_filter.tmpl b/site/templates/admin/include/order_list_filter.tmpl
new file mode 100644 (file)
index 0000000..4165b3f
--- /dev/null
@@ -0,0 +1,11 @@
+            <form action="<:adminurl shopadmin:>">
+              <input type="hidden" name="a_<:param target:>" value="1" />
+              From date: 
+              <input type="text" size="10" name="from" value="<:cgi from:>" />
+              To date: 
+              <input type="text" size="10" name="to" value="<:cgi to:>" />
+             Name: <input type="text" name="name" value="<:cgi name:>" />
+             Email: <input type="text" name="emailAddress" value="<:cgi emailAddress:>" />
+             Stage: <:stage_select:>
+              <input type=submit value="Filter orders" name="submit" />
+            </form>
index 1a625c3..2e96bd0 100644 (file)
         </tr>
         <tr> 
           <td colspan="7"> 
-            <form action="<:adminurl shopadmin:>">
-              <input type="hidden" name="a_order_list" value="1" />
-              From date: 
-              <input type="text" size="10" name="from" value="<:cgi from:>" />
-              To date: 
-              <input type="text" size="10" name="to" value="<:cgi to:>" />
-              <input type=submit value="Filter orders" name="submit" />
-            </form>
+<:include admin/include/order_list_filter.tmpl:>
           </td>
         </tr>
         <:iterator begin orders:> 
@@ -46,3 +39,4 @@
         <:iterator end orders:> 
       </table>
 <:include admin/include/order_list_pages.tmpl:>
+<!-- <:query:> -->
\ No newline at end of file
index 8e4de5d..3a69303 100644 (file)
         </tr>
         <tr> 
           <td colspan="6"> 
-            <form action="<:adminurl shopadmin:>">
-             <input type="hidden" name="a_order_list_filled" value="1" />
-              From date: 
-              <input type="text" size="10" name="from" value="<:cgi from:>" />
-              To date: 
-              <input type="text" size="10" name="to" value="<:cgi to:>" />
-              <input type=submit value="Filter orders" name="submit" />
-            </form>
+<:include admin/include/order_list_filter.tmpl:>
           </td>
         </tr>
         <:iterator begin orders:> 
index b7141d5..ce5d439 100644 (file)
@@ -20,14 +20,7 @@ not be processed and are visible only for completeness.</b></p>
         </tr>
         <tr> 
           <td colspan="6"> 
-            <form action="<:adminurl shopadmin:>">
-              <input type="hidden" name="a_order_list_incomplete" value="1">
-              From date: 
-              <input type="text" size="10" name="from" value="<:cgi from:>">
-              To date: 
-              <input type="text" size="10" name="to" value="<:cgi to:>">
-              <input type=submit value="Filter orders" name="submit2">
-            </form>
+<:include admin/include/order_list_filter.tmpl:>
           </td>
         </tr>
         <:iterator begin orders:> 
index b687677..060c58d 100644 (file)
         </tr>
         <tr> 
           <td colspan="6"> 
-            <form action="<:adminurl shopadmin:>">
-             <input type="hidden" name="a_order_list_unfilled" value="1" />
-              From date: 
-              <input type="text" size="10" name="from" value="<:cgi from:>" />
-              To date: 
-              <input type="text" size="10" name="to" value="<:cgi to:>" />
-              <input type=submit value="Filter orders" name="submit2" />
-            </form>
+<:include admin/include/order_list_filter.tmpl:>
           </td>
         </tr>
         <:iterator begin orders filter= filled==0 :>