5 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
6 http_header('Content-Type' => 'text/plain' );
9 my $formatconfig = "batchconfig".$cgi->param('format');
11 die "No batch configuration exists.\n$formatconfig\n" unless $conf->exists($formatconfig);
12 my $format = $conf->config($formatconfig);
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") {
34 my($reformat,$origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = $conf->config('batchconfig');
35 printf "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,"";
36 printf "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct;
37 }elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
40 die "Unknown format for batch in batchconfig. \n";
44 for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
45 qsearch('cust_pay_batch',
46 {'batchnum'=>$pay_batch->batchnum} )
49 $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
50 my( $mon, $y ) = ( $2, $1 );
51 $mon = "0$mon" if $mon < 10;
54 $batchtotal += $cust_pay_batch->amount;
56 if ($format eq "BoM") {
57 my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
58 printf "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum;
59 }elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
60 %>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %>
62 die "I'm already dead, but you did not know that.\n";
67 if ($format eq "BoM") {
68 printf "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"";
69 printf "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","";
70 }elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){
73 die "I'm already dead (again), but you did not know that.\n";
76 $dbh->commit or die $dbh->errstr if $oldAutoCommit;