re-work order lists
authorTony Cook <tony@develop-help.com>
Sun, 22 Jan 2012 01:30:37 +0000 (12:30 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 22 Jan 2012 04:01:11 +0000 (15:01 +1100)
MANIFEST
site/cgi-bin/modules/BSE/UI/AdminShop.pm
site/templates/admin/include/order_list_pages.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 1284527..8e28b5d 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_pages.tmpl
 site/templates/admin/include/site_menu.tmpl
 site/templates/admin/interestemail.tmpl
 site/templates/admin/locations/add.tmpl
index 283b5b6..53dcf5a 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.007";
+our $VERSION = "1.008";
 
 my %actions =
   (
@@ -426,14 +426,44 @@ sub product_form {
   return $req->dyn_response($template, \%acts);
 }
 
+=item tag all_order_count
+X<tags, shop admin, all_order_count>C<all_order_count>
+
+Returns a count of orders matching a set of conditions.
+
+=cut
+
+sub tag_all_order_count {
+  my ($args, $acts, $funcname, $templater) = @_;
+
+  my $query;
+  if ($args =~ /\S/) {
+    if (eval "\$query = [ $args ]; 1 ") {
+      return BSE::TB::Orders->getCount($query);
+    }
+    else {
+      return "<!-- error handling args: $@ -->";
+    }
+  }
+  else {
+    return BSE::TB::Orders->getCount();
+  }
+}
+
 #####################
 # order management
 
 sub order_list_low {
-  my ($req, $template, $title, @orders) = @_;
+  my ($req, $template, $title, $conds, $options) = @_;
 
   my $cgi = $req->cgi;
 
+  $options ||= {};
+  my $order = delete $options->{order};
+  defined $order or $order = 'id desc';
+  my $datelimit = delete $options->{datelimit};
+  defined $datelimit or $datelimit = 1;
+
   my $from = $cgi->param('from');
   my $to = $cgi->param('to');
   use BSE::Util::SQL qw/now_sqldate sql_to_date date_to_sql sql_date/;
@@ -452,42 +482,63 @@ sub order_list_low {
       }
     }
   }
-  $from ||= sql_date(time() - 30 * 86_400);
-  my $message = $cgi->param('m');
-  defined $message or $message = '';
-  $message = escape_html($message);
+  if ($datelimit) {
+    $from ||= sql_date(time() - 30 * 86_400);
+  }
   if (defined $from || defined $to) {
     $from ||= '1900-01-01';
     $to ||= '2999-12-31';
     $cgi->param('from', sql_to_date($from));
     $cgi->param('to', sql_to_date($to));
-    $to = $to."Z";
-    @orders = grep $from le $_->{orderDate} && $_->{orderDate} le $to,
-    @orders;
+    push @$conds,
+      [ between => 'orderDate', $from, $to." 23:59:59" ];
   }
-  my @orders_work;
-  my $order_index = -1;
+  my @ids = BSE::TB::Orders->getColumnBy
+    (
+     "id",
+     $conds,
+     { order => $order }
+    );
+
+  my $search_param;
+  {
+    my @param;
+    for my $key (qw(from to)) {
+      my $value = $cgi->param($key);
+      if (defined $value) {
+       push @param, "$key=" . escape_uri($value);
+      }
+    }
+    $search_param = join('&amp;', map escape_html($_), @param);
+  }
+
+  my $message = $cgi->param('m');
+  defined $message or $message = '';
+  $message = escape_html($message);
+
+  my $it = BSE::Util::Iterate::Objects->new;
   my %acts;
   %acts =
     (
-     BSE::Util::Tags->basic(\%acts, $cgi, $req->cfg),
-     BSE::Util::Tags->admin(\%acts, $req->cfg),
-     BSE::Util::Tags->secure($req),
-     #order=> sub { escape_html($orders_work[$order_index]{$_[0]}) },
-     DevHelp::Tags->make_iterator2
-     ( [ \&iter_orders, \@orders ],
-       'order', 'orders', \@orders_work, \$order_index, 'NoCache'),
-     script => sub { $ENV{SCRIPT_NAME} },
+     $req->admin_tags,
+     $it->make_paged
+     (
+      data => \@ids,
+      fetch => [ getByPkey => 'BSE::TB::Orders' ],
+      cgi => $req->cgi,
+      single => "order",
+      plural => "orders",
+      session => $req->session,
+      name => "orderlist",
+      perpage_parm => "pp=50",
+     ),
      title => sub { $title },
      ifHaveParam => sub { defined $cgi->param($_[0]) },
      ifParam => sub { $cgi->param($_[0]) },
-     cgi => 
-     sub { 
-       my $value = $cgi->param($_[0]);
-       defined $value or $value = '';
-       escape_html($value);
-     },
      message => $message,
+     ifError => 0,
+     all_order_count => \&tag_all_order_count,
+     search_param => $search_param,
     );
   $req->dyn_response("admin/$template", \%acts);
 }
