1 <% include('elements/search.html',
2 'title' => 'Batch payment details',
3 'name' => 'batch details',
5 'count_query' => $count_query,
6 'html_init' => $pay_batch ? $html_init : '',
28 $cpb->[3] . ', ' . $cpb->[4];
34 my $cardnum = shift->[6];
35 'x'x(length($cardnum)-4). substr($cardnum,(length($cardnum)-4));
38 shift->[7] =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
39 my( $mon, $year ) = ( $2, $1 );
40 $mon = "0$mon" if length($mon) == 1;
50 'align' => 'lllllllrl',
51 'links' => [ ['', sub{'#';}],
52 ["${p}view/cust_bill.cgi?", sub{shift->[1];},],
53 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
54 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
60 my $conf = new FS::Conf;
63 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
64 || $FS::CurrentUser::CurrentUser->access_right('Process batches')
65 || ( $cgi->param('custnum')
66 && ( $conf->exists('batch-enable')
67 || $conf->config('batch-enable_payby')
69 #&& $FS::CurrentUser::CurrentUser->access_right('View customer batched payments')
72 my( $count_query, $sql_query );
75 my $orderby = 'paybatchnum';
77 my( $pay_batch, $batchnum ) = ( '', '');
78 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
79 push @search, "batchnum = $1";
80 $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
81 die "Batch $1 not found!" unless $pay_batch;
82 $batchnum = $pay_batch->batchnum;
85 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
86 push @search, "custnum = $1";
89 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
90 push @search, "pay_batch.status = '$1'";
93 if ( $cgi->param('payby') ) {
94 $cgi->param('payby') =~ /^(CARD|CHEK)$/
95 or die "illegal payby " . $cgi->param('payby');
97 push @search, "cust_pay_batch.payby = '$1'";
100 if ( not $cgi->param('dcln') ) {
101 push @search, "cpb.status IS DISTINCT FROM 'Approved'";
104 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
106 push @search, "pay_batch.upload >= $beginning" if ($beginning);
107 push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
108 $orderby = "pay_batch.download,paybatchnum";
111 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
112 my $search = ' WHERE ' . join(' AND ', @search);
114 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch AS cpb ' .
115 'LEFT JOIN cust_main USING ( custnum ) ' .
116 'LEFT JOIN pay_batch USING ( batchnum )' .
120 $sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," .
121 "cpb.payname,cpb.payinfo,cpb.exp,amount,cpb.status " .
122 "FROM cust_pay_batch AS cpb " .
123 'LEFT JOIN cust_main USING ( custnum ) ' .
124 'LEFT JOIN pay_batch USING ( batchnum ) ' .
125 "$search ORDER BY $orderby";
129 my $fixed = $conf->config('batch-fixed_format-'. $pay_batch->payby);
131 $pay_batch->status eq 'O'
132 || ( $pay_batch->status eq 'I'
133 && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches')
135 || ( $pay_batch->status eq 'R'
136 && $FS::CurrentUser::CurrentUser->access_right('Redownload resolved batches')
139 $html_init .= qq!<FORM ACTION="$p/misc/download-batch.cgi" METHOD="POST">!;
141 $html_init .= qq!<INPUT TYPE="hidden" NAME="format" VALUE="$fixed">!;
143 $html_init .= qq!Download batch in format <SELECT NAME="format">!.
144 qq!<OPTION VALUE="">Default batch mode</OPTION>!.
145 qq!<OPTION VALUE="csv-td_canada_trust-merchant_pc_batch">CSV file for TD Canada Trust Merchant PC Batch</OPTION>!.
146 qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
147 qq!<OPTION VALUE="PAP">80 byte file for TD Canada Trust PAP Batch</OPTION>!.
148 qq!<OPTION VALUE="BoM">Bank of Montreal ECA batch</OPTION>!.
149 qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
150 qq!<OPTION VALUE="paymentech">Chase Paymentech XML</OPTION>!.
151 qq!<OPTION VALUE="RBC">Royal Bank of Canada PDS</OPTION>!.
154 $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum"><INPUT TYPE="submit" VALUE="Download"></FORM><BR>!;
158 $pay_batch->status eq 'I'
159 || ( $pay_batch->status eq 'R'
160 && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches')
163 $html_init .= qq!<FORM ACTION="$p/misc/upload-batch.cgi" METHOD="POST" ENCTYPE="multipart/form-data">!.
164 qq!Upload results<BR>!.
165 qq!Filename <INPUT TYPE="file" NAME="batch_results"><BR>!;
167 $html_init .= qq!<INPUT TYPE="hidden" NAME="format" VALUE="$fixed">!;
169 $html_init .= qq!Format <SELECT NAME="format">!.
170 qq!<OPTION VALUE="">Default batch mode</OPTION>!.
171 qq!<OPTION VALUE="csv-td_canada_trust-merchant_pc_batch">CSV results from TD Canada Trust Merchant PC Batch</OPTION>!.
172 qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
173 qq!<OPTION VALUE="PAP">264 byte results for TD Canada Trust PAP Batch</OPTION>!.
174 qq!<OPTION VALUE="BoM">Bank of Montreal ECA results</OPTION>!.
175 qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
176 qq!<OPTION VALUE="paymentech">Chase Paymentech XML</OPTION>!.
177 qq!<OPTION VALUE="RBC">Royal Bank of Canada PDS</OPTION>!.
180 $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;
181 $html_init .= '<INPUT TYPE="submit" VALUE="Upload"></FORM><BR>';
187 my $sth = dbh->prepare($count_query) or die dbh->errstr. "doing $count_query";
188 $sth->execute or die "Error executing \"$count_query\": ". $sth->errstr;
189 my $cards = $sth->fetchrow_arrayref->[0];
191 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=". $batchnum;
192 $sth = dbh->prepare($st) or die dbh->errstr. "doing $st";
193 $sth->execute or die "Error executing \"$st\": ". $sth->errstr;
194 my $total = $sth->fetchrow_arrayref->[0];
196 $html_init .= "$cards credit card payments batched<BR>\$" .
197 sprintf("%.2f", $total) ." total in batch<BR>";