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 my( $cust_main, $prospect_main, $quotation ) = ( '', '', '' );
28 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
29 $quotation = FS::quotation->by_key($1) or die "quotationnum $1 not found";
31 if ( $param->{"custnum"} =~ /^(\d+)$/ ) {
32 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
33 exists($curuser->agentnums_href->{$cust_main->agentnum})
34 or die "access denied";
36 if ( $param->{"prospectnum"} =~ /^(\d+)$/ ) {
37 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
38 exists($curuser->agentnums_href->{$prospect_main->agentnum})
39 or die "access denied";
44 if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
45 $message = "One-time charge changed";
48 unless $curuser->access_right('Modify one-time charge');
50 my $cust_pkg = FS::cust_pkg->by_key($1)
51 or die "pkgnum $pkgnum not found";
53 my $part_pkg = $cust_pkg->part_pkg;
54 die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
56 my ($amount, $setup_cost, $quantity);
57 if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
58 $amount = sprintf('%.2f', $1);
60 if ( $cgi->param('setup_cost') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
61 $setup_cost = sprintf('%.2f', $1);
63 if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
67 my $start_date = $cgi->param('start_date')
68 ? parse_datetime($cgi->param('start_date'))
71 $error = $cust_pkg->modify_charge(
72 'pkg' => scalar($cgi->param('pkg')),
73 'classnum' => scalar($cgi->param('classnum')),
74 'additional' => \@description,
75 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
77 'setup_cost' => $setup_cost,
78 'quantity' => $quantity,
79 'start_date' => $start_date,
82 } else { # the usual case: new one-time charge
84 $message = "One-time charge added";
86 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
87 or $error .= "Illegal amount " . $param->{"amount"} . " ";
91 if ( $param->{setup_cost} =~ /\S/ ) {
92 $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
93 or $error .= "Illegal setup_cost " . $param->{setup_cost} . " ";
98 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
102 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
103 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
106 if ( $param->{'taxclass'} eq '(select)' ) {
107 $error .= "Must select a tax class. "
108 unless ($conf->exists('enable_taxproducts') &&
109 ( $override || $param->{taxproductnum} )
111 $cgi->param('taxclass', '');
116 'setup_cost' => $setup_cost,
117 'quantity' => $quantity,
118 'bill_now' => scalar($cgi->param('bill_now')),
119 'invoice_terms' => scalar($cgi->param('invoice_terms')),
120 'start_date' => ( scalar($cgi->param('start_date'))
121 ? parse_datetime($cgi->param('start_date'))
124 'no_auto' => scalar($cgi->param('no_auto')),
125 'pkg' => scalar($cgi->param('pkg')),
126 'setuptax' => scalar($cgi->param('setuptax')),
127 'taxclass' => scalar($cgi->param('taxclass')),
128 'taxproductnum' => scalar($cgi->param('taxproductnum')),
129 'tax_override' => $override,
130 'classnum' => scalar($cgi->param('classnum')),
131 'additional' => \@description,
135 $error ||= $quotation->charge( \%charge );
137 $error ||= $cust_main->charge( \%charge );