f614dd5cfd96a07e23c3bf0410df2dc93723abd5
[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 %  }
9 %  pop @description until ($description[$#description]);
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({ 'amount'   => $amount,
28 %                                   'pkg'      => $cgi->param('pkg'),
29 %                                   'taxclass' => $cgi->param('taxclass'),
30 %                                   'additional' => \@description,
31 %                                 }
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>
47