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