This commit was generated by cvs2svn to compensate for changes in r6255,
[freeside.git] / httemplate / misc / process / batch-cust_pay.cgi
1 %  die "access denied"
2 %    unless $FS::CurrentUser::CurrentUser->access_right('Post payment batch');
3 %
4 %  my $param = $cgi->Vars;
5 %
6 %  #my $paybatch = $param->{'paybatch'};
7 %  my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
8 %
9 %  my @cust_pay = ();
10 %  #my $row = 0;
11 %  #while ( exists($param->{"custnum$row"}) ) {
12 %  for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
13 %    push @cust_pay, new FS::cust_pay {
14 %                                       'custnum'  => $param->{"custnum$row"},
15 %                                       'paid'     => $param->{"paid$row"},
16 %                                       'payby'    => 'BILL',
17 %                                       'payinfo'  => $param->{"payinfo$row"},
18 %                                       'paybatch' => $paybatch,
19 %                                     }
20 %      if    $param->{"custnum$row"}
21 %         || $param->{"paid$row"}
22 %         || $param->{"payinfo$row"};
23 %    #$row++;
24 %  }
25 %
26 %  my @errors = FS::cust_pay->batch_insert(@cust_pay);
27 %  my $num_errors = scalar(grep $_, @errors);
28 %
29 %  if ( $num_errors ) {
30 %
31 %    $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
32 %                         ' - Batch not processed, correct and resubmit'
33 %               );
34 %
35 %    my $erow=0;
36 %    $cgi->param('error'. $erow++, shift @errors) while @errors;
37 %
38 %    
39 <% $cgi->redirect($p.'batch-cust_pay.html?'. $cgi->query_string)
40
41   %>
42 % } else {
43 %
44 %    
45 <% $cgi->redirect(popurl(3). "search/cust_pay.cgi?magic=paybatch;paybatch=$paybatch") %>
46 % } 
47