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->first. " ". $cust_pay_batch->last;
102 % $payname =~ tr/",/ /; #payinfo too?
103 % my $batchline = qq!"$payname","!.$cust_pay_batch->paybatchnum.
104 % qq!","$aba","$account","27","!.$cust_pay_batch->amount.
106 % push @batchlines, $batchline;
110 % die "I'm already dead, but you did not know that.\n";
115 %if ($format eq "BoM") {
118 <% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ).
119 sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %>
122 %} elsif ($format eq "PAP"){
125 <% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %>
128 %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){
130 %} elsif ($format eq "csv-chase_canada-E-xactBatch"){
132 %} elsif ($format eq "ach-spiritone"){
135 % die "I'm already dead (again), but you did not know that.\n";
140 my $conf=new FS::Conf;
142 #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
143 http_header('Content-Type' => 'text/plain' );
146 if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) {
149 die "No batch number (bad URL) \n";
153 if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
156 $format = $conf->config('batch-default_format');
160 if ( $format eq 'ach-spiritone' ) {
166 my $oldAutoCommit = $FS::UID::AutoCommit;
167 local $FS::UID::AutoCommit = 0;
170 my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} );
171 my $first_download = 1;
172 unless ($pay_batch) {
173 $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} )
174 if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches');
177 die "No pending batch. \n" unless $pay_batch;
179 my $error = $pay_batch->set_status('I');
180 die "error updating batch status: $error\n" if $error;
185 my (@date)=localtime($pay_batch->download);
186 my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1);
187 my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1).
188 sprintf("%02d", $date[5] % 100);
189 my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1).
190 '/'.sprintf("%02d", $date[3]);
196 my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
197 my $fh = new File::Temp(
198 TEMPLATE => 'paybatch.'. $batchnum .'.XXXXXXXX',
200 ) or die "can't open temp file: $!\n";
202 print $fh map{ "$_\n" } @batchlines;
205 $error = $pay_batch->import_results( 'filehandle' => $fh,
208 die $error if $error;
211 $dbh->commit or die $dbh->errstr if $oldAutoCommit;