5 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
6 http_header('Content-Type' => 'text/plain' );
9 if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
12 $format = $conf->config('batch-default_format');
15 my $oldAutoCommit = $FS::UID::AutoCommit;
16 local $FS::UID::AutoCommit = 0;
19 my $pay_batch = qsearchs('pay_batch', {'status'=>'O'} );
20 die "No pending batch. \n" unless $pay_batch;
22 my %batchhash = $pay_batch->hash;
23 $batchhash{'status'} = 'I';
24 my $new = new FS::pay_batch \%batchhash;
25 my $error = $new->replace($pay_batch);
26 die "error updating batch status: $error\n" if $error;
31 my (@date)=localtime();
32 my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]);
34 if ($format eq "BoM") {
36 my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) =
37 $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 )
42 }elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
45 die "Unknown format for batch in batchconfig. \n";
49 for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
50 qsearch('cust_pay_batch',
51 {'batchnum'=>$pay_batch->batchnum} )
54 $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
55 my( $mon, $y ) = ( $2, $1 );
56 $mon = "0$mon" if $mon < 10;
59 $batchtotal += $cust_pay_batch->amount;
61 if ($format eq "BoM") {
63 my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
64 %><%= sprintf( "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum %><%
66 } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") {
68 %>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %><%
71 die "I'm already dead, but you did not know that.\n";
76 if ($format eq "BoM") {
78 %><%= sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ).
79 sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %><%
81 } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
84 die "I'm already dead (again), but you did not know that.\n";
87 $dbh->commit or die $dbh->errstr if $oldAutoCommit;