X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling.pm;h=b710f33266308d5b46ce5b1a66327e6e2ab05677;hb=b5c4237a34aef94976bc343c8d9e138664fc3984;hp=c47e630c8e6c43bb4008fe7d5170dbb58d2140a4;hpb=e5fc4f01cca3de11b2f1114efb1ff3c4cf0acc47;p=freeside.git diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index c47e630c8..b710f3326 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -726,8 +726,16 @@ sub calculate_taxes { foreach my $tax ( keys %$taxlisthash ) { foreach ( @{ $taxlisthash->{$tax} }[1 ... scalar(@{ $taxlisthash->{$tax} })] ) { next unless ref($_) eq 'FS::cust_bill_pkg'; - push @{ $packagemap{$_->pkgnum}->_cust_tax_exempt_pkg }, - splice( @{ $_->_cust_tax_exempt_pkg } ); + + my @cust_tax_exempt_pkg = splice( @{ $_->_cust_tax_exempt_pkg } ); + + next unless @cust_tax_exempt_pkg; #just avoiding the prob when irrelevant? + die "can't distribute tax exemptions: no line item for ". Dumper($_). + " in packagemap ". join(',', sort {$a<=>$b} keys %packagemap). "\n" + unless $packagemap{$_->pkgnum}; + + push @{ $packagemap{$_->pkgnum}->_cust_tax_exempt_pkg }, + @cust_tax_exempt_pkg; } } @@ -820,19 +828,21 @@ sub _make_lines { my $setup = 0; my $unitsetup = 0; - if ( $options{'resetup'} - || ( ! $cust_pkg->setup - && ( ! $cust_pkg->start_date - || $cust_pkg->start_date <= $time - ) - && ( ! $conf->exists('disable_setup_suspended_pkgs') - || ( $conf->exists('disable_setup_suspended_pkgs') && - ! $cust_pkg->getfield('susp') - ) - ) - ) - and !$options{recurring_only} - ) + if ( ! $options{recurring_only} + and ! $options{cancel} + and ( $options{'resetup'} + || ( ! $cust_pkg->setup + && ( ! $cust_pkg->start_date + || $cust_pkg->start_date <= $time + ) + && ( ! $conf->exists('disable_setup_suspended_pkgs') + || ( $conf->exists('disable_setup_suspended_pkgs') && + ! $cust_pkg->getfield('susp') + ) + ) + ) + ) + ) { warn " bill setup\n" if $DEBUG > 1; @@ -897,6 +907,7 @@ sub _make_lines { 'discounts' => \@discounts, 'real_pkgpart' => $real_pkgpart, 'freq_override' => $options{freq_override} || '', + 'setup_fee' => 0, ); my $method = $options{cancel} ? 'calc_cancel' : 'calc_recur'; @@ -905,6 +916,11 @@ sub _make_lines { # which can_discount are supported. # (the UI should prevent adding discounts to these at the moment) + warn "calling $method on cust_pkg ". $cust_pkg->pkgnum. + " for pkgpart ". $cust_pkg->pkgpart. + " with params ". join(' / ', map "$_=>$param{$_}", keys %param). "\n" + if $DEBUG > 2; + $recur = eval { $cust_pkg->$method( \$sdate, \@details, \%param ) }; return "$@ running $method for $cust_pkg\n" if ( $@ ); @@ -926,6 +942,14 @@ sub _make_lines { } + if ( $param{'setup_fee'} ) { + # Add an additional setup fee at the billing stage. + # Used for prorate_defer_bill. + $setup += $param{'setup_fee'}; + $unitsetup += $param{'setup_fee'}; + $lineitems++; + } + } warn "\$setup is undefined" unless defined($setup); @@ -995,11 +1019,11 @@ sub _make_lines { 'freq' => $part_pkg->freq, }; - if ( $part_pkg->option('recur_temporality', 1) eq 'preceding' ) { + if ( $part_pkg->recur_temporality eq 'preceding' ) { $cust_bill_pkg->sdate( $hash{last_bill} ); $cust_bill_pkg->edate( $sdate - 86399 ); #60s*60m*24h-1 $cust_bill_pkg->edate( $time ) if $options{cancel}; - } else { #if ( $part_pkg->option('recur_temporality', 1) eq 'upcoming' ) { + } else { #if ( $part_pkg->recur_temporality eq 'upcoming' ) { $cust_bill_pkg->sdate( $sdate ); $cust_bill_pkg->edate( $cust_pkg->bill ); #$cust_bill_pkg->edate( $time ) if $options{cancel};