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="PAP">80 byte file for TD Canada Trust PAP Batch</OPTION>!.
66 % qq!<OPTION VALUE="BoM">Bank of Montreal ECA batch</OPTION>!.
69 % $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum"><INPUT TYPE="submit" VALUE="Download"></FORM><BR>!;
73 % $pay_batch->status eq 'I'
74 % || ( $pay_batch->status eq 'R'
75 % && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches')
78 % $html_init .= qq!<FORM ACTION="$p/misc/upload-batch.cgi" METHOD="POST" ENCTYPE="multipart/form-data">!.
79 % qq!Upload results<BR>!.
80 % qq!Filename <INPUT TYPE="file" NAME="batch_results"><BR>!;
82 % $html_init .= qq!<INPUT TYPE="hidden" NAME="format" VALUE="$fixed">!;
84 % $html_init .= qq!Format <SELECT NAME="format">!.
85 % qq!<OPTION VALUE="">Default batch mode</OPTION>!.
86 % qq!<OPTION VALUE="csv-td_canada_trust-merchant_pc_batch">CSV results from TD Canada Trust Merchant PC Batch</OPTION>!.
87 % qq!<OPTION VALUE="PAP">264 byte results for TD Canada Trust PAP Batch</OPTION>!.
88 % qq!<OPTION VALUE="BoM">Bank of Montreal ECA results</OPTION>!.
91 % $html_init .= '<INPUT TYPE="submit" VALUE="Upload"></FORM><BR>';
97 % my $sth = dbh->prepare($count_query) or die dbh->errstr. "doing $count_query";
98 % $sth->execute or die "Error executing \"$count_query\": ". $sth->errstr;
99 % my $cards = $sth->fetchrow_arrayref->[0];
101 % my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=". $batchnum;
102 % $sth = dbh->prepare($st) or die dbh->errstr. "doing $st";
103 % $sth->execute or die "Error executing \"$st\": ". $sth->errstr;
104 % my $total = $sth->fetchrow_arrayref->[0];
106 % $html_init .= "$cards credit card payments batched<BR>\$" .
107 % sprintf("%.2f", $total) ." total in batch<BR>";
111 <% include('elements/search.html',
112 'title' => 'Batch payment details',
113 'name' => 'batch details',
114 'menubar' => ['Main Menu' => $p,],
115 'query' => $sql_query,
116 'count_query' => $count_query,
117 'html_init' => $pay_batch ? $html_init : '',
139 $cpb->[3] . ', ' . $cpb->[4];
145 my $cardnum = shift->[6];
146 'x'x(length($cardnum)-4). substr($cardnum,(length($cardnum)-4));
149 shift->[7] =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
150 my( $mon, $year ) = ( $2, $1 );
151 $mon = "0$mon" if length($mon) == 1;
161 'align' => 'lllllllrl',
162 'links' => [ ['', sub{'#';}],
163 ["${p}view/cust_bill.cgi?", sub{shift->[1];},],
164 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
165 ["${p}view/cust_main.cgi?", sub{shift->[2];},],