+ my $start_date = $cgi->param('start_date')
+ ? parse_datetime($cgi->param('start_date'))
+ : time;
+
+ $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
+ or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
+ my $override = $1;
+
+ if ( $param->{'taxclass'} eq '(select)' ) {
+ $error .= "Must select a tax class. "
+ unless ($conf->config('tax_data_vendor') &&
+ ( $override || $param->{taxproductnum} )
+ );
+ $cgi->param('taxclass', '');
+ }
+
+ $error = $cust_pkg->modify_charge(
+ 'pkg' => scalar($cgi->param('pkg')),
+ 'classnum' => scalar($cgi->param('classnum')),
+ 'additional' => \@description,
+ 'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
+ 'amount' => $amount,
+ 'setup_cost' => $setup_cost,
+ 'setuptax' => scalar($cgi->param('setuptax')),
+ 'taxclass' => scalar($cgi->param('taxclass')),
+ 'taxproductnum' => scalar($cgi->param('taxproductnum')),
+ 'tax_override' => $override,
+ 'quantity' => $quantity,
+ 'start_date' => $start_date,
+ 'separate_bill' => scalar($cgi->param('separate_bill')),
+ );
+
+} else { # the usual case: new one-time charge
+
+ $message = "One-time charge added";
+
+ $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+ or $error .= "Illegal amount " . $param->{"amount"} . " ";
+ my $amount = $1;
+
+ my $setup_cost = '';
+ if ( $param->{setup_cost} =~ /\S/ ) {
+ $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+ or $error .= "Illegal setup_cost " . $param->{setup_cost} . " ";
+ $setup_cost = $1;
+ }
+
+ my $quantity = 1;
+ if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
+ $quantity = $1;
+ }
+
+ $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
+ or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
+ my $override = $1;
+
+ if ( $param->{'taxclass'} eq '(select)' ) {
+ $error .= "Must select a tax class. "
+ unless ($conf->config('tax_data_vendor'))
+ ( $override || $param->{taxproductnum} )
+ );
+ $cgi->param('taxclass', '');
+ }
+
+ my %charge = (
+ 'amount' => $amount,
+ 'setup_cost' => $setup_cost,
+ 'quantity' => $quantity,
+ 'bill_now' => scalar($cgi->param('bill_now')),
+ 'invoice_terms' => scalar($cgi->param('invoice_terms')),
+ 'start_date' => ( scalar($cgi->param('start_date'))
+ ? parse_datetime($cgi->param('start_date'))
+ : ''
+ ),
+ 'no_auto' => scalar($cgi->param('no_auto')),
+ 'separate_bill' => scalar($cgi->param('separate_bill')),
+ 'pkg' => scalar($cgi->param('pkg')),
+ 'setuptax' => scalar($cgi->param('setuptax')),
+ 'taxclass' => scalar($cgi->param('taxclass')),
+ 'taxproductnum' => scalar($cgi->param('taxproductnum')),
+ 'tax_override' => $override,
+ 'classnum' => scalar($cgi->param('classnum')),
+ 'additional' => \@description,
+ );
+
+ if ( $quotation ) {
+ $error ||= $quotation->charge( \%charge );
+ } else {
+ $error ||= $cust_main->charge( \%charge );
+ }
+
+}