From 50f25b285b2caf77d267ed66f03e56924ad7229f Mon Sep 17 00:00:00 2001 From: jeff Date: Sat, 20 May 2006 20:06:30 +0000 Subject: first stab at BoM download --- httemplate/misc/download-batch.cgi | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 306ef5d63..5a98f1d51 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,16 +1,79 @@ <% +my $conf=new FS::Conf; + #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; + +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"; +} + + for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } - qsearch('cust_pay_batch', {} ) + 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"; +} + +} + +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"; +} + +$dbh->commit or die $dbh->errstr if $oldAutoCommit; + +%> -%>,,,,<%= $cust_pay_batch->cardnum %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %> -<% } %> -- cgit v1.2.1 From 44c866ddd722374379813d774f609ef43f39dfbc Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Jun 2006 00:27:43 +0000 Subject: s/printf/sprintf/ and make the config a little less strange --- httemplate/misc/download-batch.cgi | 66 ++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 5a98f1d51..37b31c196 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -5,11 +5,12 @@ my $conf=new FS::Conf; #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 $format; +if ( $cgi->param('format') =~ /^([\w ]+)$/ ) { + $format = $1; +} else { + $format = $conf->config('batch_default_format'); +} my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; @@ -31,11 +32,14 @@ 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; + + my($reformat,$origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = $conf->config("batchconfig-$format"); + %><%= sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,""). + sprintf( "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; +# 1; }else{ die "Unknown format for batch in batchconfig. \n"; } @@ -46,30 +50,36 @@ for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } {'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; + $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") { -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( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); + %><%= sprintf( "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"; + } } 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{ + + %><%= sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ). + sprintf( "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"; } -- cgit v1.2.1 From 2aee6063dd65e588b884181542815f98319419bf Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Jun 2006 00:33:31 +0000 Subject: oops i'm gonna do that too, now that the batch format file is not the same as the batch params files --- httemplate/misc/download-batch.cgi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 37b31c196..88b10eecf 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -33,7 +33,8 @@ 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-$format"); + my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = + $conf->config("batchconfig-$format"); %><%= sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,""). sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct ) %><% -- cgit v1.2.1 From 1904b218cacfe4e96f3fd3b57f7242617099c485 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Jun 2006 00:47:39 +0000 Subject: and fix the name for TD Canada Trust. and that's it for now. really. --- httemplate/misc/download-batch.cgi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 88b10eecf..2d6f8a286 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -6,10 +6,10 @@ my $conf=new FS::Conf; http_header('Content-Type' => 'text/plain' ); my $format; -if ( $cgi->param('format') =~ /^([\w ]+)$/ ) { +if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { $format = $1; } else { - $format = $conf->config('batch_default_format'); + $format = $conf->config('batch-default_format'); } my $oldAutoCommit = $FS::UID::AutoCommit; @@ -39,7 +39,7 @@ if ($format eq "BoM") { sprintf( "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"){ +}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ # 1; }else{ die "Unknown format for batch in batchconfig. \n"; @@ -63,7 +63,7 @@ for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); %><%= sprintf( "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") { + } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") { %>,,,,<%= $cust_pay_batch->payinfo %>,<%= $exp %>,<%= $cust_pay_batch->amount %>,<%= $cust_pay_batch->paybatchnum %><% @@ -78,7 +78,7 @@ if ($format eq "BoM") { %><%= sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ). sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %><% -} elsif ($format eq "CSV file for TD Canada Trust Merchant PC Batch"){ +} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ #1; } else { die "I'm already dead (again), but you did not know that.\n"; -- cgit v1.2.1 From aaad08cae3a0d46d012de5b78360101cda836c30 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 16 Jun 2006 01:23:41 +0000 Subject: value issues and many bits remain --- httemplate/misc/download-batch.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 2d6f8a286..6172b1335 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -16,7 +16,7 @@ my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; -my $pay_batch = qsearchs('pay_batch', {'status'=>''} ); +my $pay_batch = qsearchs('pay_batch', {'status'=>'O'} ); die "No pending batch. \n" unless $pay_batch; my %batchhash = $pay_batch->hash; -- cgit v1.2.1 From 6c375156081be5d2023001ed8eaac9b6db568e95 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 9 Aug 2006 06:43:02 +0000 Subject: batch refactor --- httemplate/misc/download-batch.cgi | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 6172b1335..2c6481493 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -5,6 +5,13 @@ my $conf=new FS::Conf; #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes http_header('Content-Type' => 'text/plain' ); +my $batchnum; +if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { + $batchnum = $1; +} else { + die "No batch number (bad URL) \n"; +} + my $format; if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { $format = $1; @@ -16,11 +23,12 @@ my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; -my $pay_batch = qsearchs('pay_batch', {'status'=>'O'} ); +my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); die "No pending batch. \n" unless $pay_batch; my %batchhash = $pay_batch->hash; $batchhash{'status'} = 'I'; +$batchhash{'download'} = time unless $batchhash{'download'}; my $new = new FS::pay_batch \%batchhash; my $error = $new->replace($pay_batch); die "error updating batch status: $error\n" if $error; @@ -28,8 +36,10 @@ die "error updating batch status: $error\n" if $error; my $batchtotal=0; my $batchcount=0; -my (@date)=localtime(); -my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]); +my (@date)=localtime($new->download); +my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); +my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). + sprintf("%02d", $date[5] % 100); if ($format eq "BoM") { @@ -39,6 +49,14 @@ if ($format eq "BoM") { sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct ) %><% +}elsif ($format eq "PAP"){ + + my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = + $conf->config("batchconfig-$format"); + %><%= sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") + + %><% + }elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ # 1; }else{ @@ -61,7 +79,12 @@ for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } if ($format eq "BoM") { my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); - %><%= sprintf( "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum %><% + %><%= sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %><% + + } elsif ($format eq "PAP"){ + + my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); + %><%= 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) %><% } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") { @@ -75,9 +98,13 @@ for my $cust_pay_batch ( sort { $a->paybatchnum <=> $b->paybatchnum } if ($format eq "BoM") { - %><%= sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ). + %><%= sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ). sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %><% +} elsif ($format eq "PAP"){ + + %><%= sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %><% + } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ #1; } else { -- cgit v1.2.1 From 3ce7691203a7737406bf2d4442f7fd84b81f847e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 23 Aug 2006 22:25:39 +0000 Subject: Will things ever be the same again? It's the final masonize --- httemplate/misc/download-batch.cgi | 243 ++++++++++++++++++++----------------- 1 file changed, 129 insertions(+), 114 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 2c6481493..038aa2049 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,117 +1,132 @@ -<% - -my $conf=new FS::Conf; - -#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes -http_header('Content-Type' => 'text/plain' ); - -my $batchnum; -if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { - $batchnum = $1; -} else { - die "No batch number (bad URL) \n"; -} - -my $format; -if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { - $format = $1; -} else { - $format = $conf->config('batch-default_format'); -} - -my $oldAutoCommit = $FS::UID::AutoCommit; -local $FS::UID::AutoCommit = 0; -my $dbh = dbh; - -my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); -die "No pending batch. \n" unless $pay_batch; - -my %batchhash = $pay_batch->hash; -$batchhash{'status'} = 'I'; -$batchhash{'download'} = time unless $batchhash{'download'}; -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; - -my (@date)=localtime($new->download); -my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); -my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). - sprintf("%02d", $date[5] % 100); - -if ($format eq "BoM") { - - my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = - $conf->config("batchconfig-$format"); - %><%= sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,""). +% +% +%my $conf=new FS::Conf; +% +%#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes +%http_header('Content-Type' => 'text/plain' ); +% +%my $batchnum; +%if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { +% $batchnum = $1; +%} else { +% die "No batch number (bad URL) \n"; +%} +% +%my $format; +%if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { +% $format = $1; +%} else { +% $format = $conf->config('batch-default_format'); +%} +% +%my $oldAutoCommit = $FS::UID::AutoCommit; +%local $FS::UID::AutoCommit = 0; +%my $dbh = dbh; +% +%my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); +%die "No pending batch. \n" unless $pay_batch; +% +%my %batchhash = $pay_batch->hash; +%$batchhash{'status'} = 'I'; +%$batchhash{'download'} = time unless $batchhash{'download'}; +%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; +% +%my (@date)=localtime($new->download); +%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); +%my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). +% sprintf("%02d", $date[5] % 100); +% +%if ($format eq "BoM") { +% +% my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = +% $conf->config("batchconfig-$format"); +% +<% sprintf( "A%10s%04u%06u%05u%54s\n",$origid,$pay_batch->batchnum,$jdate,$datacenter,""). sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct ) - %><% - -}elsif ($format eq "PAP"){ - - my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = - $conf->config("batchconfig-$format"); - %><%= sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") - - %><% - -}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ -# 1; -}else{ - die "Unknown format for batch in batchconfig. \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 ); - %><%= sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %><% - - } elsif ($format eq "PAP"){ - - my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); - %><%= 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) %><% - - } elsif ($format eq "csv-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"; - } - -} - -if ($format eq "BoM") { - - %><%= sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ). - sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %><% - -} elsif ($format eq "PAP"){ - - %><%= sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %><% - -} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ - #1; -} else { - die "I'm already dead (again), but you did not know that.\n"; -} - -$dbh->commit or die $dbh->errstr if $oldAutoCommit; + %> +% +% +%}elsif ($format eq "PAP"){ +% +% my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = +% $conf->config("batchconfig-$format"); +% +<% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") + + %> +% +% +%}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ +%# 1; +%}else{ +% die "Unknown format for batch in batchconfig. \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 ); +% +<% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %> +% +% +% } elsif ($format eq "PAP"){ +% +% my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); +% +<% 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) %> +% +% +% } elsif ($format eq "csv-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"; +% } +% +%} +% +%if ($format eq "BoM") { +% +% +<% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ). + sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %> +% +% +%} elsif ($format eq "PAP"){ +% +% +<% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %> +% +% +%} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ +% #1; +%} else { +% die "I'm already dead (again), but you did not know that.\n"; +%} +% +%$dbh->commit or die $dbh->errstr if $oldAutoCommit; +% +% -%> -- cgit v1.2.1 From 6af1b1bfa25e5ececef5e0dcd38b55917121cee2 Mon Sep 17 00:00:00 2001 From: jeff Date: Sat, 26 Aug 2006 23:15:14 +0000 Subject: batch refactor continued --- httemplate/misc/download-batch.cgi | 44 +++++--------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 038aa2049..ad88092d3 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,17 +1,9 @@ % -% %my $conf=new FS::Conf; % %#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes %http_header('Content-Type' => 'text/plain' ); % -%my $batchnum; -%if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { -% $batchnum = $1; -%} else { -% die "No batch number (bad URL) \n"; -%} -% %my $format; %if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { % $format = $1; @@ -23,12 +15,11 @@ %local $FS::UID::AutoCommit = 0; %my $dbh = dbh; % -%my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); +%my $pay_batch = qsearchs('pay_batch', {'status'=>''} ); %die "No pending batch. \n" unless $pay_batch; % %my %batchhash = $pay_batch->hash; %$batchhash{'status'} = 'I'; -%$batchhash{'download'} = time unless $batchhash{'download'}; %my $new = new FS::pay_batch \%batchhash; %my $error = $new->replace($pay_batch); %die "error updating batch status: $error\n" if $error; @@ -36,10 +27,8 @@ %my $batchtotal=0; %my $batchcount=0; % -%my (@date)=localtime($new->download); -%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); -%my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). -% sprintf("%02d", $date[5] % 100); +%my (@date)=localtime(); +%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]); % %if ($format eq "BoM") { % @@ -51,16 +40,6 @@ %> % % -%}elsif ($format eq "PAP"){ -% -% my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = -% $conf->config("batchconfig-$format"); -% -<% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") - - %> -% -% %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ %# 1; %}else{ @@ -84,14 +63,7 @@ % % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); % -<% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %> -% -% -% } elsif ($format eq "PAP"){ -% -% my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); -% -<% 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) %> +<% sprintf( "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-td_canada_trust-merchant_pc_batch") { @@ -109,16 +81,10 @@ %if ($format eq "BoM") { % % -<% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ). +<% sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ). sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %> % % -%} elsif ($format eq "PAP"){ -% -% -<% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %> -% -% %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ % #1; %} else { -- cgit v1.2.1 From 4142ac8edaafd2791cd89116e2a6883f0be99366 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 27 Aug 2006 19:30:38 +0000 Subject: correct bad conflict resolution --- httemplate/misc/download-batch.cgi | 44 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index ad88092d3..038aa2049 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,9 +1,17 @@ % +% %my $conf=new FS::Conf; % %#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes %http_header('Content-Type' => 'text/plain' ); % +%my $batchnum; +%if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { +% $batchnum = $1; +%} else { +% die "No batch number (bad URL) \n"; +%} +% %my $format; %if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { % $format = $1; @@ -15,11 +23,12 @@ %local $FS::UID::AutoCommit = 0; %my $dbh = dbh; % -%my $pay_batch = qsearchs('pay_batch', {'status'=>''} ); +%my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); %die "No pending batch. \n" unless $pay_batch; % %my %batchhash = $pay_batch->hash; %$batchhash{'status'} = 'I'; +%$batchhash{'download'} = time unless $batchhash{'download'}; %my $new = new FS::pay_batch \%batchhash; %my $error = $new->replace($pay_batch); %die "error updating batch status: $error\n" if $error; @@ -27,8 +36,10 @@ %my $batchtotal=0; %my $batchcount=0; % -%my (@date)=localtime(); -%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7]); +%my (@date)=localtime($new->download); +%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); +%my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). +% sprintf("%02d", $date[5] % 100); % %if ($format eq "BoM") { % @@ -40,6 +51,16 @@ %> % % +%}elsif ($format eq "PAP"){ +% +% my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = +% $conf->config("batchconfig-$format"); +% +<% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") + + %> +% +% %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ %# 1; %}else{ @@ -63,7 +84,14 @@ % % my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); % -<% sprintf( "D%010u%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->invnum %> +<% sprintf( "D%010.0f%09u%-12s%-29s%-19s\n",$cust_pay_batch->amount*100,$aba,$account,$cust_pay_batch->payname,$cust_pay_batch->paybatchnum) %> +% +% +% } elsif ($format eq "PAP"){ +% +% my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo ); +% +<% 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) %> % % % } elsif ($format eq "csv-td_canada_trust-merchant_pc_batch") { @@ -81,10 +109,16 @@ %if ($format eq "BoM") { % % -<% sprintf( "YD%08u%014u%56s\n",$batchcount,$batchtotal*100,"" ). +<% sprintf( "YD%08u%014.0f%56s\n",$batchcount,$batchtotal*100,"" ). sprintf( "Z%014u%05u%014u%05u%41s\n",$batchtotal*100,$batchcount,"0","0","" ) %> % % +%} elsif ($format eq "PAP"){ +% +% +<% sprintf( "T%08u%014.0f%57s\n",$batchcount,$batchtotal*100,"" ) %> +% +% %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ % #1; %} else { -- cgit v1.2.1 From 2c8748ac26281934a1b75671c6a5d0125145660a Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 1 Dec 2006 06:31:55 +0000 Subject: chase canada E-xactBatch --- httemplate/misc/download-batch.cgi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 038aa2049..a1e7b5c44 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -40,6 +40,8 @@ %my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); %my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). % sprintf("%02d", $date[5] % 100); +%my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1). +% '/'.sprintf("%02d", $date[3]); % %if ($format eq "BoM") { % @@ -63,6 +65,12 @@ % %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ %# 1; +%}elsif ($format eq "csv-chase_canada-E-xactBatch"){ +% +% my($origid) = $conf->config("batchconfig-$format"); +<% sprintf( '$$E-xactBatchFileV1.0$$%s:%03u$$%s',$sdate,$pay_batch->batchnum, $origid) + %> +% %}else{ % die "Unknown format for batch in batchconfig. \n"; %} @@ -100,6 +108,12 @@ ,,,,<% $cust_pay_batch->payinfo %>,<% $exp %>,<% $cust_pay_batch->amount %>,<% $cust_pay_batch->paybatchnum %> % % +% } elsif ($format eq "csv-chase_canada-E-xactBatch"){ +% +% +<% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $cust_pay_batch->payname %>",01,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,, +% +% % } else { % die "I'm already dead, but you did not know that.\n"; % } @@ -121,6 +135,8 @@ % %} elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ % #1; +%} elsif ($format eq "csv-chase_canada-E-xactBatch"){ +% #1; %} else { % die "I'm already dead (again), but you did not know that.\n"; %} -- cgit v1.2.1 From a3e2c44624aa50e408046e77e6b1cd5d9c20b4c2 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 10 Jan 2007 00:41:36 +0000 Subject: permit batch redownloads --- httemplate/misc/download-batch.cgi | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index a1e7b5c44..7e6750c58 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -24,6 +24,10 @@ %my $dbh = dbh; % %my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); +%unless ($pay_batch) { +% $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} ) +% if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches'); +%} %die "No pending batch. \n" unless $pay_batch; % %my %batchhash = $pay_batch->hash; -- cgit v1.2.1 From db690b75431c6bcff432930db1646f316d2e7154 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 15 Jan 2007 07:53:54 +0000 Subject: add batch expiration date incrementer for 295 --- httemplate/misc/download-batch.cgi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 7e6750c58..74805b2a8 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -87,7 +87,13 @@ % % $cust_pay_batch->exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/; % my( $mon, $y ) = ( $2, $1 ); -% $mon = "0$mon" if $mon < 10; +% if ( $conf->exists('batch-increment_expiration') ) { +% my( $curmon, $curyear ) = (localtime(time))[4,5]; +% $curmon++; $curyear-=100; +% $y++ while $y < $curyear || ( $y == $curyear && $mon < $curmon ); +% } +% $mon = "0$mon" if $mon =~ /^\d$/; +% $y = "0$y" if $y =~ /^\d$/; % my $exp = "$mon$y"; % $batchcount++; % $batchtotal += $cust_pay_batch->amount; -- cgit v1.2.1 From 216136a9a2aed14a099b9cc931c5b21a29c04894 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 19 Jan 2007 23:00:36 +0000 Subject: work around CSV brokenness --- httemplate/misc/download-batch.cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 74805b2a8..371f17d19 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -120,8 +120,8 @@ % % } elsif ($format eq "csv-chase_canada-E-xactBatch"){ % -% -<% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $cust_pay_batch->payname %>",01,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,, +% my $payname=$cust_pay_batch->payname; $payname =~ tr/",/ /; #payinfo too? :P +<% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",01,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,, % % % } else { -- cgit v1.2.1 From ddf21d3a3e70b4839e6b5db7a154ccc118026209 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 24 Jan 2007 23:41:46 +0000 Subject: 00 = sale, 01 = pre-auth. we need the former --- httemplate/misc/download-batch.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index 371f17d19..b6af849b9 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -121,7 +121,7 @@ % } elsif ($format eq "csv-chase_canada-E-xactBatch"){ % % my $payname=$cust_pay_batch->payname; $payname =~ tr/",/ /; #payinfo too? :P -<% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",01,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,, +<% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",00,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,, % % % } else { -- cgit v1.2.1 From dcbca21adce59e19ee6c602c648c1033869e116b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 5 Feb 2007 09:45:45 +0000 Subject: upon first download, have batches auto-set amount to customer balance if it is smaller --- httemplate/misc/download-batch.cgi | 123 ++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 55 deletions(-) (limited to 'httemplate/misc/download-batch.cgi') diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi index b6af849b9..8d6c94969 100644 --- a/httemplate/misc/download-batch.cgi +++ b/httemplate/misc/download-batch.cgi @@ -1,52 +1,3 @@ -% -% -%my $conf=new FS::Conf; -% -%#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes -%http_header('Content-Type' => 'text/plain' ); -% -%my $batchnum; -%if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { -% $batchnum = $1; -%} else { -% die "No batch number (bad URL) \n"; -%} -% -%my $format; -%if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { -% $format = $1; -%} else { -% $format = $conf->config('batch-default_format'); -%} -% -%my $oldAutoCommit = $FS::UID::AutoCommit; -%local $FS::UID::AutoCommit = 0; -%my $dbh = dbh; -% -%my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); -%unless ($pay_batch) { -% $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} ) -% if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches'); -%} -%die "No pending batch. \n" unless $pay_batch; -% -%my %batchhash = $pay_batch->hash; -%$batchhash{'status'} = 'I'; -%$batchhash{'download'} = time unless $batchhash{'download'}; -%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; -% -%my (@date)=localtime($new->download); -%my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); -%my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). -% sprintf("%02d", $date[5] % 100); -%my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1). -% '/'.sprintf("%02d", $date[3]); -% %if ($format eq "BoM") { % % my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = @@ -56,15 +7,12 @@ sprintf( "XD%03u%06u%-15s%-30s%09u%-12s \n",$typecode,$jdate,$shortname,$longname,$mybank,$myacct ) %> % -% %}elsif ($format eq "PAP"){ % % my($origid,$datacenter,$typecode,$shortname,$longname,$mybank,$myacct) = % $conf->config("batchconfig-$format"); % -<% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") - - %> +<% sprintf( "H%10sD%3s%06u%-15s%09u%-12s%04u%19s\n",$origid,$typecode,$cdate,$shortname,$mybank,$myacct,$pay_batch->batchnum,"") %> % % %}elsif ($format eq "csv-td_canada_trust-merchant_pc_batch"){ @@ -95,6 +43,27 @@ % $mon = "0$mon" if $mon =~ /^\d$/; % $y = "0$y" if $y =~ /^\d$/; % my $exp = "$mon$y"; +% +% if ( $first_download ) { +% my $balance = $cust_pay_batch->cust_main->balance; +% if ( $balance <= 0 ) { +% my $error = $cust_pay_batch->delete; +% if ( $error ) { +% $dbh->rollback or die $dbh->errstr if $oldAutoCommit; +% die $error; +% } +% next; +% } elsif ( $balance < $cust_pay_batch->amount ) { +% $cust_pay_batch->amount($balance); +% my $error = $cust_pay_batch->replace; +% if ( $error ) { +% $dbh->rollback or die $dbh->errstr if $oldAutoCommit; +% die $error; +% } +% #} elsif ( $balance > $cust_pay_batch->amount ) { +% } +% } +% % $batchcount++; % $batchtotal += $cust_pay_batch->amount; % @@ -152,7 +121,51 @@ %} % %$dbh->commit or die $dbh->errstr if $oldAutoCommit; -% -% +<%init> + +my $conf=new FS::Conf; + +#http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes +http_header('Content-Type' => 'text/plain' ); + +my $batchnum; +if ( $cgi->param('batchnum') =~ /^(\d+)$/ ) { + $batchnum = $1; +} else { + die "No batch number (bad URL) \n"; +} + +my $format; +if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) { + $format = $1; +} else { + $format = $conf->config('batch-default_format'); +} + +my $oldAutoCommit = $FS::UID::AutoCommit; +local $FS::UID::AutoCommit = 0; +my $dbh = dbh; + +my $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'O'} ); +my $first_download = 1; +unless ($pay_batch) { + $pay_batch = qsearchs('pay_batch', {'batchnum'=>$batchnum, 'status'=>'I'} ) + if $FS::CurrentUser::CurrentUser->access_right('Reprocess batches'); + $first_download = 0; +} +die "No pending batch. \n" unless $pay_batch; + +my $error = $pay_batch->set_status('I'); +die "error updating batch status: $error\n" if $error; + +my $batchtotal=0; +my $batchcount=0; +my (@date)=localtime($pay_batch->download); +my $jdate = sprintf("%03d", $date[5] % 100).sprintf("%03d", $date[7] + 1); +my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1). + sprintf("%02d", $date[5] % 100); +my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1). + '/'.sprintf("%02d", $date[3]); + -- cgit v1.2.1