Fix 'Can't use an undefined value as an ARRAY reference at /usr/local/share/perl...
[freeside.git] / httemplate / edit / process / quick-charge.cgi
1 %
2 %  my $error = '';
3 %  my $param = $cgi->Vars;
4 %
5 %  my @description = ();
6 %  for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
7 %    push @description, $param->{"description$row"}
8 %      if ($param->{"description$row"} =~ /\S/);
9 %  }
10 %
11 %  $param->{"custnum"} =~ /^(\d+)$/
12 %    or $error .= "Illegal customer number " . $param->{"custnum"} . "  ";
13 %  my $custnum = $1;
14 %
15 %  $param->{"amount"} =~ /^\s*(\d+(\.\d{1,2})?)\s*$/
16 %    or $error .= "Illegal amount " . $param->{"amount"} . "  ";
17 %  my $amount = $1;
18 %
19 %  if ( $param->{'taxclass'} eq '(select)' ) {
20 %    $error .= "Must select a tax class.  ";
21 %  }
22 %
23 %  unless ( $error ) {
24 %    my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
25 %      or $error .= "Unknown customer number $custnum.  ";
26 %
27 %    $error ||= $cust_main->charge( {
28 %      'amount'     => $amount,
29 %      'pkg'        => scalar($cgi->param('pkg')),
30 %      'taxclass'   => scalar($cgi->param('taxclass')),
31 %      'additional' => \@description,
32 %    } );
33 %  }
34 %
35 %  if ( $error ) {
36 %
37 %    $cgi->param('error', $error );
38 %    
39 <% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %>
40 %
41 % }
42 <% header("One-time charge added") %>
43   <SCRIPT TYPE="text/javascript">
44     window.top.location.reload();
45   </SCRIPT>
46   </BODY></HTML>