@@ -498,62 +549,111 @@ sub iter_orders {
   return bse_sort({ id => 'n', total => 'n', filled=>'n' }, $args, @$orders);
 }
 
+=item target order_list
+X<shopadmin targets, order_list>X<order_list target>
+
+List all completed orders.
+
+By default limits to the last 30 days.
+
+=cut
+
 sub req_order_list {
   my ($class, $req) = @_;
 
-  my $orders = BSE::TB::Orders->new;
-  my @orders = sort { $b->{orderDate} cmp $a->{orderDate} } 
-    grep $_->{complete}, $orders->all;
   my $template = $req->cgi->param('template');
   unless (defined $template && $template =~ /^\w+$/) {
     $template = 'order_list';
   }
 
-  return order_list_low($req, $template, 'Order list', @orders);
+  my @conds = 
+    (
+     [ '<>', complete => 0 ],
+    );
+
+  return order_list_low($req, $template, 'Order list', \@conds);
 }
 
+=item target order_list_filled
+X<shopadmin targets, order_list_filled>X<order_list_filled target>
+
+List all filled orders.
+
+By default limits to the last 30 days.
+
+=cut
+
 sub req_order_list_filled {
   my ($class, $req) = @_;
 
-  my $orders = BSE::TB::Orders->new;
-  my @orders = sort { $b->{orderDate} cmp $a->{orderDate} } 
-    grep $_->{complete} && $_->{filled} && $_->{paidFor}, $orders->all;
+  my @conds =
+    (
+     [ '<>', complete => 0 ],
+     [ '<>', filled => 0 ],
+     #[ '<>', paidFor => 0 ],
+    );
 
-  return order_list_low($req, 'order_list_filled', 'Order list - Filled orders', @orders);
+  return order_list_low($req, 'order_list_filled', 'Order list - Filled orders',
+                      \@conds);
 }
 
+=item target order_list_unfilled
+X<shopadmin targets, order_list_unfilled>X<order_list_unfilled target>
+
+List completed but unfilled orders.
+
+Unlike the other order lists, this lists oldest order first, and does
+not limit to the last 30 days.
+
+=cut
+
 sub req_order_list_unfilled {
   my ($class, $req) = @_;
 
-  my $orders = BSE::TB::Orders->new;
-  my @orders = sort { $b->{orderDate} cmp $a->{orderDate} } 
-    grep $_->{complete} && !$_->{filled} && $_->{paidFor}, $orders->all;
+  my @conds =
+    (
+     [ '<>', complete => 0 ],
+     [ filled => 0 ],
+    );
 
   return order_list_low($req, 'order_list_unfilled', 
-                       'Order list - Unfilled orders', @orders);
-
+                       'Order list - Unfilled orders',
+                       \@conds, { order => 'id asc', datelimit => 0 });
 }
 
 sub req_order_list_unpaid {
   my ($class, $req) = @_;
 
-  my $orders = BSE::TB::Orders->new;
-  my @orders = sort { $b->{orderDate} cmp $a->{orderDate} } 
-    grep $_->{complete} && !$_->{paidFor}, $orders->all;
+  my @conds =
+    (
+     [ '<>', complete => 0 ],
+     [ paidFor => 0 ],
+    );
 
   return order_list_low($req, 'order_list_unpaid', 
-                       'Order list - Incomplete orders', @orders);
+                       'Order list - Unpaid orders', \@conds);
 }
 
