X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fflat.pm;h=97d4363da910c5b16bf81943db2946ea98c166c9;hp=8844991cd396fd12fb662d6cfae3ee0010117ce0;hb=44dcd4a1ff335a85a6babf0e007be57e6ec4f525;hpb=f5674f02fc85ffe3cb8b5ff8b2ca1ffd1af70d00 diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 8844991cd..97d4363da 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -5,7 +5,10 @@ use base qw( FS::part_pkg::prorate_Mixin ); use strict; -use vars qw( %info %usage_recharge_fields @usage_recharge_fieldorder ); +use vars qw( $conf $money_char %info + %usage_recharge_fields @usage_recharge_fieldorder + ); +use FS::UID; use FS::Record qw( qsearch ); use FS::cust_credit_source_bill_pkg; use Tie::IxHash; @@ -13,6 +16,12 @@ use List::Util qw( min ); use FS::UI::bytecount; use FS::Conf; +#ask FS::UID to run this stuff for us later +FS::UID->install_callback( sub { + $conf = new FS::Conf; + $money_char = $conf->config('money_char') || '$'; +}); + tie my %temporalities, 'Tie::IxHash', 'upcoming' => "Upcoming (future)", 'preceding' => "Preceding (past)", @@ -49,8 +58,9 @@ tie my %contract_years, 'Tie::IxHash', ( }, 'prorate_round_day' => { 'name' => 'When synchronizing, round the prorated '. - 'period to the nearest full day', - 'type' => 'checkbox', + 'period', + 'type' => 'select', + 'select_options' => \%FS::part_pkg::prorate_Mixin::prorate_round_day_opts, }, 'add_full_period' => { 'disabled' => 1 }, # doesn't make sense with sync? @@ -86,20 +96,20 @@ tie my %contract_years, 'Tie::IxHash', ( ); sub price_info { - my $self = shift; - my %opt = @_; - my $conf = new FS::Conf; - my $money_char = $conf->config('money_char') || '$'; - my $setup = $opt{cust_pkg} ? $self->base_setup( $opt{cust_pkg} ) - : ($self->option('setup_fee') || 0); - my $recur = $opt{cust_pkg} ? $self->base_recur( $opt{cust_pkg} ) - : ($self->option('recur_fee', 1) || 0); - $recur += $self->usageprice_recur( $opt{cust_pkg} ) if $opt{cust_pkg}; - my $str = ''; - $str = $money_char . $setup . ($recur ? ' setup' : ' one-time') if $setup; - $str .= ', ' if ($setup && $recur); - $str .= $money_char. $recur. '/'. $self->freq_pretty if $recur; - $str; + my $self = shift; + my %opt = @_; + + my $setup = $opt{cust_pkg} ? $self->base_setup( $opt{cust_pkg} ) + : ($self->option('setup_fee') || 0); + my $recur = $opt{cust_pkg} ? $self->base_recur( $opt{cust_pkg} ) + : ($self->option('recur_fee', 1) || 0); + $recur += $self->usageprice_recur( $opt{cust_pkg} ) if $opt{cust_pkg}; + + my $str = ''; + $str = $money_char . $setup . ($recur ? ' setup' : ' one-time') if $setup; + $str .= ', ' if ($setup && $recur); + $str .= $money_char. $recur. '/'. $self->freq_pretty if $recur; + $str; } sub calc_setup { @@ -127,11 +137,7 @@ sub calc_setup { sub base_setup { my($self, $cust_pkg, $sdate, $details ) = @_; - ( exists( $self->{'Hash'}{'_opt_setup_fee'} ) - ? $self->{'Hash'}{'_opt_setup_fee'} - : $self->option('setup_fee', 1) - ) - || 0; + $self->option('setup_fee', 1) || 0; } sub calc_recur { @@ -169,7 +175,7 @@ sub cutoff_day { my $cust_pkg = shift; if ( $self->option('sync_bill_date',1) ) { my $next_bill = $cust_pkg->cust_main->next_bill_date; - if ( defined($next_bill) ) { + if ( $next_bill ) { # careful here. if the prorate calculation is going to round to # the nearest day, this needs to always return the same result if ( $self->option('prorate_round_day', 1) ) { @@ -184,11 +190,7 @@ sub cutoff_day { sub base_recur { my($self, $cust_pkg, $sdate) = @_; - ( exists( $self->{'Hash'}{'_opt_recur_fee'} ) - ? $self->{'Hash'}{'_opt_recur_fee'} - : $self->option('recur_fee', 1) - ) - || 0; + $self->option('recur_fee', 1) || 0; } sub base_recur_permonth { @@ -210,7 +212,6 @@ sub usageprice_recur { sub calc_cancel { my $self = shift; - my $conf = new FS::Conf; if ( $self->recur_temporality eq 'preceding' and $self->option('bill_recur_on_cancel', 1) ) { # run another recurring cycle @@ -224,6 +225,8 @@ sub calc_cancel { } } +# no longer used; see credit_remaining in FS::cust_pkg + sub calc_remain { my ($self, $cust_pkg, %options) = @_;