1 %if ($format eq "BoM") {
3 % my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
4 % $conf->config("batchconfig-$format");
6 <% sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"").
7 sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct )
10 %}elsif ($format eq "PAP"){
12 % my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
13 % $conf->config("batchconfig-$format");
15 <% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") %>
18 %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
20 %}elsif ($format eq "csv-chase_canada-E-xactBatch"){
22 % my($origid) = $conf->config("batchconfig-$format");
23 <% sprintf( '$$E-xactBatchFileV1.0$$%s:%03u$$%s',$sdate,$pay_batch->batchnum, $origid)
27 % die "Unknown format for batch in batchconfig. \n";
31 %for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
32 % qsearch('cust_pay_batch',
33 % {'batchnum'=>$pay_batch->batchnum} )
36 % $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
37 % my( $mon, $y ) = ( $2, $1 );
38 % if ( $conf->exists('batch-increment_expiration') ) {
39 % my( $curmon, $curyear ) = (localtime(time))[4,5];
40 % $curmon++; $curyear-=100;
41 % $y++ while $y < $curyear || ( $y == $curyear && $mon < $curmon );
43 % $mon = "0$mon" if $mon =~ /^\d$/;
44 % $y = "0$y" if $y =~ /^\d$/;
47 % if ( $first_download ) {
48 % my $balance = $cust_pay_batch->cust_main->balance;
49 % if ( $balance <= 0 ) {
50 % my $error = $cust_pay_batch->delete;
52 % $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
56 % } elsif ( $balance < $cust_pay_batch->amount ) {
57 % $cust_pay_batch->amount($balance);
58 % my $error = $cust_pay_batch->replace;
60 % $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
63 % #} elsif ( $balance > $cust_pay_batch->amount ) {
68 % $batchtotal += $cust_pay_batch->amount;
70 % if ($format eq "BoM") {
72 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
74 <% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %>
77 % } elsif ($format eq "PAP"){
79 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
81 <% sprintf( "D%-23s%06u%-19s%09u%-12s%010.0f\n",$cust_pay_batch->payname,$cdate,$cust_pay_batch->paybatchnum,$aba,$account,$cust_pay_batch->amount*100) %>
84 % } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") {
87 ,,,,<% $cust_pay_batch->payinfo %>,<% $exp %>,<% $cust_pay_batch->amount %>,<% $cust_pay_batch->paybatchnum %>
90 % } elsif ($format eq "csv-chase_canada-E-xactBatch"){
92 % my $payname=$cust_pay_batch->payname; $payname =~ tr/",/ /; #payinfo too? :P
93 <% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",00,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,,
97 % die "I'm already dead, but you did not know that.\n";
102 %if ($format eq "BoM") {
105 <% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ).
106 sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %>
109 %} elsif ($format eq "PAP"){
112 <% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %>
115 %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
117 %} elsif ($format eq "csv-chase_canada-E-xactBatch"){
120 % die "I'm already dead (again), but you did not know that.\n";
123 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
126 my $conf=new FS::Conf;
128 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
129 http_header('Content-Type' => 'text/plain' );
132 if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) {
135 die "No batch number (bad URL) \n";
139 if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
142 $format = $conf->config('batch-default_format');
145 my $oldAutoCommit = $FS::UID::AutoCommit;
146 local $FS::UID::AutoCommit = 0;
149 my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} );
150 my $first_download = 1;
151 unless ($pay_batch) {
152 $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} )
153 if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches');
156 die "No pending batch. \n" unless $pay_batch;
158 my $error = $pay_batch->set_status('I');
159 die "error updating batch status: $error\n" if $error;
164 my (@date)=localtime($pay_batch->download);
165 my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1);
166 my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1).
167 sprintf("%02d", $date[5] % 100);
168 my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1).
169 '/'.sprintf("%02d", $date[3]);