X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling.pm;h=e94cd84938724988acd82095f29886f521fff951;hp=f6a60805344312d736be6635a6826aba7cd09ed6;hb=077bb34b3467c3320440c49b76064f664c0eee98;hpb=27cfd639aa367ad8d878c71a9516bd913099d528 diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index f6a608053..e94cd8493 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -603,27 +603,52 @@ sub bill { #discard bundled packages of 0 value sub _omit_zero_value_bundles { + my @in = @_; my @cust_bill_pkg = (); my @cust_bill_pkg_bundle = (); my $sum = 0; my $discount_show_always = 0; - foreach my $cust_bill_pkg ( @_ ) { + foreach my $cust_bill_pkg ( @in ) { + $discount_show_always = ($cust_bill_pkg->get('discounts') && scalar(@{$cust_bill_pkg->get('discounts')}) && $conf->exists('discount-show-always')); + + warn " pkgnum ". $cust_bill_pkg->pkgnum. " sum $sum, ". + "setup_show_zero ". $cust_bill_pkg->setup_show_zero. + "recur_show_zero ". $cust_bill_pkg->recur_show_zero. "\n" + if $DEBUG > 0; + if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) { push @cust_bill_pkg, @cust_bill_pkg_bundle - if ($sum > 0 || ($sum == 0 && $discount_show_always)); + if $sum > 0 + || ($sum == 0 && ( $discount_show_always + || grep {$_->recur_show_zero || $_->setup_show_zero} + @cust_bill_pkg_bundle + ) + ); @cust_bill_pkg_bundle = (); $sum = 0; } + $sum += $cust_bill_pkg->setup + $cust_bill_pkg->recur; push @cust_bill_pkg_bundle, $cust_bill_pkg; + } + push @cust_bill_pkg, @cust_bill_pkg_bundle - if ($sum > 0 || ($sum == 0 && $discount_show_always)); + if $sum > 0 + || ($sum == 0 && ( $discount_show_always + || grep {$_->recur_show_zero || $_->setup_show_zero} + @cust_bill_pkg_bundle + ) + ); + + warn " _omit_zero_value_bundles: ". scalar(@in). + '->'. scalar(@cust_bill_pkg). "\n" #. Dumper(@cust_bill_pkg). "\n" + if $DEBUG > 2; (@cust_bill_pkg); @@ -1024,10 +1049,13 @@ sub _make_lines { my $discount_show_always = ($recur == 0 && scalar(@discounts) && $conf->exists('discount-show-always')); - if ( $setup != 0 || - $recur != 0 || - (!$part_pkg->hidden && $options{has_hidden}) || #include some $0 lines - $discount_show_always ) + if ( $setup != 0 + || $recur != 0 + || (!$part_pkg->hidden && $options{has_hidden}) #include some $0 lines + || $discount_show_always + || ($setup == 0 && $cust_pkg->_X_show_zero('setup')) + || ($recur == 0 && $cust_pkg->_X_show_zero('recur')) + ) { warn " charges (setup=$setup, recur=$recur); adding line items\n" @@ -1641,7 +1669,7 @@ sub do_cust_event { if $DEBUG > 1; #if ( my $error = $cust_event->do_event(%options) ) { #XXX %options? - if ( my $error = $cust_event->do_event() ) { + if ( my $error = $cust_event->do_event( 'time' => $time ) ) { #XXX wtf is this? figure out a proper dealio with return value #from do_event return $error; @@ -2125,11 +2153,14 @@ sub apply_payments { my $amount = min( $payment->unapplied, $owed ); - my $cust_bill_pay = new FS::cust_bill_pay ( { + my $cbp = { 'paynum' => $payment->paynum, 'invnum' => $cust_bill->invnum, 'amount' => $amount, - } ); + }; + $cbp->{_date} = $payment->_date + if $options{'manual'} && $options{'backdate_application'}; + my $cust_bill_pay = new FS::cust_bill_pay($cbp); $cust_bill_pay->pkgnum( $payment->pkgnum ) if $conf->exists('pkg-balances') && $payment->pkgnum; my $error = $cust_bill_pay->insert(%options);