1 <% $cgi->redirect($redirect) %>
4 my $curuser = $FS::CurrentUser::CurrentUser;
6 unless $curuser->access_right('One-time charge');
9 my $conf = new FS::conf;
10 my $param = $cgi->Vars;
13 for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
14 push @description, $param->{"description$row"}
15 if ($param->{"description$row"} =~ /\S/);
18 my( $cust_main, $prospect_main, $quotation ) = ( '', '', '' );
19 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
20 $quotation = FS::quotation->by_key($1) or die "quotationnum $1 not found";
22 if ( $param->{"custnum"} =~ /^(\d+)$/ ) {
23 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
24 exists($curuser->agentnums_href->{$cust_main->agentnum})
25 or die "access denied";
27 if ( $param->{"prospectnum"} =~ /^(\d+)$/ ) {
28 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
29 exists($curuser->agentnums_href->{$prospect_main->agentnum})
30 or die "access denied";
35 if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
36 $message = "One-time charge changed";
39 unless $curuser->access_right('Modify one-time charge');
41 my $cust_pkg = FS::cust_pkg->by_key($1)
42 or die "pkgnum $pkgnum not found";
44 my $part_pkg = $cust_pkg->part_pkg;
45 die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
47 my ($amount, $setup_cost, $quantity);
48 if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
49 $amount = sprintf('%.2f', $1);
51 if ( $cgi->param('setup_cost') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
52 $setup_cost = sprintf('%.2f', $1);
54 if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
58 my $start_date = $cgi->param('start_date')
59 ? parse_datetime($cgi->param('start_date'))
62 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
63 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
66 if ( $param->{'taxclass'} eq '(select)' ) {
67 $error .= "Must select a tax class. "
68 unless ($conf->config('tax_data_vendor') &&
69 ( $override || $param->{taxproductnum} )
71 $cgi->param('taxclass', '');
74 $error = $cust_pkg->modify_charge(
75 'pkg' => scalar($cgi->param('pkg')),
76 'classnum' => scalar($cgi->param('classnum')),
77 'additional' => \@description,
78 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
80 'setup_cost' => $setup_cost,
81 'setuptax' => scalar($cgi->param('setuptax')),
82 'taxclass' => scalar($cgi->param('taxclass')),
83 'taxproductnum' => scalar($cgi->param('taxproductnum')),
84 'tax_override' => $override,
85 'quantity' => $quantity,
86 'start_date' => $start_date,
87 'separate_bill' => scalar($cgi->param('separate_bill')),
90 } else { # the usual case: new one-time charge
92 $message = "One-time charge added";
94 $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
95 or $error .= "Illegal amount " . $param->{"amount"} . " ";
99 if ( $param->{setup_cost} =~ /\S/ ) {
100 $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
101 or $error .= "Illegal setup_cost " . $param->{setup_cost} . " ";
106 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
110 $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
111 or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
114 if ( $param->{'taxclass'} eq '(select)' ) {
115 $error .= "Must select a tax class. "
116 unless ($conf->config('tax_data_vendor') &&
117 ( $override || $param->{taxproductnum} )
119 $cgi->param('taxclass', '');
124 'setup_cost' => $setup_cost,
125 'quantity' => $quantity,
126 'bill_now' => scalar($cgi->param('bill_now')),
127 'invoice_terms' => scalar($cgi->param('invoice_terms')),
128 'start_date' => ( scalar($cgi->param('start_date'))
129 ? parse_datetime($cgi->param('start_date'))
132 'no_auto' => scalar($cgi->param('no_auto')),
133 'separate_bill' => scalar($cgi->param('separate_bill')),
134 'pkg' => scalar($cgi->param('pkg')),
135 'setuptax' => scalar($cgi->param('setuptax')),
136 'taxclass' => scalar($cgi->param('taxclass')),
137 'taxproductnum' => scalar($cgi->param('taxproductnum')),
138 'tax_override' => $override,
139 'classnum' => scalar($cgi->param('classnum')),
140 'additional' => \@description,
144 $error ||= $quotation->charge( \%charge );
146 $error ||= $cust_main->charge( \%charge );
153 $cgi->param('error', $error );
154 $redirect = $p.'quick-charge.html?'. $cgi->query_string;
155 } elsif ( $quotation ) {
156 $redirect = $fsurl.'view/quotation.html?' . $quotation->quotationnum;
158 $redirect = $fsurl.'view/cust_main.cgi?custnum=' . $cust_main->custnum . ';show=last';