X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=4718d18243d7ed9bc930ff50ba0cb6c67e16575a;hb=d46254f9b36873e457424eefdcf3610b71ef889d;hp=4fe64debb5dc55261a505f450d57178ac53dcc7c;hpb=6816a23d70984027517d33d6eb0ccd49ddd57704;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 4fe64debb..4718d1824 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -671,6 +671,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 ... @@ -1266,7 +1305,8 @@ sub upgrade_tax_location { next INVOICE; } } - my $exempt_cust = 1 if $h_cust_main->tax; + my $exempt_cust; + $exempt_cust = 1 if $h_cust_main->tax; # classify line items my @tax_items;