select quick payment entry batch in payment report, RT#26343
authorIvan Kohler <ivan@freeside.biz>
Sun, 19 Jan 2014 22:05:44 +0000 (14:05 -0800)
committerIvan Kohler <ivan@freeside.biz>
Sun, 19 Jan 2014 22:05:44 +0000 (14:05 -0800)
httemplate/elements/select-paybatch.html [new file with mode: 0644]
httemplate/elements/tr-select-paybatch.html [new file with mode: 0644]
httemplate/search/elements/cust_pay_or_refund.html
httemplate/search/elements/report_cust_pay_or_refund.html

diff --git a/httemplate/elements/select-paybatch.html b/httemplate/elements/select-paybatch.html
new file mode 100644 (file)
index 0000000..1dba452
--- /dev/null
@@ -0,0 +1,46 @@
+<SELECT NAME="<% $opt{field} || 'paybatch' %>">
+
+  <OPTION VALUE="">any/none</OPTION>
+
+% foreach my $p (@paybatch) {
+%   my( $paybatch, $date ) = @$p;
+%   #my @components = split('-', $paybatch);
+%   my $pretty_date = time2str($date_format, $date);
+%   my $pretty = "$pretty_date: $paybatch";
+
+    <OPTION VALUE="<% $paybatch |h %>"><% $pretty |h %></OPTION>
+
+% }
+
+</SELECT>
+<%init>
+
+use Date::Parse qw(str2time); #i should be in Mason.pm
+
+my %opt = @_;
+#my $paybatch = $opt{'curr_value'}; # || $opt{'value'} necessary?
+
+my $conf = new FS::Conf;
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+
+my $sth = dbh->prepare('SELECT DISTINCT paybatch FROM cust_pay
+                          WHERE paybatch IS NOT NULL')
+  or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+
+my @paybatch = #map $_->[0],
+                 sort { $a->[1] <=> $b->[1] }
+                   map { my $date = '';
+                         if ( /^\w+\-(\d+)\-/ ) {
+                           $date = $1;
+                         } elsif ( /^\w+\-([\d\/]+)\-([\d\:]+)\-/ ) {
+                           $date = str2time("$1 $2");
+                         #} else {
+                         #  warn "unparsable: $_\n";
+                         }
+                         [ $_, $date ];
+                       }
+                     grep ! /^webui-/, #don't actually want the single entries
+                       map $_->[0], @{ $sth->fetchall_arrayref };
+
+</%init>
diff --git a/httemplate/elements/tr-select-paybatch.html b/httemplate/elements/tr-select-paybatch.html
new file mode 100644 (file)
index 0000000..aedf893
--- /dev/null
@@ -0,0 +1,13 @@
+<TR>
+  <TD ALIGN="right"><% $opt{'paybatch'} || 'Payment entry batch: ' %></TD>
+  <TD>
+    <% include( '/elements/select-paybatch.html', 'curr_value' => $selected_paybatch, %opt ) %>
+  </TD>
+</TR>
+<%init>
+
+my( %opt ) = @_;
+#my $conf = new FS::Conf;
+my $selected_paybatch = $opt{'curr_value'}; # || $opt{'value'} necessary?
+
+</%init>
index 234121f..c272a16 100755 (executable)
@@ -440,8 +440,6 @@ if ( $cgi->param('magic') ) {
     $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/
       or die "illegal paybatch: ". $cgi->param('paybatch');
 
     $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/
       or die "illegal paybatch: ". $cgi->param('paybatch');
 
-    push @search, "paybatch = '$1'";
-
     $orderby = "LOWER(company || ' ' || last || ' ' || first )";
 
   } elsif ( $cgi->param('magic') eq 'batchnum' ) {
     $orderby = "LOWER(company || ' ' || last || ' ' || first )";
 
   } elsif ( $cgi->param('magic') eq 'batchnum' ) {
@@ -457,6 +455,10 @@ if ( $cgi->param('magic') ) {
     die "unknown search magic: ". $cgi->param('magic');
   }
 
     die "unknown search magic: ". $cgi->param('magic');
   }
 
+  if ( $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/ ) {
+    push @search, "paybatch = '$1'";
+  }
+
   #unapplied payment/refund
   if ( $unapplied ) {
     push @select, '(' . "FS::$table"->unapplied_sql . ') AS unapplied_amount';
   #unapplied payment/refund
   if ( $unapplied ) {
     push @select, '(' . "FS::$table"->unapplied_sql . ') AS unapplied_amount';
index b39c7c0..25f7cda 100644 (file)
@@ -89,6 +89,16 @@ Examples:
     </TR>
 % }
 
     </TR>
 % }
 
+% if ( $table eq 'cust_pay' ) {
+
+% # payment batch
+% #  <& /elements/tr-select-batchnum.html &>
+
+% #payment "entry" batch (should probably just all become the same thing)
+  <& /elements/tr-select-paybatch.html &>
+
+% }
+
   <& /elements/tr-input-lessthan_greaterthan.html,
                 'label' => emt('Amount'),
                 'field' => 'paid',
   <& /elements/tr-input-lessthan_greaterthan.html,
                 'label' => emt('Amount'),
                 'field' => 'paid',