voxlinesystems CDRs and quantity bs
[freeside.git] / httemplate / edit / process / quick-charge.cgi
1 % if ( $error ) {
2 %   $cgi->param('error', $error );
3 <% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %>
4 % } else {
5 <% header("One-time charge added") %>
6   <SCRIPT TYPE="text/javascript">
7     window.top.location.reload();
8   </SCRIPT>
9   </BODY></HTML>
10 % }
11 <%init>
12
13 die "access denied"
14   unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
15
16 my $error = '';
17 my $param = $cgi->Vars;
18
19 my @description = ();
20 for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
21   push @description, $param->{"description$row"}
22     if ($param->{"description$row"} =~ /\S/);
23 }
24
25 $param->{"custnum"} =~ /^(\d+)$/
26   or $error .= "Illegal customer number " . $param->{"custnum"} . "  ";
27 my $custnum = $1;
28
29 $param->{"amount"} =~ /^\s*(\d+(\.\d{1,2})?)\s*$/
30   or $error .= "Illegal amount " . $param->{"amount"} . "  ";
31 my $amount = $1;
32
33 my $quantity = 1;
34 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
35   $quantity = $1;
36 }
37
38 if ( $param->{'taxclass'} eq '(select)' ) {
39   $error .= "Must select a tax class.  ";
40 }
41
42 unless ( $error ) {
43   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
44     or $error .= "Unknown customer number $custnum.  ";
45
46   $error ||= $cust_main->charge( {
47     'amount'     => $amount,
48     'quantity'   => $quantity,
49     'pkg'        => scalar($cgi->param('pkg')),
50     'taxclass'   => scalar($cgi->param('taxclass')),
51     'classnum'   => scalar($cgi->param('classnum')),
52     'additional' => \@description,
53   } );
54 }
55
56 </%init>