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 'start_date' => ( scalar($cgi->param('start_date'))
127 ? parse_datetime($cgi->param('start_date'))
130 'tax_override' => $override,
131 'additional' => \@description,
133 map { $_ => scalar($cgi->param($_)), } qw(
134 bill_now invoice_terms no_auto separate_bill pkg
135 setuptax taxclass taxproductnum classnum
136 setup_discountnum setup_discountnum_amount setup_discountnum_percent
141 $error ||= $quotation->charge( \%charge );
143 $error ||= $cust_main->charge( \%charge );
150 $cgi->param('error', $error );
151 @redirect = ( $p.'quick-charge.html?'. $cgi->query_string );
152 } elsif ( $quotation ) {
154 -uri => $fsurl.'view/quotation.html?' . $quotation->quotationnum,
155 -cookie => CGI::Cookie->new( -name => 'freeside_status',
156 -value => mt('One-time charge added to quotation'),
162 -uri => $fsurl.'view/cust_main.cgi?custnum='. $cust_main->custnum.
164 -cookie => CGI::Cookie->new( -name => 'freeside_status',
165 -value => mt('One-time charge ordered'),