27921b8c36580e34559b84eb02855cc22a1cbede
[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 $conf = new FS::conf;
18 my $param = $cgi->Vars;
19
20 my @description = ();
21 for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
22   push @description, $param->{"description$row"}
23     if ($param->{"description$row"} =~ /\S/);
24 }
25
26 $param->{"custnum"} =~ /^(\d+)$/
27   or $error .= "Illegal customer number " . $param->{"custnum"} . "  ";
28 my $custnum = $1;
29
30 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
31   or $error .= "Illegal amount " . $param->{"amount"} . "  ";
32 my $amount = $1;
33
34 my $quantity = 1;
35 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
36   $quantity = $1;
37 }
38
39 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
40   or $error .= "Illegal tax override " . $param->{"tax_override"} . "  ";
41 my $override = $1;
42
43 if ( $param->{'taxclass'} eq '(select)' ) {
44   $error .= "Must select a tax class.  "
45     unless ($conf->exists('enable_taxproducts') &&
46              ( $override || $param->{taxproductnum} )
47            );
48   $cgi->param('taxclass', '');
49 }
50
51 unless ( $error ) {
52   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
53     or $error .= "Unknown customer number $custnum.  ";
54
55   $error ||= $cust_main->charge( {
56     'amount'        => $amount,
57     'quantity'      => $quantity,
58     'bill_now'      => scalar($cgi->param('bill_now')),
59     'invoice_terms' => scalar($cgi->param('invoice_terms')),
60     'start_date'    => ( scalar($cgi->param('start_date'))
61                            ? str2time($cgi->param('start_date'))
62                            : ''
63                        ),
64     'no_auto'       => scalar($cgi->param('no_auto')),
65     'pkg'           => scalar($cgi->param('pkg')),
66     'setuptax'      => scalar($cgi->param('setuptax')),
67     'taxclass'      => scalar($cgi->param('taxclass')),
68     'taxproductnum' => scalar($cgi->param('taxproductnum')),
69     'tax_override'  => $override,
70     'classnum'      => scalar($cgi->param('classnum')),
71     'additional'    => \@description,
72   } );
73 }
74
75 </%init>