summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill_pkg.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-01-31 14:44:16 -0800
committerMark Wells <mark@freeside.biz>2015-01-31 14:44:22 -0800
commitf6abf4cd6d8e7a0121124e9394b5f28f5bc4daa5 (patch)
treedb6264c4c2c38a423310d82d4443580607ecc82d /FS/FS/cust_bill_pkg.pm
parent3d796bf211374d941bda1116ee27a0543045ea8a (diff)
discounts + quotations, #33099
Diffstat (limited to 'FS/FS/cust_bill_pkg.pm')
-rw-r--r--FS/FS/cust_bill_pkg.pm39
1 files changed, 39 insertions, 0 deletions
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index 56a666e..352ed6a 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -668,6 +668,45 @@ sub units {
$self->pkgnum ? $self->part_pkg->calc_units($self->cust_pkg) : 0; # 1?
}
+=item _item_discount
+
+If this item has any discounts, returns a hashref in the format used
+by L<FS::Template_Mixin/_items_cust_bill_pkg> to describe the discount(s)
+on an invoice. This will contain the keys 'description', 'amount',
+'ext_description' (an arrayref of text lines describing the discounts),
+and '_is_discount' (a flag).
+
+The value for 'amount' will be negative, and will be scaled for the package
+quantity.
+
+=cut
+
+sub _item_discount {
+ my $self = shift;
+ 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'),
+ amount => 0,
+ ext_description => \@ext,
+ # maybe should show quantity/unit discount?
+ };
+ foreach my $pkg_discount (@pkg_discounts) {
+ push @ext, $pkg_discount->description;
+ $d->{amount} -= $pkg_discount->amount;
+ }
+ $d->{amount} *= $self->quantity || 1;
+
+ return $d;
+}
=item set_display OPTION => VALUE ...