summaryrefslogtreecommitdiff
path: root/httemplate/edit/process
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-10-12 18:50:20 -0700
committerMark Wells <mark@freeside.biz>2013-10-12 18:50:20 -0700
commitddb0ff57880eeb2183b227592545f2619079d221 (patch)
tree63bf92c229dab41e91c690d079dbeffcaa4e17ee /httemplate/edit/process
parentf9c93506a5f42b4c6dd33e402b9248c66af5b60a (diff)
allow changing package class of one-time charges post-billing, #25342
Diffstat (limited to 'httemplate/edit/process')
-rw-r--r--httemplate/edit/process/quick-charge.cgi108
1 files changed, 68 insertions, 40 deletions
diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi
index 38f06e1e9..db41fb238 100644
--- a/httemplate/edit/process/quick-charge.cgi
+++ b/httemplate/edit/process/quick-charge.cgi
@@ -10,8 +10,9 @@
% }
<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
+ unless $curuser->access_right('One-time charge');
my $error = '';
my $conf = new FS::conf;
@@ -27,49 +28,76 @@ $param->{"custnum"} =~ /^(\d+)$/
or $error .= "Illegal customer number " . $param->{"custnum"} . " ";
my $custnum = $1;
-$param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
- or $error .= "Illegal amount " . $param->{"amount"} . " ";
-my $amount = $1;
+my $cust_main = FS::cust_main->by_key($custnum)
+ or die "custnum $custnum not found";
-my $quantity = 1;
-if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
- $quantity = $1;
-}
+exists($curuser->agentnums_href->{$cust_main->agentnum})
+ or die "access denied";
-$param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
- or $error .= "Illegal tax override " . $param->{"tax_override"} . " ";
-my $override = $1;
+if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
+ my $pkgnum = $1;
+ die "access denied"
+ unless $curuser->access_right('Modify one-time charge');
-if ( $param->{'taxclass'} eq '(select)' ) {
- $error .= "Must select a tax class. "
- unless ($conf->exists('enable_taxproducts') &&
- ( $override || $param->{taxproductnum} )
- );
- $cgi->param('taxclass', '');
-}
+ my $cust_pkg = FS::cust_pkg->by_key($1)
+ or die "pkgnum $pkgnum not found";
+
+ my $part_pkg = $cust_pkg->part_pkg;
+ die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
+
+ $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),
+ );
+
+} else {
+ # the usual case: new one-time charge
+ $param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+ or $error .= "Illegal amount " . $param->{"amount"} . " ";
+ my $amount = $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->exists('enable_taxproducts') &&
+ ( $override || $param->{taxproductnum} )
+ );
+ $cgi->param('taxclass', '');
+ }
+
+ unless ( $error ) {
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ or $error .= "Unknown customer number $custnum. ";
-unless ( $error ) {
- my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
- or $error .= "Unknown customer number $custnum. ";
-
- $error ||= $cust_main->charge( {
- 'amount' => $amount,
- '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')),
- '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,
- } );
+ $error ||= $cust_main->charge( {
+ 'amount' => $amount,
+ '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')),
+ '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,
+ } );
+ }
}
</%init>