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 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
72 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
75 if ( $param->{'taxclass'} eq '(select)' ) {
76 $error .= "Must select a tax class. "
77 unless ($conf->exists('enable_taxproducts') &&
78 ( $override || $param->{taxproductnum} )
80 $cgi->param('taxclass', '');
83 $error = $cust_pkg->modify_charge(
84 'pkg' => scalar($cgi->param('pkg')),
85 'classnum' => scalar($cgi->param('classnum')),
86 'additional' => \@description,
87 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
89 'setup_cost' => $setup_cost,
90 'setuptax' => scalar($cgi->param('setuptax')),
91 'taxclass' => scalar($cgi->param('taxclass')),
92 'taxproductnum' => scalar($cgi->param('taxproductnum')),
93 'tax_override' => $override,
94 'quantity' => $quantity,
95 'start_date' => $start_date,
96 'separate_bill' => scalar($cgi->param('separate_bill')),
99 } else { # the usual case: new one-time charge
101 $message = "One-time charge added";
103 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
104 or $error .= "Illegal amount " . $param->{"amount"} . " ";
108 if ( $param->{setup_cost} =~ /\S/ ) {
109 $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
110 or $error .= "Illegal setup_cost " . $param->{setup_cost} . " ";
115 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
119 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
120 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
123 if ( $param->{'taxclass'} eq '(select)' ) {
124 $error .= "Must select a tax class. "
125 unless ($conf->exists('enable_taxproducts') &&
126 ( $override || $param->{taxproductnum} )
128 $cgi->param('taxclass', '');
133 'setup_cost' => $setup_cost,
134 'quantity' => $quantity,
135 'bill_now' => scalar($cgi->param('bill_now')),
136 'invoice_terms' => scalar($cgi->param('invoice_terms')),
137 'start_date' => ( scalar($cgi->param('start_date'))
138 ? parse_datetime($cgi->param('start_date'))
141 'no_auto' => scalar($cgi->param('no_auto')),
142 'separate_bill' => scalar($cgi->param('separate_bill')),
143 'pkg' => scalar($cgi->param('pkg')),
144 'setuptax' => scalar($cgi->param('setuptax')),
145 'taxclass' => scalar($cgi->param('taxclass')),
146 'taxproductnum' => scalar($cgi->param('taxproductnum')),
147 'tax_override' => $override,
148 'classnum' => scalar($cgi->param('classnum')),
149 'additional' => \@description,
153 $error ||= $quotation->charge( \%charge );
155 $error ||= $cust_main->charge( \%charge );