X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=352ed6a12a05e640054a886e09a5693daadb8216;hb=f6abf4cd6d8e7a0121124e9394b5f28f5bc4daa5;hp=56a666e8260e2c85a571e881d6171817c63b7254;hpb=844cadb72e5e37ba0c78ffc8b6f2eded669b2226;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 56a666e82..352ed6a12 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 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 ...