summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-10-16 15:32:32 -0700
committerMark Wells <mark@freeside.biz>2015-10-16 15:47:47 -0700
commitf641486e28214ad1eca18c47d2252701b83614f1 (patch)
treebc52ae1fedb9e088d5690940480bddd0ea5c8b6c /httemplate
parentb6f16a22bd93ec66ffbb1da30e63f7e950b3b819 (diff)
separate setup and recur discounts, #14092
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/edit/cust_pkg_discount.html66
-rw-r--r--httemplate/edit/process/cust_pkg_discount.html96
-rw-r--r--httemplate/edit/process/quick-cust_pkg.cgi29
-rw-r--r--httemplate/elements/select-months.html11
-rw-r--r--httemplate/elements/tr-select-months.html16
-rw-r--r--httemplate/elements/tr-select-pkg-discount.html196
-rw-r--r--httemplate/misc/order_pkg.html17
-rw-r--r--httemplate/search/cust_bill_pkg_discount.html11
-rw-r--r--httemplate/search/cust_pkg_discount.html9
-rwxr-xr-xhttemplate/view/cust_main/packages.html1
-rw-r--r--httemplate/view/cust_main/packages/package.html31
-rw-r--r--httemplate/view/cust_main/packages/status.html31
12 files changed, 399 insertions, 115 deletions
diff --git a/httemplate/edit/cust_pkg_discount.html b/httemplate/edit/cust_pkg_discount.html
index 0bb84b8f2..e1e3daede 100755
--- a/httemplate/edit/cust_pkg_discount.html
+++ b/httemplate/edit/cust_pkg_discount.html
@@ -1,18 +1,5 @@
-<% include('/elements/header-popup.html', "Discount Package") %>
-
-<SCRIPT TYPE="text/javascript">
-
- function enable_discount_pkg () {
- if ( document.DiscountPkgForm.discountnum.selectedIndex > 0 ) {
- document.DiscountPkgForm.submit.disabled = false;
- } else {
- document.DiscountPkgForm.submit.disabled = true;
- }
- }
-
-</SCRIPT>
-
-<% include('/elements/error.html') %>
+<& /elements/header-popup.html, "Discount Package" &>
+<& /elements/error.html &>
<FORM NAME="DiscountPkgForm" ACTION="<% $p %>edit/process/cust_pkg_discount.html" METHOD=POST>
<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
@@ -26,17 +13,17 @@
</TD>
</TR>
-<% include('/elements/tr-select-discount.html',
- 'empty_label' => ( $pkgdiscountnum ? '' : 'Select discount' ),
- 'onchange' => 'enable_discount_pkg()',
- 'cgi' => $cgi,
- )
-%>
-
+<& /elements/tr-select-pkg-discount.html,
+ curr_value_setup => $setup_discountnum,
+ curr_value_recur => $recur_discountnum,
+ disable_setup => $disable_setup,
+ disable_recur => $disable_recur,
+&>
+
</TABLE>
<BR>
-<INPUT NAME="submit" TYPE="submit" VALUE="Discount package" <% $pkgdiscountnum ? '' : 'DISABLED' %>>
+<INPUT NAME="submit" TYPE="submit" VALUE="Discount package">
</FORM>
</BODY>
@@ -44,14 +31,13 @@
<%init>
-#some false laziness w/misc/change_pkg.cgi
-
my $conf = new FS::Conf;
my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
- unless $curuser->access_right('Discount customer package');
+ unless $curuser->access_right([ 'Discount customer package',
+ 'Waive setup fee']);
my $pkgnum = scalar($cgi->param('pkgnum'));
$pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum";
@@ -67,10 +53,30 @@ my $cust_pkg =
'extra_sql' => ' AND '. $curuser->agentnums_sql,
}) or die "unknown pkgnum $pkgnum";
-#my $cust_main = $cust_pkg->cust_main
-# or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
-# " ( pkgnum ". cust_pkg->pkgnum. ")";
-
my $part_pkg = $cust_pkg->part_pkg;
+my @discounts = $cust_pkg->cust_pkg_discount_active;
+my ($setup_discountnum, $recur_discountnum);
+foreach (@discounts) {
+ if ( $_->setuprecur eq 'setup') {
+ die "multiple setup discounts on pkg#$pkgnum" if $setup_discountnum;
+ $setup_discountnum = $_->discountnum;
+ } elsif ( $_->setuprecur eq 'recur' ) {
+ die "multiple setup discounts on pkg#$pkgnum" if $recur_discountnum;
+ $recur_discountnum = $_->discountnum;
+ }
+}
+if ( $cust_pkg->waive_setup ) {
+ $setup_discountnum = -2;
+}
+
+my $disable_setup = 1;
+if ( !$cust_pkg->get('setup') and $cust_pkg->base_setup > 0 ) {
+ $disable_setup = 0;
+}
+my $disable_recur = 1;
+if ( $cust_pkg->base_recur > 0 ) {
+ $disable_recur = 0;
+}
+
</%init>
diff --git a/httemplate/edit/process/cust_pkg_discount.html b/httemplate/edit/process/cust_pkg_discount.html
index 4a71f6975..143611ef9 100644
--- a/httemplate/edit/process/cust_pkg_discount.html
+++ b/httemplate/edit/process/cust_pkg_discount.html
@@ -14,9 +14,8 @@
<%init>
my $curuser = $FS::CurrentUser::CurrentUser;
-
-die "access denied"
- unless $curuser->access_right('Discount customer package');
+my $can_discount = $curuser->access_right('Discount customer package');
+my $can_waive_setup = $curuser->access_right('Waive setup fee');
#this search is really for security wrt agent virt...
#maybe move it to the cust_pkg_discount->insert call?
@@ -29,20 +28,81 @@ my $cust_pkg = qsearchs({
});
die 'unknown pkgnum' unless $cust_pkg;
-my $cust_pkg_discount = new FS::cust_pkg_discount {
- 'pkgnum' => $cust_pkg->pkgnum,
- 'discountnum' => scalar($cgi->param('discountnum')),
- 'months_used' => 0,
- 'end_date' => '', #XXX
- #for the create a new discount case
- '_type' => scalar($cgi->param('discountnum__type')),
- 'amount' => scalar($cgi->param('discountnum_amount')),
- 'percent' => scalar($cgi->param('discountnum_percent')),
- 'months' => scalar($cgi->param('discountnum_months')),
- 'setup' => scalar($cgi->param('discountnum_setup')),
- #'linked' => scalar($cgi->param('discountnum_linked')),
- #'disabled' => $self->discountnum_disabled,
-};
-my $error = $cust_pkg_discount->insert;
+my $error;
+my %discountnum = (setup => '', recur => '');
+if ( $cgi->param('setup_discountnum') == -2 ) {
+
+ die "access denied" unless $can_waive_setup; # UI protects against this
+ # waive setup fee (not really a discount but treated as one in the UI)
+ if ( !$cust_pkg->get('setup') and !$cust_pkg->waive_setup ) {
+ $cust_pkg->set('waive_setup' => 'Y');
+ $error = $cust_pkg->replace;
+ }
+
+} else {
+ if ( $cgi->param('setup_discountnum') =~ /^(-?\d+)$/ ) {
+ $discountnum{setup} = $1;
+ }
+ if ( $cust_pkg->waive_setup ) {
+ $cust_pkg->set('waive_setup', '');
+ $error = $cust_pkg->replace;
+ }
+}
+
+if ( $cgi->param('recur_discountnum') =~ /^(-?\d+)$/ ) {
+
+ $discountnum{recur} = $1;
+
+}
+
+my @active_discounts = $cust_pkg->cust_pkg_discount_active;
+
+foreach my $setuprecur (qw(setup recur)) {
+
+ if ( $cust_pkg->get('setup') and $setuprecur eq 'setup' ) {
+ # no point allowing setup discounts to be edited for a previously setup
+ # package
+ next;
+ }
+
+ my ($active) = grep { $_->setuprecur eq $setuprecur } @active_discounts;
+
+ if ( $active ) {
+ if ( $active->discount ne $discountnum{$setuprecur} ) {
+ $active->set('disabled' => 'Y');
+ $error ||= $active->replace;
+ undef $active;
+ } else {
+ # it's the same discountnum; don't touch it
+ next;
+ }
+ }
+
+ if ( $discountnum{$setuprecur} ) {
+ die "access_denied" unless $can_discount;
+ my $cust_pkg_discount = FS::cust_pkg_discount->new({
+ 'pkgnum' => $cust_pkg->pkgnum,
+ 'discountnum' => $discountnum{$setuprecur},
+ 'setuprecur' => $setuprecur,
+ 'months_used' => 0,
+ 'end_date' => '', #XXX
+ #for the create a new discount case
+ '_type' => scalar($cgi->param($setuprecur.'_discountnum__type')),
+ 'amount' => scalar($cgi->param($setuprecur.'_discountnum_amount')),
+ 'percent' => scalar($cgi->param($setuprecur.'_discountnum_percent')),
+ });
+ if ( $setuprecur eq 'setup' ) {
+ $cust_pkg_discount->set('setup' => 'Y');
+ $cust_pkg_discount->set('months' => 1);
+ } else {
+ if ( $cgi->param($setuprecur.'_discountnum_months') =~ /^(\w+)$/ ) {
+ $cust_pkg_discount->set('months' => $1);
+ }
+ }
+
+ $error ||= $cust_pkg_discount->insert;
+
+ }
+} # foreach $setuprecur
</%init>
diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi
index f1d8c2696..60352154a 100644
--- a/httemplate/edit/process/quick-cust_pkg.cgi
+++ b/httemplate/edit/process/quick-cust_pkg.cgi
@@ -79,9 +79,6 @@ my $contactnum = $1;
$cgi->param('locationnum') =~ /^(\-?\d*)$/
or die 'illegal locationnum '. $cgi->param('locationnum');
my $locationnum = $1;
-$cgi->param('discountnum') =~ /^(\-?\d*)$/
- or die 'illegal discountnum '. $cgi->param('discountnum');
-my $discountnum = $1;
# for going right to a provision service after ordering a package
my( $svcpart, $part_svc ) = ( '', '' );
@@ -114,19 +111,29 @@ my %hash = (
'refnum' => $refnum,
'contactnum' => $contactnum,
'locationnum' => $locationnum,
- 'discountnum' => $discountnum,
- #for the create a new discount case
- 'discountnum__type' => scalar($cgi->param('discountnum__type')),
- 'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
- 'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
- 'discountnum_months' => scalar($cgi->param('discountnum_months')),
- 'discountnum_setup' => scalar($cgi->param('discountnum_setup')),
'contract_end' => ( scalar($cgi->param('contract_end'))
? parse_datetime($cgi->param('contract_end'))
: ''
),
- 'waive_setup' => ( $cgi->param('waive_setup') eq 'Y' ? 'Y' : '' ),
);
+
+if ( $cgi->param('setup_discountnum') =~ /^(-?\d+)$/ ) {
+ if ( $1 == -2 ) {
+ $hash{waive_setup} = 'Y';
+ } else {
+ $hash{setup_discountnum} = $1;
+ $hash{setup_discountnum_amount} = $cgi->param('setup_discountnum_amount');
+ $hash{setup_discountnum_percent} = $cgi->param('setup_discountnum_percent');
+ }
+}
+
+if ( $cgi->param('recur_discountnum') =~ /^(-?\d+)$/ ) {
+ $hash{recur_discountnum} = $1;
+ $hash{recur_discountnum_amount} = $cgi->param('recur_discountnum_amount');
+ $hash{recur_discountnum_percent} = $cgi->param('recur_discountnum_percent');
+ $hash{recur_discountnum_months} = $cgi->param('recur_discountnum_months');
+}
+
$hash{'custnum'} = $cust_main->custnum if $cust_main;
if ( $cgi->param('start') eq 'on_hold' ) {
diff --git a/httemplate/elements/select-months.html b/httemplate/elements/select-months.html
new file mode 100644
index 000000000..1cd72fcba
--- /dev/null
+++ b/httemplate/elements/select-months.html
@@ -0,0 +1,11 @@
+<%init>
+my %opt = @_;
+$opt{id} ||= $opt{field}; # should be the default everywhere
+my $max = $opt{max} || 36;
+$opt{options} = [ '', 1 .. $max ];
+$opt{labels} = { '' => '',
+ map { $_ => emt('[quant,_1,month]', $_) } 1 .. $max
+ };
+
+</%init>
+<& select.html, %opt &>
diff --git a/httemplate/elements/tr-select-months.html b/httemplate/elements/tr-select-months.html
index b90ce1ed7..4d8576411 100644
--- a/httemplate/elements/tr-select-months.html
+++ b/httemplate/elements/tr-select-months.html
@@ -1,11 +1,5 @@
-<%init>
-my %opt = @_;
-$opt{id} ||= $opt{field}; # should be the default everywhere
-my $max = $opt{max} || 36;
-$opt{options} = [ '', 1 .. $max ];
-$opt{labels} = { '' => '',
- map { $_ => emt('[quant,_1,month]', $_) } 1 .. $max
- };
-
-</%init>
-<& tr-select.html, %opt &>
+<& tr-td-label.html, @_ &>
+ <td>
+ <& select-months.html, @_ &>
+ </td>
+</tr>
diff --git a/httemplate/elements/tr-select-pkg-discount.html b/httemplate/elements/tr-select-pkg-discount.html
new file mode 100644
index 000000000..dc38cff3e
--- /dev/null
+++ b/httemplate/elements/tr-select-pkg-discount.html
@@ -0,0 +1,196 @@
+<%doc>
+
+In order_pkg.html or similar:
+
+<& /elements/tr-select-pkg-discount.html,
+ curr_value_setup => ($cgi->param('setup_discountnum') || ''),
+ curr_value_recur => ($cgi->param('recur_discountnum') || ''),
+ disable_setup => 0,
+ disable_recur => 0,
+&>
+
+This provides the following:
+- If the user can waive setup fees or apply a discount, they get a
+ select box for the setup discount, with "Waive setup fee" as an option.
+- If they can custom discount, they will also get "Custom discount" as an
+ option. If selected, this will show fields to enter the custom discount
+ amount/percentage.
+- If they can waive setup fees but NOT apply a discount, they only get a
+ checkbox to waive setup fee.
+- Same for recurring fee, but without the "waive setup fee" stuff, obviously.
+- Custom recurring discounts also have an option for a duration in months.
+
+"disable_setup" locks the setup discount, but will still show a static
+description if curr_value_setup is set. Likewise "disable_recur".
+
+</%doc>
+% # SETUP DISCOUNT
+
+% # select-discount knows about the "custom discount" ACL
+% if ( $curuser->access_right('Discount customer package')
+% and !$opt{disable_setup} )
+% {
+% my $pre_options = [ '' => '(none)' ];
+% if ( $curuser->access_right('Waive setup fee') ) {
+% push @$pre_options, -2 => 'Waive setup fee';
+% }
+<& tr-td-label.html, label => emt('Setup fee') &>
+ <td>
+ <& select-discount.html,
+ field => 'setup_discountnum',
+ id => 'setup_discountnum',
+ hashref => { disabled => '',
+ setup => 'Y'
+ },
+ extra_sql => ' AND (percent > 0 OR months = 1)',
+ curr_value => $opt{'curr_value_setup'},
+ disable_empty => 1,
+ pre_options => $pre_options,
+ &>
+ </td>
+</tr>
+% # custom discount
+<tr class="setup_discount_custom">
+ <td></td>
+ <td>Amount <% $money_char %>
+ <& input-text.html,
+ field => 'setup_discountnum_amount',
+ curr_value => ($cgi->param('setup_discountnum_amount') || ''),
+ size => 5,
+ &>
+ or percentage
+ <& input-text.html,
+ field => 'setup_discountnum_percent',
+ curr_value => ($cgi->param('setup_discountnum_percent') || ''),
+ size => 5,
+ &> %
+ </td>
+</tr>
+
+% } elsif ( $curuser->access_right('Waive setup fee')
+% and !$opt{disable_setup} )
+% {
+
+<& tr-td-label.html, label => emt('Waive setup fee') &>
+ <td>
+ <& checkbox.html,
+ field => 'setup_discountnum',
+ id => 'setup_discountnum',
+ value => '-2',
+ curr_value => $opt{'curr_value_setup'},
+ &>
+ </td>
+</tr>
+
+% } elsif ( $opt{'curr_value_setup'} ) { # user can't do anything
+%
+% my $discount = FS::discount->by_key($opt{'curr_value_setup'});
+
+ <INPUT TYPE="hidden" NAME="setup_discountnum" VALUE="<% $opt{curr_value_setup} %>">
+
+ <% $discount->description_short %>
+
+% }
+
+% # RECUR DISCOUNT
+
+% if ( $curuser->access_right('Discount customer package')
+% and !$opt{disable_recur} ) {
+
+<& tr-td-label.html, label => emt('Recurring fee') &>
+ <td>
+ <& select-discount.html,
+ field => 'recur_discountnum',
+ id => 'recur_discountnum',
+ hashref => { disabled => '' },
+ curr_value => $opt{'curr_value_recur'},
+ &>
+
+ </td>
+</tr>
+% # custom discount
+<tr class="recur_discount_custom">
+ <td></td>
+ <td>Amount <% $money_char %>
+ <& input-text.html,
+ field => 'recur_discountnum_amount',
+ curr_value => ($cgi->param('recur_discountnum_amount') || ''),
+ size => 5,
+ &>
+ or percentage
+ <& input-text.html,
+ field => 'recur_discountnum_percent',
+ curr_value => ($cgi->param('recur_discountnum_percent') || ''),
+ size => 5,
+ &> %
+ </td>
+</tr>
+<tr class="recur_discount_custom">
+ <td></td>
+ <td>Expires after
+ <& /elements/select-months.html,
+ field => 'recur_discountnum_months',
+ curr_value => ($cgi->param('recur_discountnum_months') || ''),
+ &>
+ </td>
+</tr>
+
+% } elsif ( $opt{'curr_value_recur'} ) {
+%
+% my $discount = FS::discount->by_key($opt{'curr_value_recur'});
+
+ <INPUT TYPE="hidden" NAME="recur_discountnum" VALUE="<% $opt{curr_value_recur} %>">
+
+ <% $discount->description %>
+
+% }
+
+<SCRIPT TYPE="text/javascript">
+$(document).ready(function() {
+ ['setup', 'recur'].forEach(function(x) {
+ var discountnum = $('#'+x+'_discountnum');
+
+ // if it's been set to a custom discount, show custom discount inputs
+ var discountnum_changed = function() {
+ var val = this.value;
+ var custom = $('.'+x+'_discount_custom');
+ if ( val == -1 ) {
+ custom.show();
+ } else {
+ custom.hide();
+ }
+ };
+
+ discountnum.on('change', discountnum_changed);
+ discountnum.trigger('change');
+
+ // if amount contains a value, disable percent, and vice versa
+ var amount_percent_keyup = function(event) {
+ var other = event.data;
+ if (this.value.length > 0) {
+ other.disabled = true;
+ } else {
+ other.disabled = false;
+ }
+ };
+ var amount = $('#'+x+'_discountnum_amount');
+ var percent = $('#'+x+'_discountnum_percent');
+ amount.on('keyup', percent, amount_percent_keyup);
+ percent.on('keyup', amount, amount_percent_keyup);
+
+ amount.trigger('keyup');
+ percent.trigger('keyup');
+ });
+});
+</script>
+<%init>
+
+my %opt = (
+ 'curr_value_setup' => ($cgi->param('setup_discountnum') || ''),
+ 'curr_value_recur' => ($cgi->param('recur_discountnum') || ''),
+ @_
+);
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $money_char = FS::Conf->new->config('money_char') || '$';
+
+</%init>
diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html
index cb2bd4832..e28250110 100644
--- a/httemplate/misc/order_pkg.html
+++ b/httemplate/misc/order_pkg.html
@@ -127,22 +127,7 @@
% if ( $discount_cust_pkg || $waive_setup_fee ) {
<FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
<% ntable("#cccccc") %>
-
-% if ( $waive_setup_fee ) {
- <TR>
- <TH ALIGN="right"><% mt('Waive setup fee') |h %> </TH>
- <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="waive_setup" VALUE="Y"></TD>
- </TR>
-% }
-
-% if ( $discount_cust_pkg ) {
- <& /elements/tr-select-discount.html,
- 'element_etc' => 'DISABLED',
- 'colspan' => 7,
- 'cgi' => $cgi,
- &>
-% }
-
+ <& /elements/tr-select-pkg-discount.html &>
</TABLE><BR>
% }
diff --git a/httemplate/search/cust_bill_pkg_discount.html b/httemplate/search/cust_bill_pkg_discount.html
index 6da5787a0..c63482827 100644
--- a/httemplate/search/cust_bill_pkg_discount.html
+++ b/httemplate/search/cust_bill_pkg_discount.html
@@ -20,9 +20,7 @@
sub { $_[0]->cust_pkg_discount->discount->description },
sub { $_[0]->cust_pkg_discount->discount->classname },
sub { sprintf($money_char.'%.2f', shift->amount ) },
- sub { my $m = shift->months;
- $m =~ /\./ ? sprintf('%.2f', $m) : $m;
- },
+ $months_sub,
'pkg',#sub { $_[0]->cust_bill_pkg->cust_pkg->part_pkg->pkg },
'invnum',
sub { time2str('%b %d %Y', shift->_date ) },
@@ -218,4 +216,11 @@ my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
+my $months_sub = sub {
+ my $cust_bill_pkg_discount = shift;
+ return 'Setup'
+ if $cust_bill_pkg_discount->cust_pkg_discount->setuprecur eq 'setup';
+ sprintf('%.2f', $cust_bill_pkg_discount->months);
+};
+
</%init>
diff --git a/httemplate/search/cust_pkg_discount.html b/httemplate/search/cust_pkg_discount.html
index f0c7447a5..ab6ad2bd0 100644
--- a/httemplate/search/cust_pkg_discount.html
+++ b/httemplate/search/cust_pkg_discount.html
@@ -18,9 +18,7 @@
sub { ucfirst( shift->status ) },
sub { shift->discount->description },
sub { shift->discount->classname },
- sub { my $m = shift->months_used;
- $m =~ /\./ ? sprintf('%.2f',$m) : $m;
- },
+ $months_used_sub,
'otaker',
'pkg',
\&FS::UI::Web::cust_fields,
@@ -165,4 +163,9 @@ my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
my $conf = new FS::Conf;
+my $months_used_sub = sub {
+ my $cust_pkg_discount = shift;
+ return 'Setup only' if $cust_pkg_discount->setuprecur eq 'setup';
+ return sprintf('%.2f', $cust_pkg_discount->months_used);
+};
</%init>
diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html
index 4903e185b..0c67843d4 100755
--- a/httemplate/view/cust_main/packages.html
+++ b/httemplate/view/cust_main/packages.html
@@ -42,6 +42,7 @@ table.hiddenrows {
z-index: 1;
text-align: center;
}
+
</STYLE>
% # activate rolldown buttons for hidden package blocks
<SCRIPT TYPE="text/javascript">
diff --git a/httemplate/view/cust_main/packages/package.html b/httemplate/view/cust_main/packages/package.html
index 8aa64039c..e98b95e1c 100644
--- a/httemplate/view/cust_main/packages/package.html
+++ b/httemplate/view/cust_main/packages/package.html
@@ -53,10 +53,7 @@
(&nbsp;<%onetime_change_link($cust_pkg)%>&nbsp;)
% }
% # also, you can discount it
-% if ( $curuser->access_right('Discount customer package')
-% && ! scalar($cust_pkg->cust_pkg_discount_active)
-% && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
-% ) {
+% if ( $can_discount_pkg ) {
(&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
% }
<BR>
@@ -79,14 +76,7 @@
(&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
% }
%
-% if ( $curuser->access_right('Discount customer package')
-% && $part_pkg->can_discount
-% && ! scalar( @{ $cust_pkg->{_cust_pkg_discount_active} } )
-% && ( ! $opt{'term_discounts'}
-% || ! scalar($cust_pkg->part_pkg->part_pkg_discount)
-% )
-% )
-% {
+% if ( $can_discount_pkg ) {
% $br=1;
(&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
% }
@@ -437,4 +427,21 @@ sub pkg_event_link {
'</a>';
}
+# figure out if this user will be able to edit either the setup or recurring
+# discounts for this package
+my $can_discount_pkg = (
+ $part_pkg->can_discount
+ and
+ ( ( $curuser->access_right(['Discount customer package', 'Waive setup fee'])
+ and $cust_pkg->base_setup > 0
+ and !$cust_pkg->setup
+ )
+ or
+ ( $curuser->access_right('Discount customer package')
+ and $cust_pkg->base_recur > 0
+ and $cust_pkg->freq ne '0'
+ )
+ )
+);
+
</%init>
diff --git a/httemplate/view/cust_main/packages/status.html b/httemplate/view/cust_main/packages/status.html
index 7e125f72e..13bd2024b 100644
--- a/httemplate/view/cust_main/packages/status.html
+++ b/httemplate/view/cust_main/packages/status.html
@@ -461,10 +461,11 @@ sub pkg_status_row_changed {
my $part_pkg = $old->part_pkg;
$html .= pkg_status_row_colspan(
$cust_pkg,
- emt("Changed from [_1]: [_2]",
- $cust_pkg->change_pkgnum,
- $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
- ),
+# emt("Changed from [_1]: [_2]",
+# $cust_pkg->change_pkgnum,
+# $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
+# ),
+ '',
'',
'size' => '-1',
'align' => 'right',
@@ -529,17 +530,25 @@ sub pkg_status_row_discount {
my $discount = $cust_pkg_discount->discount;
- my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
- if ( $discount->months ) {
+ my $label = '<SPAN STYLE="font-size: small"><B>';
+ if ( $cust_pkg_discount->setuprecur eq 'setup' ) {
+ $label .= emt('Setup Discount');
+ } else {
+ $label .= emt('Recurring Discount');
+ }
+ $label .= '</B>: '. $discount->description;
+ warn Dumper $cust_pkg_discount;
+ if ( $discount->months > 0 and $cust_pkg_discount->months_used > 0 ) {
my $remaining = $discount->months - $cust_pkg_discount->months_used;
$remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
- $label .= emt("([_1] months remaining)",$remaining);
+ $label .= <br> . emt("([_1] months remaining)",$remaining);
}
+ $label .= '</SPAN>';
- $label .= ' <FONT SIZE="-1">('.
- '<A HREF="../misc/delete-cust_pkg_discount.html?'.
- $cust_pkg_discount->pkgdiscountnum.
- '">'.emt('remove discount').'</A>)</FONT>';
+ #$label .= ' <FONT SIZE="-1">('.
+ # '<A HREF="../misc/delete-cust_pkg_discount.html?'.
+ # $cust_pkg_discount->pkgdiscountnum.
+ # '">'.emt('remove discount').'</A>)</FONT>';
$html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );