2 % $cgi->param('error', $error );
3 <% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %>
5 <% header(emt($message)) %>
6 <SCRIPT TYPE="text/javascript">
7 window.top.location.reload();
13 my $curuser = $FS::CurrentUser::CurrentUser;
15 unless $curuser->access_right('One-time charge');
18 my $conf = new FS::conf;
19 my $param = $cgi->Vars;
22 for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
23 push @description, $param->{"description$row"}
24 if ($param->{"description$row"} =~ /\S/);
27 $param->{"custnum"} =~ /^(\d+)$/
28 or $error .= "Illegal customer number " . $param->{"custnum"} . " ";
31 my $cust_main = FS::cust_main->by_key($custnum)
32 or die "custnum $custnum not found";
34 exists($curuser->agentnums_href->{$cust_main->agentnum})
35 or die "access denied";
39 if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
40 $message = "One-time charge changed";
43 unless $curuser->access_right('Modify one-time charge');
45 my $cust_pkg = FS::cust_pkg->by_key($1)
46 or die "pkgnum $pkgnum not found";
48 my $part_pkg = $cust_pkg->part_pkg;
49 die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
51 my ($amount, $setup_cost, $quantity);
52 if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
53 $amount = sprintf('%.2f', $1);
55 if ( $cgi->param('setup_cost') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
56 $setup_cost = sprintf('%.2f', $1);
58 if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
62 my $start_date = $cgi->param('start_date')
63 ? parse_datetime($cgi->param('start_date'))
66 $error = $cust_pkg->modify_charge(
67 'pkg' => scalar($cgi->param('pkg')),
68 'classnum' => scalar($cgi->param('classnum')),
69 'additional' => \@description,
70 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
72 'setup_cost' => $setup_cost,
73 'quantity' => $quantity,
74 'start_date' => $start_date,
77 } else { # the usual case: new one-time charge
79 $message = "One-time charge added";
81 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
82 or $error .= "Illegal amount " . $param->{"amount"} . " ";
86 if ( $param->{setup_cost} =~ /\S/ ) {
87 $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
88 or $error .= "Illegal setup_cost " . $param->{setup_cost} . " ";
93 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
97 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
98 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
101 if ( $param->{'taxclass'} eq '(select)' ) {
102 $error .= "Must select a tax class. "
103 unless ($conf->exists('enable_taxproducts') &&
104 ( $override || $param->{taxproductnum} )
106 $cgi->param('taxclass', '');
110 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
111 or $error .= "Unknown customer number $custnum. ";
113 $error ||= $cust_main->charge( {
115 'setup_cost' => $setup_cost,
116 'quantity' => $quantity,
117 'bill_now' => scalar($cgi->param('bill_now')),
118 'invoice_terms' => scalar($cgi->param('invoice_terms')),
119 'start_date' => ( scalar($cgi->param('start_date'))
120 ? parse_datetime($cgi->param('start_date'))
123 'no_auto' => scalar($cgi->param('no_auto')),
124 'pkg' => scalar($cgi->param('pkg')),
125 'setuptax' => scalar($cgi->param('setuptax')),
126 'taxclass' => scalar($cgi->param('taxclass')),
127 'taxproductnum' => scalar($cgi->param('taxproductnum')),
128 'tax_override' => $override,
129 'classnum' => scalar($cgi->param('classnum')),
130 'additional' => \@description,