+=item target order_list_incomplete
+X<shopadmin targets, order_list_incomplete>X<order_list_incomplete>
+
+List incomplete orders, ie. orders that the user abandoned before the
+payment step was complete.
+
+By default limits to the last 30 days.
+
+=cut
+
 sub req_order_list_incomplete {
   my ($class, $req) = @_;
 
-  my $orders = BSE::TB::Orders->new;
-  my @orders = sort { $b->{orderDate} cmp $a->{orderDate} } 
-    grep !$_->{complete}, $orders->all;
+  my @conds =
+    (
+     [ complete => 0 ]
+    );
 
   return order_list_low($req, 'order_list_incomplete', 
-                       'Order list - Incomplete orders', @orders);
+                       'Order list - Incomplete orders', \@conds);
 }
 
 sub tag_siteuser {
diff --git a/site/templates/admin/include/order_list_pages.tmpl b/site/templates/admin/include/order_list_pages.tmpl
new file mode 100644 (file)
index 0000000..8bdc77c
--- /dev/null
@@ -0,0 +1,11 @@
+<div class="pagelist">Page <:orders_pagenum:> of <:orders_pagecount:>
+<:ifFirstOrdersPage:><span>&lt;&lt;&lt;&lt;</span> <span>&lt;&lt;</span><:or:><a href="<:adminurl2 shopadmin [param target] pp [orders_perpage] p 1:>&amp;<:search_param:>">&lt;&lt;&lt;&lt;</a> <a href="<:adminurl2 shopadmin [param target] pp [orders_perpage] p [prevOrdersPage]:>&amp;<:search_param:>">&lt;&lt;</a><:eif:>
+<:iterator begin orders_pagec:>
+<:switch:>
+<:case order_pagec gap:>...
+<:case order_pagec link:><a href="<:adminurl2 shopadmin [param target] pp [orders_perpage]:>&amp;p=<:order_pagec page:>&amp;<:search_param:>"><:order_pagec page:></a>
+<:case default:><span><:order_pagec page:></span>
+<:endswitch:>
+<:iterator end orders_pagec:>
+<:ifLastOrdersPage:><span>&gt;&gt;</span> <span>&gt;&gt;&gt;&gt;</span><:or:><a href="<:adminurl2 shopadmin [param target] pp [orders_perpage] p [nextOrdersPage]:>&amp;<:search_param:>">&gt;&gt;</a> <a href="<:adminurl2 shopadmin [param target] pp [orders_perpage] p [orders_pagecount]:>&amp;<:search_param:>">&gt;&gt;&gt;&gt;</a><:eif:>
+</div>
index 9c84ccf..1a625c3 100644 (file)
@@ -1,8 +1,9 @@
-<:wrap admin/base.tmpl title => "Order list - Shop administration":>
+<:wrap admin/base.tmpl title => "Order list - Shop administration", target => order_list:>
 <h1>Shop Administration</h1>
 <p>| <a href="<:adminurl menu:>">Admin menu</a> | <a href="<:adminurl shopadmin:>">Manage catalogs</a> 
-  | <a href="<:adminurl shopadmin order_list 1 template order_list_unfilled:>">Unfilled orders</a>  [ <:order_count filter= filled==0 :> ]
-  | <a href="<:adminurl shopadmin order_list 1 template order_list_filled:>">Filled orders</a>   [ <:order_count filter= filled!=0 :> ]
+  | <a href="<:adminurl2 shopadmin order_list_unfilled:>">Unfilled orders</a>  [ <:all_order_count [ filled => 0 ] :> ]
+  | <a href="<:adminurl2 shopadmin order_list_filled:>">Filled orders</a>   [ <:all_order_count ['<>', filled => 0] :> ]
+  | <a href="<:adminurl2 shopadmin order_list_incomplete:>" title="Orders the customer did not complete">Incomplete orders</a>   [ <:all_order_count [complete => 0] :> ]
   |</p>
 <h2>Order list</h2>
 
@@ -18,8 +19,8 @@
         </tr>
         <tr> 
           <td colspan="7"> 
-            <form action="<:script:>" method="post">
-              <input type="hidden" name="order_list" value="1" />
+            <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: 
@@ -44,3 +45,4 @@
         </tr>
         <:iterator end orders:> 
       </table>
+<:include admin/include/order_list_pages.tmpl:>
index 83d48da..8e4de5d 100644 (file)
@@ -1,8 +1,8 @@
-<:wrap admin/base.tmpl title => "Order list - Shop administration":>
+<:wrap admin/base.tmpl title => "Order list - Shop administration", target=>order_list_filled:>
 <h1>Shop Administration</h1>
 <p>| <a href="<:adminurl menu:>">Admin menu</a> | <a href="<:adminurl shopadmin:>">Manage catalogs</a> 
-  | <a href="<:adminurl shopadmin order_list 1 template order_list_unfilled:>">Unfilled orders</a>  [ <:order_count filter= filled==0:> ]
-  | <a href="<:adminurl shopadmin order_list 1:>">All orders</a>  [ <:order_count filter= id!=0:> ] |</p>
+  | <a href="<:adminurl2 shopadmin order_list_unfilled:>">Unfilled orders</a>  [ <:all_order_count [ filled => 0 ] :> ]
+  | <a href="<:adminurl2 shopadmin order_list:>">All orders</a>  [ <:all_order_count:> ] |</p>
 <h2>Order list - Filled orders</h2>
 
       <table class="editform orderlist">
@@ -16,9 +16,8 @@
         </tr>
         <tr> 
           <td colspan="6"> 
-            <form action="<:script:>" method="post">
-              <input type="hidden" name="order_list" value="1" />
-              <input type="hidden" name="template" value="order_list_filled" />
+            <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: 
             </form>
           </td>
         </tr>
-        <:iterator begin orders filter= filled!=0 :> 
+        <:iterator begin orders:> 
         <tr> 
-          <td class="col_id"><a href="<:adminurl shopadmin id [order id] order_detail 1:>"><:order 
+          <td class="col_id"><a href="<:adminurl2 shopadmin order_detail id [order id]:>"><:order 
             id:></a></td>
           <td class="col_title"><:ifOrder billFirstName:><:order billFirstName:> <:order billLastName:><:or:><:order delivFirstName:> <:order delivLastName:><:eif:> <:ifOrder 
             userId:><font color="#CCCCCC">&#8212; (logged in)</font><:or:><:eif:></td>
           <td class="col_date"><:date order orderDate:></td>
           <td class="col_total">$<:money order total:></td>
           <td class="col_total">$<:money order gst:></td>
-          <td class="col_tools"> <a href="<:adminurl shopadmin id [order id] order_detail 1:>">Order 
+          <td class="col_tools"> <a href="<:adminurl2 shopadmin order_detail id [order id]:>">Order 
             details </a> </td>
         </tr>
         <:iterator end orders:> 
       </table>
+<:include admin/include/order_list_pages.tmpl:>
index 7193012..b7141d5 100644 (file)
@@ -1,22 +1,16 @@
-<html><head><title>Incomplete order list - Shop administration</title>
-<link rel="stylesheet" href="/css/admin.css">
-</head>
-<body>
+<:wrap admin/base.tmpl title => "Incomplete order list - Shop administration", target => order_list_incomplete:>
 <h1>Shop Administration</h1>
 <p>| <a href="/cgi-bin/admin/menu.pl">Admin menu</a> | <a href="<:script:>">Manage catalogs</a> 
-  | <a href="<:script:>?order_list=1&template=order_list_filled">Filled orders</a> [ <:order_count filter= filled!=0:> ]
-  | <a href="<:script:>?order_list=1">All orders</a>  [ <:order_count filter= id!=0:> ] |</p>
+  | <a href="<:adminurl2 shopadmin order_list_filled:>">Filled orders</a> [ <:all_order_count [ '<>', filled => 0 ]:> ]
+  | <a href="<:adminurl2 shopadmin order_list:>">All orders</a>  [ <:all_order_count [ '<>', complete => 0 ]:> ] |</p>
 <h2>Order list - Incomplete orders</h2>
 
 <p><b>These orders had failures during online credit card processing
 and the user did not go back to fix the problem.  These orders should
-not be processes and are visible only for completeness.</b></p>
+not be processed and are visible only for completeness.</b></p>
 
-<table bgcolor="#000000" cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
-  <tr>
-<td>
-      <table border=0 cellpadding="6" cellspacing="1" width="100%">
-        <tr bgcolor="#FFFFFF"> 
+<table class="editform orderlist">
+        <tr> 
           <th>Id</th>
           <th width="100%">Name</th>
           <th>Date</th>
@@ -24,36 +18,30 @@ not be processes and are visible only for completeness.</b></p>
           <th>GST</th>
           <th>Details</th>
         </tr>
-        <tr bgcolor="#FFFFFF"
+        <tr> 
           <td colspan="6"> 
-            <form action="<:script:>" method="POST">
-              <input type="hidden" name="order_list2" value="1">
-              <input type="hidden" name="template2" value="order_list_incomplete">
+            <form action="<:adminurl shopadmin:>">
+              <input type="hidden" name="a_order_list_incomplete" value="1">
               From date: 
-              <input type="text" size="10" name="from2" value="<:cgi from:>">
+              <input type="text" size="10" name="from" value="<:cgi from:>">
               To date: 
-              <input type="text" size="10" name="to2" value="<:cgi to:>">
+              <input type="text" size="10" name="to" value="<:cgi to:>">
               <input type=submit value="Filter orders" name="submit2">
             </form>
           </td>
         </tr>
-        <:iterator begin orders filter= filled==0 :> 
-        <tr bgcolor="#FFFFFF"
-          <td align="center" nowrap><a href="<:script:>?id=<:order id:>&order_detail=1"><:order 
+        <:iterator begin orders:> 
+        <tr> 
+          <td class="col_id"><a href="<:adminurl2 shopadmin order_detail id [order id]:>"><:order 
             id:></a></td>
-          <td width="100%"><:order delivFirstName:> <:order delivLastName:> <:ifOrder 
+          <td class="col_name"><:order delivFirstName:> <:order delivLastName:> <:ifOrder 
             userId:><font color="#CCCCCC">&#8212; (logged in)</font><:or:><:eif:></td>
-          <td nowrap><:date order orderDate:></td>
-          <td align=right nowrap>$<:money order total:></td>
-          <td align=right nowrap>$<:money order gst:></td>
-          <td nowrap> <a href="<:script:>?id=<:order id:>&order_detail=1">Order 
+          <td class="col_date"><:date order orderDate:></td>
+          <td class="col_total">$<:money order total:></td>
+          <td class="col_gst">$<:money order gst:></td>
+          <td class="col_tools"> <a href="<:adminurl2 shopadmin order_detail id [order id]:>">Order 
             details </a></td>
         </tr>
         <:iterator end orders:> 
-      </table>
-</td>
-</tr>
 </table>
-<p><font size="-1">BSE Release <:release:></font></p>
-</body>
-</html>
+<:include admin/include/order_list_pages.tmpl:>
index d465922..b687677 100644 (file)
@@ -1,8 +1,8 @@
-<:wrap admin/base.tmpl title => "Order list - Shop administration":>
+<:wrap admin/base.tmpl title => "Order list - Shop administration", target => order_list_unfilled:>
 <h1>Shop Administration</h1>
 <p>| <a href="<:adminurl menu:>">Admin menu</a> | <a href="<:adminurl shopadmin:>">Manage catalogs</a> 
-  | <a href="<:adminurl shopadmin order_list 1 template order_list_filled:>">Filled orders</a> [ <:order_count filter= filled!=0:> ]
-  | <a href="<:adminurl shopadmin order_list 1:>">All orders</a>  [ <:order_count filter= id!=0:> ] |</p>
+  | <a href="<:adminurl2 shopadmin order_list_filled:>">Filled orders</a> [ <:all_order_count [ '<>', filled => 0 ] :> ]
+  | <a href="<:adminurl2 shopadmin order_list:>">All orders</a>  [ <:all_order_count:> ] |</p>
 <h2>Order list - Unfilled orders</h2>
 
       <table class="editform orderlist">
         </tr>
         <tr> 
           <td colspan="6"> 
-            <form action="<:script:>" method="post">
-              <input type="hidden" name="order_list2" value="1" />
-              <input type="hidden" name="template2" value="order_list_unfilled" />
+            <form action="<:adminurl shopadmin:>">
+             <input type="hidden" name="a_order_list_unfilled" value="1" />
               From date: 
-              <input type="text" size="10" name="from2" value="<:cgi from:>" />
+              <input type="text" size="10" name="from" value="<:cgi from:>" />
               To date: 
-              <input type="text" size="10" name="to2" value="<:cgi to:>" />
+              <input type="text" size="10" name="to" value="<:cgi to:>" />
               <input type=submit value="Filter orders" name="submit2" />
             </form>
           </td>
         </tr>
         <:iterator begin orders filter= filled==0 :> 
         <tr> 
-          <td class="col_id"><a href="<:adminurl shopadmin id [order id] order_detail 1:>"><:order 
+          <td class="col_id"><a href="<:adminurl2 shopadmin order_detail id [order id]:>"><:order 
             id:></a></td>
           <td class="col_name"><:ifOrder billFirstName:><:order billFirstName:> <:order billLastName:><:or:><:order delivFirstName:> <:order delivLastName:><:eif:> <:ifOrder 
             userId:><font color="#CCCCCC">&#8212; (logged in)</font><:or:><:eif:></td>
           <td class="col_date"><:date order orderDate:></td>
           <td class="col_total">$<:money order total:></td>
           <td class="col_total">$<:money order gst:></td>
-          <td class="col_tools"> <a href="<:adminurl shopadmin id [order id] order_detail 1:>">Order 
+          <td class="col_tools"> <a href="<:adminurl2 shopadmin order_detail id [order id]:>">Order 
             details </a></td>
         </tr>
         <:iterator end orders:> 
       </table>
+<:include admin/include/order_list_pages.tmpl:>