X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Fbatch-cust_pay.cgi;h=0720fdadad34ddc27cc27ba0ebbed6a533c1b472;hb=94b60bb13c044e436800239be3e3c5a029bdff8e;hp=3b06f3ab70c2a8f7ada54272ab13c75c9485b386;hpb=43e6b2ea06434abead940939c9b04e00e3a72f32;p=freeside.git diff --git a/httemplate/misc/process/batch-cust_pay.cgi b/httemplate/misc/process/batch-cust_pay.cgi index 3b06f3ab7..0720fdada 100644 --- a/httemplate/misc/process/batch-cust_pay.cgi +++ b/httemplate/misc/process/batch-cust_pay.cgi @@ -1,5 +1,5 @@ <%init> -my $DEBUG = 1; +my $DEBUG = 0; die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch'); @@ -12,7 +12,8 @@ my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time); my @cust_pay = (); #my $row = 0; #while ( exists($param->{"custnum$row"}) ) { -for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) { +my @invrows = grep(/^invnum\d+\.\d+$/, keys %$param); +foreach my $row ( map /^custnum(\d+)$/, keys %$param ) { my $custnum = $param->{"custnum$row"}; my $cust_main; if ( $custnum =~ /^(\d+)$/ and $1 <= 2147483647 ) { @@ -32,13 +33,17 @@ for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) { $custnum = $cust_main->custnum if $cust_main; # if !$cust_main, then this will throw an error on batch_insert + my $_date = $param->{"_date$row"} ? parse_datetime($param->{"_date$row"}) : ''; + my $cust_pay = new FS::cust_pay { 'custnum' => $custnum, 'paid' => $param->{"paid$row"}, 'payby' => 'BILL', 'payinfo' => $param->{"payinfo$row"}, + '_date' => $_date, 'discount_term' => $param->{"discount_term$row"}, 'paybatch' => $paybatch, + 'no_auto_apply' => exists($param->{"no_auto_apply$row"}) ? 'Y' : '', } if $param->{"custnum$row"} || $param->{"paid$row"} @@ -48,7 +53,8 @@ for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) { # payment applications, if any my @cust_bill_pay = (); - for ( my $app = 0; exists($param->{"invnum$row.$app"}); $app++ ) { + foreach my $app ( sort {$a <=> $b} map /^invnum$row\.(\d+)$/, @invrows ) { +# for ( my $app = 0; exists($param->{"invnum$row.$app"}); $app++ ) { next if !$param->{"invnum$row.$app"}; push @cust_bill_pay, new FS::cust_bill_pay { 'invnum' => $param->{"invnum$row.$app"},