summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-12-12 19:20:24 -0800
committerIvan Kohler <ivan@freeside.biz>2014-12-12 19:20:24 -0800
commit52bea6aecfcc8274fd852f626a0f751e1b5bd6a8 (patch)
treeada11b424b4963c843538ebac8d47855a98f19a8 /httemplate
parentda0d59f239e7116893cf3249792e7c572bc8bf84 (diff)
costs for one-time charges, RT#31429
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/edit/process/quick-charge.cgi28
-rw-r--r--httemplate/edit/quick-charge.html60
2 files changed, 62 insertions, 26 deletions
diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi
index 07797d0c4..e87be6272 100644
--- a/httemplate/edit/process/quick-charge.cgi
+++ b/httemplate/edit/process/quick-charge.cgi
@@ -36,7 +36,7 @@ exists($curuser->agentnums_href->{$cust_main->agentnum})
my $message;
-if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
+if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
$message = "One-time charge changed";
my $pkgnum = $1;
die "access denied"
@@ -48,18 +48,20 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
my $part_pkg = $cust_pkg->part_pkg;
die "pkgnum $pkgnum is not a one-time charge" unless $part_pkg->freq eq '0';
- my ($amount, $quantity, $start_date);
+ my ($amount, $setup_cost, $quantity);
if ( $cgi->param('amount') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
$amount = sprintf('%.2f', $1);
}
+ if ( $cgi->param('setup_cost') =~ /^\s*(\d*(\.\d{1,2})*)\s*$/ ) {
+ $setup_cost = sprintf('%.2f', $1);
+ }
if ( $cgi->param('quantity') =~ /^\s*(\d*)\s*$/ ) {
$quantity = $1 || 1;
}
- if ( $cgi->param('start_date') ) {
- $start_date = parse_datetime($cgi->param('start_date'));
- } else {
- $start_date = time;
- }
+
+ my $start_date = $cgi->param('start_date')
+ ? parse_datetime($cgi->param('start_date'))
+ : time;
$error = $cust_pkg->modify_charge(
'pkg' => scalar($cgi->param('pkg')),
@@ -67,17 +69,24 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
'additional' => \@description,
'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
'amount' => $amount,
+ 'setup_cost' => $setup_cost,
'quantity' => $quantity,
'start_date' => $start_date,
);
-} else {
+} else { # the usual case: new one-time charge
+
$message = "One-time charge added";
- # 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 $setup_cost = '';
+ $param->{"setup_cost"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+ or $error .= "Illegal setup_cost " . $param->{"setup_cost"} . " ";
+ my $setup_cost = $1;
+
my $quantity = 1;
if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
$quantity = $1;
@@ -101,6 +110,7 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) {
$error ||= $cust_main->charge( {
'amount' => $amount,
+ 'setup_cost' => $setup_cost,
'quantity' => $quantity,
'bill_now' => scalar($cgi->param('bill_now')),
'invoice_terms' => scalar($cgi->param('invoice_terms')),
diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html
index 06669fa0e..eca6c78e5 100644
--- a/httemplate/edit/quick-charge.html
+++ b/httemplate/edit/quick-charge.html
@@ -111,13 +111,23 @@ function bill_now_changed (what) {
% # don't allow changing these after the fact
% $field = '/elements/tr-fixed.html' if $billed;
<& $field,
- label => 'Amount',
- field => 'amount',
- value => sprintf('%.2f',$part_pkg->option('setup_fee')),
- size => 8,
- prefix => $money_char,
+ label => mt('Amount to charge'),
+ field => 'amount',
+ value => sprintf('%.2f',$part_pkg->option('setup_fee')),
+ size => 8,
+ prefix => $money_char,
&>
+% if ( $curuser->access_right('Edit package definition costs') ) {
+ <& $field,
+ label => mt('Cost'),
+ field => 'setup_cost',
+ value => sprintf('%.2f',$part_pkg->setup_cost),
+ size => 8,
+ prefix => $money_char,
+ &>
+% }
+
% if ( $conf->exists('invoice-unitprice') ) {
<& $field,
label => 'Quantity',
@@ -158,20 +168,31 @@ function bill_now_changed (what) {
}
&>
% }
+
% } else { # new one-time charge
-<TR>
- <TD ALIGN="right"><% mt('Amount') |h %> </TD>
- <TD>
- <% $money_char %><INPUT TYPE = "text"
- NAME = "amount"
- SIZE = 6
- VALUE = "<% $amount %>"
- onChange = "return enable_quick_charge(event)"
- onKeyPress = "return enable_quick_charge(event)"
- >
- </TD>
-</TR>
+ <TR>
+ <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
+ <TD>
+ <% $money_char %><INPUT TYPE = "text"
+ NAME = "amount"
+ SIZE = 8
+ VALUE = "<% $amount %>"
+ onChange = "return enable_quick_charge(event)"
+ onKeyPress = "return enable_quick_charge(event)"
+ >
+ </TD>
+ </TR>
+
+% if ( $curuser->access_right('Edit package definition costs') ) {
+ <& /elements/tr-input-text.html,
+ label => mt('Cost'),
+ field => 'setup_cost',
+ value => $setup_cost,
+ size => 8,
+ prefix => $money_char,
+ &>
+% }
% if ( $conf->exists('invoice-unitprice') ) {
<TR>
@@ -417,6 +438,11 @@ if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
$amount = $1;
}
+my $setup_cost = '';
+if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
+ $setup_cost = $1;
+}
+
my $quantity = 1;
if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
$quantity = $1;