2 %my $conf=new FS::Conf;
4 %#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
5 %http_header('Content-Type' => 'text/plain' );
8 %if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
11 % $format = $conf->config('batch-default_format');
14 %my $oldAutoCommit = $FS::UID::AutoCommit;
15 %local $FS::UID::AutoCommit = 0;
18 %my $pay_batch = qsearchs('pay_batch', {'status'=>''} );
19 %die "No pending batch. \n" unless $pay_batch;
21 %my %batchhash = $pay_batch->hash;
22 %$batchhash{'status'} = 'I';
23 %my $new = new FS::pay_batch \%batchhash;
24 %my $error = $new->replace($pay_batch);
25 %die "error updating batch status: $error\n" if $error;
30 %my (@date)=localtime();
31 %my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]);
33 %if ($format eq "BoM") {
35 % my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
36 % $conf->config("batchconfig-$format");
38 <% sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"").
39 sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct )
43 %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
46 % die "Unknown format for batch in batchconfig. \n";
50 %for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
51 % qsearch('cust_pay_batch',
52 % {'batchnum'=>$pay_batch->batchnum} )
55 % $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
56 % my( $mon, $y ) = ( $2, $1 );
57 % $mon = "0$mon" if $mon < 10;
60 % $batchtotal += $cust_pay_batch->amount;
62 % if ($format eq "BoM") {
64 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
66 <% sprintf( "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum %>
69 % } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") {
72 ,,,,<% $cust_pay_batch->payinfo %>,<% $exp %>,<% $cust_pay_batch->amount %>,<% $cust_pay_batch->paybatchnum %>
76 % die "I'm already dead, but you did not know that.\n";
81 %if ($format eq "BoM") {
84 <% sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ).
85 sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %>
88 %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
91 % die "I'm already dead (again), but you did not know that.\n";
94 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;