2 % unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch');
4 % my $param = $cgi->Vars;
6 % #my $paybatch = $param->{'paybatch'};
7 % my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
11 % #while ( exists($param->{"custnum$row"}) ) {
12 % for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
13 % my $custnum = $param->{"custnum$row"};
15 % if ( $custnum =~ /^(\d+)$/ and $1 <= 2147483647 ) {
16 % $cust_main = qsearchs({
17 % 'table' => 'cust_main',
18 % 'hashref' => { 'custnum' => $1 },
19 % 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
22 % if ( length($custnum) and !$cust_main ) { # not found, try agent_custid
23 % $cust_main = qsearchs({
24 % 'table' => 'cust_main',
25 % 'hashref' => { 'agent_custid' => $custnum },
26 % 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
29 % $custnum = $cust_main->custnum if $cust_main;
30 % # if !$cust_main, then this will throw an error on batch_insert
32 % push @cust_pay, new FS::cust_pay {
33 % 'custnum' => $custnum,
34 % 'paid' => $param->{"paid$row"},
36 % 'payinfo' => $param->{"payinfo$row"},
37 % 'discount_term' => $param->{"discount_term$row"},
38 % 'paybatch' => $paybatch,
40 % if $param->{"custnum$row"}
41 % || $param->{"paid$row"}
42 % || $param->{"payinfo$row"};
46 % my @errors = FS::cust_pay->batch_insert(@cust_pay);
47 % my $num_errors = scalar(grep $_, @errors);
49 % if ( $num_errors ) {
51 % $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
52 % ' - Batch not processed, correct and resubmit'
56 % $cgi->param('error'. $erow++, shift @errors) while @errors;
58 % my $query = $m->scomp('/elements/create_uri_query');
60 <% $cgi->redirect($p."batch-cust_pay.html?$query")
66 <% $cgi->redirect(popurl(3). "search/cust_pay.html?magic=paybatch;paybatch=$paybatch") %>