summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill_pkg.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-08-16 13:10:41 -0700
committerMark Wells <mark@freeside.biz>2016-08-16 13:10:56 -0700
commitf10cc704ae52f6d1982e50a4b9a00385a40fa19f (patch)
treefdc9cfe8a6fee9c2b660fb25bbd44ea763714f9e /FS/FS/cust_bill_pkg.pm
parent8d37b300115b2fc8cdc427ae4919f2c612914b48 (diff)
optionally show introductory rates as discounts, #72097
Diffstat (limited to 'FS/FS/cust_bill_pkg.pm')
-rw-r--r--FS/FS/cust_bill_pkg.pm73
1 files changed, 46 insertions, 27 deletions
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index df67f3d..a1762e4 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -832,34 +832,53 @@ sub _item_discount {
my $self = shift;
my %options = @_;
+ my $d; # this will be returned.
+
my @pkg_discounts = $self->pkg_discount;
- return if @pkg_discounts == 0;
- # special case: if there are old "discount details" on this line item, don't
- # show discount line items
- if ( FS::cust_bill_pkg_detail->count("detail LIKE 'Includes discount%' AND billpkgnum = ?", $self->billpkgnum || 0) > 0 ) {
- return;
- }
-
- my @ext;
- my $d = {
- _is_discount => 1,
- description => $self->mt('Discount'),
- setup_amount => 0,
- recur_amount => 0,
- ext_description => \@ext,
- pkgpart => $self->pkgpart,
- feepart => $self->feepart,
- # maybe should show quantity/unit discount?
- };
- foreach my $pkg_discount (@pkg_discounts) {
- push @ext, $pkg_discount->description;
- my $setuprecur = $pkg_discount->cust_pkg_discount->setuprecur;
- $d->{$setuprecur.'_amount'} -= $pkg_discount->amount;
- }
- $d->{setup_amount} *= $self->quantity || 1; # ??
- $d->{recur_amount} *= $self->quantity || 1; # ??
-
- return $d;
+ if (@pkg_discounts) {
+ # special case: if there are old "discount details" on this line item,
+ # don't show discount line items
+ if ( FS::cust_bill_pkg_detail->count("detail LIKE 'Includes discount%' AND billpkgnum = ?", $self->billpkgnum || 0) > 0 ) {
+ return;
+ }
+
+ my @ext;
+ $d = {
+ _is_discount => 1,
+ description => $self->mt('Discount'),
+ setup_amount => 0,
+ recur_amount => 0,
+ ext_description => \@ext,
+ pkgpart => $self->pkgpart,
+ feepart => $self->feepart,
+ # maybe should show quantity/unit discount?
+ };
+ foreach my $pkg_discount (@pkg_discounts) {
+ push @ext, $pkg_discount->description;
+ my $setuprecur = $pkg_discount->cust_pkg_discount->setuprecur;
+ $d->{$setuprecur.'_amount'} -= $pkg_discount->amount;
+ }
+ }
+
+ # show introductory rate as a pseudo-discount
+ if (!$d) { # this will conflict with showing real discounts
+ my $part_pkg = $self->part_pkg;
+ if ( $part_pkg and $part_pkg->option('show_as_discount') ) {
+ my $cust_pkg = $self->cust_pkg;
+ my $intro_end = $part_pkg->intro_end($cust_pkg);
+ my $_date = $self->cust_bill->_date;
+ if ( $intro_end > $_date ) {
+ $d = $part_pkg->item_discount($cust_pkg);
+ }
+ }
+ }
+
+ if ( $d ) {
+ $d->{setup_amount} *= $self->quantity || 1; # ??
+ $d->{recur_amount} *= $self->quantity || 1; # ??
+ }
+
+ $d;
}
=item set_display OPTION => VALUE ...