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)
26 %}elsif ($format eq "ach-spiritone"){
29 % die "Unknown format for batch in batchconfig. \n";
33 %for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum }
34 % qsearch('cust_pay_batch',
35 % {'batchnum'=>$pay_batch->batchnum} )
38 % $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
39 % my( $mon, $y ) = ( $2, $1 );
40 % if ( $conf->exists('batch-increment_expiration') ) {
41 % my( $curmon, $curyear ) = (localtime(time))[4,5];
42 % $curmon++; $curyear-=100;
43 % $y++ while $y < $curyear || ( $y == $curyear && $mon < $curmon );
45 % $mon = "0$mon" if $mon =~ /^\d$/;
46 % $y = "0$y" if $y =~ /^\d$/;
49 % if ( $first_download ) {
50 % my $balance = $cust_pay_batch->cust_main->balance;
51 % if ( $balance <= 0 ) {
52 % my $error = $cust_pay_batch->delete;
54 % $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
58 % } elsif ( $balance < $cust_pay_batch->amount ) {
59 % $cust_pay_batch->amount($balance);
60 % my $error = $cust_pay_batch->replace;
62 % $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
65 % #} elsif ( $balance > $cust_pay_batch->amount ) {
70 % $batchtotal += $cust_pay_batch->amount;
72 % if ($format eq "BoM") {
74 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
76 <% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %>
79 % } elsif ($format eq "PAP"){
81 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
83 <% 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) %>
86 % } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") {
89 ,,,,<% $cust_pay_batch->payinfo %>,<% $exp %>,<% $cust_pay_batch->amount %>,<% $cust_pay_batch->paybatchnum %>
92 % } elsif ($format eq "csv-chase_canada-E-xactBatch"){
94 % my $payname=$cust_pay_batch->payname; $payname =~ tr/",/ /; #payinfo too? :P
95 <% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",00,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,,
98 % }elsif ($format eq "ach-spiritone"){
100 % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
101 % my $payname=$cust_pay_batch->payname; $payname =~ tr/",/ /; #payinfo too?
102 % my $batchline = qq!"$payname","!.$cust_pay_batch->custnum. #dodgy, works for autoapply
103 % qq!","$aba","$account","27","!.$cust_pay_batch->amount.
105 % push @batchlines, $batchline;
109 % die "I'm already dead, but you did not know that.\n";
114 %if ($format eq "BoM") {
117 <% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ).
118 sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %>
121 %} elsif ($format eq "PAP"){
124 <% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %>
127 %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
129 %} elsif ($format eq "csv-chase_canada-E-xactBatch"){
131 %} elsif ($format eq "ach-spiritone"){
134 % die "I'm already dead (again), but you did not know that.\n";
139 my $conf=new FS::Conf;
141 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
142 http_header('Content-Type' => 'text/plain' );
145 if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) {
148 die "No batch number (bad URL) \n";
152 if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
155 $format = $conf->config('batch-default_format');
159 if ( $format eq 'ach-spiritone' ) {
165 my $oldAutoCommit = $FS::UID::AutoCommit;
166 local $FS::UID::AutoCommit = 0;
169 my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} );
170 my $first_download = 1;
171 unless ($pay_batch) {
172 $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} )
173 if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches');
176 die "No pending batch. \n" unless $pay_batch;
178 my $error = $pay_batch->set_status('I');
179 die "error updating batch status: $error\n" if $error;
184 my (@date)=localtime($pay_batch->download);
185 my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1);
186 my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1).
187 sprintf("%02d", $date[5] % 100);
188 my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1).
189 '/'.sprintf("%02d", $date[3]);
195 my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
196 my $fh = new File::Temp(
197 TEMPLATE => 'paybatch.'. $batchnum .'.XXXXXXXX',
199 ) or die "can't open temp file: $!\n";
201 print $fh map{ "$_\n" } @batchlines;
204 $error = $pay_batch->import_results( 'filehandle' => $fh,
207 die $error if $error;
210 $dbh->commit or die $dbh->errstr if $oldAutoCommit;