X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling.pm;h=eee0958e0632e3322b2ea15df30423a4eeb5af08;hb=61a0dc609fd2b7db3571f8f86672481d1e064331;hp=5c10c639a36fa50c65b3e4a6353267881c341878;hpb=df94942698dac9ecf31b8d1eb7a0d383b247ee17;p=freeside.git diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index 5c10c639a..eee0958e0 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -880,6 +880,7 @@ sub bill { } #discard bundled packages of 0 value +# XXX we should reconsider whether we even need this sub _omit_zero_value_bundles { my @in = @_; @@ -888,11 +889,20 @@ sub _omit_zero_value_bundles { my $discount_show_always = $conf->exists('discount-show-always'); my $show_this = 0; + # Sort @in the same way we do during invoice rendering, so we can identify + # bundles. See FS::Template_Mixin::_items_nontax. + @in = sort { $a->pkgnum <=> $b->pkgnum or + $a->sdate <=> $b->sdate or + ($a->pkgpart_override ? 0 : -1) or + ($b->pkgpart_override ? 0 : 1) or + $b->hidden cmp $a->hidden or + $a->pkgpart_override <=> $b->pkgpart_override + } @in; + # this is a pack-and-deliver pattern. every time there's a cust_bill_pkg # _without_ pkgpart_override, that's the start of the new bundle. if there's # an existing bundle, and it contains a nonzero amount (or a zero amount # that's displayable anyway), push all line items in the bundle. - foreach my $cust_bill_pkg ( @in ) { if (scalar(@bundle) and !$cust_bill_pkg->pkgpart_override) { @@ -1014,8 +1024,14 @@ sub _make_lines { return "$@ running calc_setup for $cust_pkg\n" if $@; - $unitsetup = $cust_pkg->base_setup() - || $setup; #XXX uuh + # Only increment unitsetup here if there IS a setup fee. + # prorate_defer_bill may cause calc_setup on a setup-stage package + # to return zero, and the setup fee to be charged later. (This happens + # when it's first billed on the prorate cutoff day. RT#31276.) + if ( $setup ) { + $unitsetup = $cust_pkg->base_setup() + || $setup; #XXX uuh + } if ( $setup_param{'billed_currency'} ) { $setup_billed_currency = delete $setup_param{'billed_currency'}; @@ -1186,7 +1202,7 @@ sub _make_lines { # Add an additional setup fee at the billing stage. # Used for prorate_defer_bill. $setup += $param{'setup_fee'}; - $unitsetup += $param{'setup_fee'}; + $unitsetup = $cust_pkg->base_setup(); $lineitems++; }