fix small side-effect of mysql-compat change eliminating DISTINCT ON: map changing...
[freeside.git] / httemplate / search / cust_pay_batch.cgi
index fec3dfd..c678feb 100755 (executable)
 %>
 <%init>
 
+my $conf = new FS::Conf;
+
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
-      || $FS::CurrentUser::CurrentUser->access_right('Process batches');
+      || $FS::CurrentUser::CurrentUser->access_right('Process batches')
+      || ( $cgi->param('custnum') 
+           && $conf->exists('batch-enable')
+           #&& $FS::CurrentUser::CurrentUser->access_right('View customer batched payments')
+         );
 
 my( $count_query, $sql_query );
 my $hashref = {};
@@ -75,6 +81,14 @@ if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
   $batchnum = $pay_batch->batchnum;
 }
 
+if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
+  push @search, "custnum = $1";
+}
+
+if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
+  push @search, "pay_batch.status = '$1'";
+}
+
 if ( $cgi->param('payby') ) {
   $cgi->param('payby') =~ /^(CARD|CHEK)$/
     or die "illegal payby " . $cgi->param('payby');
@@ -111,7 +125,6 @@ $sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," .
 
 my $html_init = '';
 if ( $pay_batch ) {
-  my $conf = new FS::Conf;
   my $fixed = $conf->config('batch-fixed_format-'. $pay_batch->payby);
   if (
        $pay_batch->status eq 'O' 
@@ -129,6 +142,7 @@ if ( $pay_batch ) {
                     qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
                     qq!<OPTION VALUE="PAP">80 byte file for TD Canada Trust PAP Batch</OPTION>!.
                     qq!<OPTION VALUE="BoM">Bank of Montreal ECA batch</OPTION>!.
+                    qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
                     qq!</SELECT>!;
     }
     $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum"><INPUT TYPE="submit" VALUE="Download"></FORM><BR>!;
@@ -152,6 +166,7 @@ if ( $pay_batch ) {
                     qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
                     qq!<OPTION VALUE="PAP">264 byte results for TD Canada Trust PAP Batch</OPTION>!.
                     qq!<OPTION VALUE="BoM">Bank of Montreal ECA results</OPTION>!.
+                    qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
                     qq!</SELECT><BR>!;
     }
     $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;