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+)$/ ) {
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, $quantity, $start_date);
52 if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
53 $amount = sprintf('%.2f', $1);
55 if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
58 if ( $cgi->param('start_date') ) {
59 $start_date = parse_datetime($cgi->param('start_date'));
64 $error = $cust_pkg->modify_charge(
65 'pkg' => scalar($cgi->param('pkg')),
66 'classnum' => scalar($cgi->param('classnum')),
67 'additional' => \@description,
68 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
70 'quantity' => $quantity,
71 'start_date' => $start_date,
75 $message = "One-time charge added";
76 # the usual case: new one-time charge
77 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
78 or $error .= "Illegal amount " . $param->{"amount"} . " ";
82 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
86 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
87 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
90 if ( $param->{'taxclass'} eq '(select)' ) {
91 $error .= "Must select a tax class. "
92 unless ($conf->exists('enable_taxproducts') &&
93 ( $override || $param->{taxproductnum} )
95 $cgi->param('taxclass', '');
99 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
100 or $error .= "Unknown customer number $custnum. ";
102 $error ||= $cust_main->charge( {
104 'quantity' => $quantity,
105 'bill_now' => scalar($cgi->param('bill_now')),
106 'invoice_terms' => scalar($cgi->param('invoice_terms')),
107 'start_date' => ( scalar($cgi->param('start_date'))
108 ? parse_datetime($cgi->param('start_date'))
111 'no_auto' => scalar($cgi->param('no_auto')),
112 'pkg' => scalar($cgi->param('pkg')),
113 'setuptax' => scalar($cgi->param('setuptax')),
114 'taxclass' => scalar($cgi->param('taxclass')),
115 'taxproductnum' => scalar($cgi->param('taxproductnum')),
116 'tax_override' => $override,
117 'classnum' => scalar($cgi->param('classnum')),
118 'additional' => \@description,