$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 ...
# It's either the bill or ship address of the customer as of the
# invoice date-of-insertion. (Not necessarily the invoice date.)
my $date = $h_cust_bill->history_date;
+ local($FS::Record::qsearch_qualify_columns) = 0;
my $h_cust_main = qsearchs('h_cust_main',
{ custnum => $custnum },
FS::h_cust_main->sql_h_searchs($date)
} else {
# (pkgparts really shouldn't change, right?)
+ local($FS::Record::qsearch_qualify_columns) = 0;
my $h_cust_pkg = qsearchs('h_cust_pkg', { pkgnum => $pkgnum },
FS::h_cust_pkg->sql_h_searchs($date)
);
}
if (!exists $pkgpart_taxclass{$pkgpart}) {
+ local($FS::Record::qsearch_qualify_columns) = 0;
my $h_part_pkg = qsearchs('h_part_pkg', { pkgpart => $pkgpart },
FS::h_part_pkg->sql_h_searchs($date)
);
# Get any per-customer taxname exemptions that were in effect.
my %exempt_cust_taxname;
foreach (keys %all_tax_names) {
+ local($FS::Record::qsearch_qualify_columns) = 0;
my $h_exemption = qsearchs('h_cust_main_exemption', {
'custnum' => $custnum,
'taxname' => $_,