X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fflat.pm;h=8844991cd396fd12fb662d6cfae3ee0010117ce0;hb=f5674f02fc85ffe3cb8b5ff8b2ca1ffd1af70d00;hp=eb70253bb312fc124ff3c4938152d43d27725f19;hpb=5b193ee2c5fae0743699adb1a28591f2a1735eb7;p=freeside.git diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index eb70253bb..8844991cd 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -34,16 +34,6 @@ tie my %contract_years, 'Tie::IxHash', ( 'select_options' => \%temporalities, }, - #used in cust_pkg.pm so could add to any price plan - 'expire_months' => { 'name' => 'Auto-add an expiration date this number of months out', - }, - 'adjourn_months'=> { 'name' => 'Auto-add a suspension date this number of months out', - }, - 'contract_end_months'=> { - 'name' => 'Auto-add a contract end date this number of years out', - 'type' => 'select', - 'select_options' => \%contract_years, - }, #used in cust_pkg.pm so could add to any price plan where it made sense 'start_1st' => { 'name' => 'Auto-add a start date to the 1st, ignoring the current month.', 'type' => 'checkbox', @@ -85,8 +75,6 @@ tie my %contract_years, 'Tie::IxHash', ( }, }, 'fieldorder' => [ qw( recur_temporality - expire_months adjourn_months - contract_end_months start_1st sync_bill_date prorate_defer_bill prorate_round_day suspend_bill unsuspend_adjust_bill @@ -139,8 +127,11 @@ sub calc_setup { sub base_setup { my($self, $cust_pkg, $sdate, $details ) = @_; - - $self->option('setup_fee') || 0; + ( exists( $self->{'Hash'}{'_opt_setup_fee'} ) + ? $self->{'Hash'}{'_opt_setup_fee'} + : $self->option('setup_fee', 1) + ) + || 0; } sub calc_recur { @@ -193,7 +184,11 @@ sub cutoff_day { sub base_recur { my($self, $cust_pkg, $sdate) = @_; - $self->option('recur_fee', 1) || 0; + ( exists( $self->{'Hash'}{'_opt_recur_fee'} ) + ? $self->{'Hash'}{'_opt_recur_fee'} + : $self->option('recur_fee', 1) + ) + || 0; } sub base_recur_permonth { @@ -252,7 +247,6 @@ sub calc_remain { foreach my $cust_bill_pkg ( qsearch('cust_bill_pkg', { pkgnum => $cust_pkg->pkgnum, - sdate => {op => '<' , value => $time}, edate => {op => '>=', value => $time}, recur => {op => '>' , value => 0}, }) @@ -264,8 +258,17 @@ sub calc_remain { $edate = $self->add_freq($cust_bill_pkg->sdate); } - my $amount = ($cust_bill_pkg->recur - $cust_bill_pkg->usage) * - ($edate - $time) / ($edate - $cust_bill_pkg->sdate); + # this will also get any package charges that are _entirely_ after the + # cancellation date (can happen with advance billing). in that case, + # use the entire recurring charge: + my $amount = $cust_bill_pkg->recur - $cust_bill_pkg->usage; + + # but if the cancellation happens during the interval, prorate it: + # (XXX obey prorate_round_day here?) + if ( $cust_bill_pkg->sdate < $time ) { + $amount = $amount * ($edate - $time) / ($edate - $cust_bill_pkg->sdate); + } + $credit += $amount; push @{ $options{'cust_credit_source_bill_pkg'} },