1 %my( $count_query, $sql_query );
4 %my $orderby = 'paybatchnum';
6 %my( $pay_batch, $batchnum ) = ( '', '');
7 %if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
8 % push @search, "batchnum = $1";
9 % $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
10 % die "Batch $1 not found!" unless $pay_batch;
11 % $batchnum = $pay_batch->batchnum;
14 %if ( $cgi->param('payby') ) {
15 % $cgi->param('payby') =~ /^(CARD|CHEK)$/
16 % or die "illegal payby " . $cgi->param('payby');
18 % push @search, "cust_pay_batch.payby = '$1'";
21 %if ( not $cgi->param('dcln') ) {
22 % push @search, "cpb.status IS DISTINCT FROM 'Approved'";
25 %my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
27 % push @search, "pay_batch.upload >= $beginning" if ($beginning);
28 % push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
29 % $orderby = "pay_batch.download,paybatchnum";
32 %push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
33 %my $search = ' WHERE ' . join(' AND ', @search);
35 %$count_query = 'SELECT COUNT(*) FROM cust_pay_batch AS cpb ' .
36 % 'LEFT JOIN cust_main USING ( custnum ) ' .
37 % 'LEFT JOIN pay_batch USING ( batchnum )' .
41 %$sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," .
42 % "cpb.payname,cpb.payinfo,cpb.exp,amount,cpb.status " .
43 % "FROM cust_pay_batch AS cpb " .
44 % 'LEFT JOIN cust_main USING ( custnum ) ' .
45 % 'LEFT JOIN pay_batch USING ( batchnum ) ' .
46 % "$search ORDER BY $orderby";
50 % my $conf = new FS::Conf;
51 % my $fixed = $conf->config('batch-fixed_format-'. $pay_batch->payby);
53 % $pay_batch->status eq 'O'
54 % || ( $pay_batch->status eq 'I'
55 % && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches')
58 % $html_init .= qq!<FORM ACTION="$p/misc/download-batch.cgi" METHOD="POST">!;
60 % $html_init .= qq!<INPUT TYPE="hidden" NAME="format" VALUE="$fixed">!;
62 % $html_init .= qq!Download batch in format <SELECT NAME="format">!.
63 % qq!<OPTION VALUE="">Default batch mode</OPTION>!.
64 % qq!<OPTION VALUE="csv-td_canada_trust-merchant_pc_batch">CSV file for TD Canada Trust Merchant PC Batch</OPTION>!.
65 % qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
66 % qq!<OPTION VALUE="PAP">80 byte file for TD Canada Trust PAP Batch</OPTION>!.
67 % qq!<OPTION VALUE="BoM">Bank of Montreal ECA batch</OPTION>!.
70 % $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum"><INPUT TYPE="submit" VALUE="Download"></FORM><BR>!;
74 % $pay_batch->status eq 'I'
75 % || ( $pay_batch->status eq 'R'
76 % && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches')
79 % $html_init .= qq!<FORM ACTION="$p/misc/upload-batch.cgi" METHOD="POST" ENCTYPE="multipart/form-data">!.
80 % qq!Upload results<BR>!.
81 % qq!Filename <INPUT TYPE="file" NAME="batch_results"><BR>!;
83 % $html_init .= qq!<INPUT TYPE="hidden" NAME="format" VALUE="$fixed">!;
85 % $html_init .= qq!Format <SELECT NAME="format">!.
86 % qq!<OPTION VALUE="">Default batch mode</OPTION>!.
87 % qq!<OPTION VALUE="csv-td_canada_trust-merchant_pc_batch">CSV results from TD Canada Trust Merchant PC Batch</OPTION>!.
88 % qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
89 % qq!<OPTION VALUE="PAP">264 byte results for TD Canada Trust PAP Batch</OPTION>!.
90 % qq!<OPTION VALUE="BoM">Bank of Montreal ECA results</OPTION>!.
93 % $html_init .= '<INPUT TYPE="submit" VALUE="Upload"></FORM><BR>';
99 % my $sth = dbh->prepare($count_query) or die dbh->errstr. "doing $count_query";
100 % $sth->execute or die "Error executing \"$count_query\": ". $sth->errstr;
101 % my $cards = $sth->fetchrow_arrayref->[0];
103 % my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=". $batchnum;
104 % $sth = dbh->prepare($st) or die dbh->errstr. "doing $st";
105 % $sth->execute or die "Error executing \"$st\": ". $sth->errstr;
106 % my $total = $sth->fetchrow_arrayref->[0];
108 % $html_init .= "$cards credit card payments batched<BR>\$" .
109 % sprintf("%.2f", $total) ." total in batch<BR>";
113 <% include('elements/search.html',
114 'title' => 'Batch payment details',
115 'name' => 'batch details',
116 'menubar' => ['Main Menu' => $p,],
117 'query' => $sql_query,
118 'count_query' => $count_query,
119 'html_init' => $pay_batch ? $html_init : '',
141 $cpb->[3] . ', ' . $cpb->[4];
147 my $cardnum = shift->[6];
148 'x'x(length($cardnum)-4). substr($cardnum,(length($cardnum)-4));
151 shift->[7] =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
152 my( $mon, $year ) = ( $2, $1 );
153 $mon = "0$mon" if length($mon) == 1;
163 'align' => 'lllllllrl',
164 'links' => [ ['', sub{'#';}],
165 ["${p}view/cust_bill.cgi?", sub{shift->[1];},],
166 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
167 ["${p}view/cust_main.cgi?", sub{shift->[2];},],