prepayment discounts rt#5318
[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 %                      'discount_term'  => $param->{"discount_term$row"},
19 %                      'paybatch'       => $paybatch,
20 %                    }
21 %      if    $param->{"custnum$row"}
22 %         || $param->{"paid$row"}
23 %         || $param->{"payinfo$row"};
24 %    #$row++;
25 %  }
26 %
27 %  my @errors = FS::cust_pay->batch_insert(@cust_pay);
28 %  my $num_errors = scalar(grep $_, @errors);
29 %
30 %  if ( $num_errors ) {
31 %
32 %    $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
33 %                         ' - Batch not processed, correct and resubmit'
34 %               );
35 %
36 %    my $erow=0;
37 %    $cgi->param('error'. $erow++, shift @errors) while @errors;
38 %
39 %    
40 <% $cgi->redirect($p.'batch-cust_pay.html?'. $cgi->query_string)
41
42   %>
43 % } else {
44 %
45 %    
46 <% $cgi->redirect(popurl(3). "search/cust_pay.html?magic=paybatch;paybatch=$paybatch") %>
47 % } 
48