X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Fdownload-batch.cgi;h=c4bc37e93df7e1cf61c6aaefbd7fca435b4b0b9e;hp=5a98f1d51989181689e13f0d954e760c892f1a3b;hb=560af69840e7e3fcebf65d5d56ca4efc0851efec;hpb=50f25b285b2caf77d267ed66f03e56924ad7229f diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 5a98f1d51..c4bc37e93 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,79 +1,37 @@ -<% - -my $conf=new FS::Conf; +<% $exporttext %><%init> #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes -http_header('Content-Type' => 'text/plain' ); - -#need default -my $formatconfig = "batchconfig".$cgi->param('format'); - -die "No batch configuration exists.\n$formatconfig\n" unless $conf->exists($formatconfig); -my $format = $conf->config($formatconfig); - -my $oldAutoCommit = $FS::UID::AutoCommit; -local $FS::UID::AutoCommit = 0; -my $dbh = dbh; - -my $pay_batch = qsearchs('pay_batch', {'status'=>''} ); -die "No pending batch. \n" unless $pay_batch; - -my %batchhash = $pay_batch->hash; -$batchhash{'status'} = 'I'; -my $new = new FS::pay_batch \%batchhash; -my $error = $new->replace($pay_batch); -die "error updating batch status: $error\n" if $error; - -my $batchtotal=0; -my $batchcount=0; +http_header('Content-Type' => 'text/plain' ); # not necessarily correct... -my (@date)=localtime(); -my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]); - -if ($format eq "BoM") { - my($reformat,$origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = $conf->config('batchconfig'); - printf "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,""; - printf "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct; -}elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){ - 1; -}else{ - die "Unknown format for batch in batchconfig. \n"; +my $batchnum; +if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { + $batchnum = $1; +} else { + die "No batch number (bad URL) \n"; } - -for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } - qsearch('cust_pay_batch', - {'batchnum'=>$pay_batch->batchnum} ) -) { - -$cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/; -my( $mon, $y ) = ( $2, $1 ); -$mon = "0$mon" if $mon < 10; -my $exp = "$mon$y"; -$batchcount++; -$batchtotal += $cust_pay_batch->amount; - -if ($format eq "BoM") { - my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); - printf "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum; -}elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){ -%>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %> -<% }else{ - die "I'm already dead, but you did not know that.\n"; +my %opt; +if ( $cgi->param('gatewaynum') =~ /^(\d+)$/ ) { + my $gateway = FS::payment_gateway->by_key($1); + die "gatewaynum $1 not found" unless $gateway; + $opt{'gateway'} = $gateway; } - +elsif ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { + $opt{'format'} = $1; } -if ($format eq "BoM") { - printf "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,""; - printf "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0",""; -}elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){ - 1; -} else{ - die "I'm already dead (again), but you did not know that.\n"; +my $pay_batch = qsearchs('pay_batch', { batchnum => $batchnum } ); +die "Batch not found: '$batchnum'" if !$pay_batch; + +my $exporttext = $pay_batch->export_batch(%opt); +unless ($exporttext) { + http_header('Content-Type' => 'text/html' ); + $exporttext = < +alert('Batch was empty, and has been resolved'); +window.top.location.href = '${p}search/pay_batch.cgi?magic=_date;open=1;intransit=1;resolved=1'; + +EOF } -$dbh->commit or die $dbh->errstr if $oldAutoCommit; - -%> - +