diff options
author | jeff <jeff> | 2007-12-21 21:38:11 +0000 |
---|---|---|
committer | jeff <jeff> | 2007-12-21 21:38:11 +0000 |
commit | 9acabac91f26630353303271d1b953e9f8744ea2 (patch) | |
tree | 47fbc088096c11798065120bb9bf411a26ef5184 | |
parent | 9d1cd91904cf82b10fed9a89e68bf5a824870dd5 (diff) |
backport flat, prorate, and subscription plans
-rw-r--r-- | FS/FS/cust_main.pm | 7 | ||||
-rw-r--r-- | FS/FS/part_pkg/flat.pm | 26 | ||||
-rw-r--r-- | FS/FS/part_pkg/prorate.pm | 8 | ||||
-rw-r--r-- | FS/FS/part_pkg/subscription.pm | 7 |
4 files changed, 37 insertions, 11 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 3dbe8b3e0..031f47733 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1983,6 +1983,13 @@ sub bill { ( $cust_pkg->getfield('bill') || 0 ) <= $time ) { + # XXX should this be a package event? probably. events are called + # at collection time at the moment, though... + if ( $part_pkg->can('reset_usage') ) { + warn " resetting usage counters" if $DEBUG > 1; + $part_pkg->reset_usage($cust_pkg); + } + warn " bill recur\n" if $DEBUG > 1; # XXX shared with $recur_prog diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 7f795bd35..f5ccd0119 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -72,12 +72,16 @@ use FS::part_pkg; 'format' => \&FS::UI::bytecount::display_bytecount, 'parse' => \&FS::UI::bytecount::parse_bytecount, }, + 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '. + ' over into current period', + 'type' => 'checkbox', + }, }, 'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 'seconds', 'upbytes', 'downbytes', 'totalbytes', 'recharge_amount', 'recharge_seconds', 'recharge_upbytes', 'recharge_downbytes', 'recharge_totalbytes', - 'externalid' ], + 'usage_rollover', 'externalid' ], 'weight' => 10, ); @@ -95,18 +99,24 @@ sub calc_setup { sub calc_recur { my($self, $cust_pkg) = @_; - $self->reset_usage($cust_pkg); $self->base_recur($cust_pkg); } sub base_recur { my($self, $cust_pkg) = @_; - $self->option('recur_fee'); + $self->option('recur_fee', 1) || 0; } sub calc_remain { - my ($self, $cust_pkg) = @_; - my $time = time; #should be able to pass this in for credit calculation + my ($self, $cust_pkg, %options) = @_; + + my $time; + if ($options{'time'}) { + $time = $options{'time'}; + } else { + $time = time; + } + my $next_bill = $cust_pkg->getfield('bill') || 0; my $last_bill = $cust_pkg->last_bill || 0; return 0 if ! $self->base_recur @@ -144,7 +154,11 @@ sub reset_usage { my %values = map { $_, $self->option($_) } grep { $self->option($_, 'hush') } qw(seconds upbytes downbytes totalbytes); - $cust_pkg->set_usage(\%values); + if ($self->option('usage_rollover', 1)) { + $cust_pkg->recharge(\%values); + }else{ + $cust_pkg->set_usage(\%values); + } } 1; diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm index 9ad0c89c4..3dfab37ba 100644 --- a/FS/FS/part_pkg/prorate.pm +++ b/FS/FS/part_pkg/prorate.pm @@ -70,6 +70,10 @@ use FS::part_pkg::flat; 'format' => \&FS::UI::bytecount::display_bytecount, 'parse' => \&FS::UI::bytecount::parse_bytecount, }, + 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '. + 'over into current period', + 'type' => 'checkbox', + }, #it would be better if this had to be turned on, its confusing 'externalid' => { 'name' => 'Optional External ID', 'default' => '', @@ -79,7 +83,7 @@ use FS::part_pkg::flat; 'seconds', 'upbyte', 'downbytes', 'totalbytes', 'recharge_amount', 'recharge_seconds', 'recharge_upbytes', 'recharge_downbytes', 'recharge_totalbytes', - 'externalid', ], + 'usage_rollover', 'externalid', ], 'freq' => 'm', 'weight' => 20, ); @@ -92,8 +96,6 @@ sub calc_recur { my $mend; my $mstart; - $self->reset_usage($cust_pkg); - if ( $mday >= $cutoff_day ) { $mend = timelocal(0,0,0,$cutoff_day, $mon == 11 ? 0 : $mon+1, $year+($mon==11)); diff --git a/FS/FS/part_pkg/subscription.pm b/FS/FS/part_pkg/subscription.pm index 6fe74a8fe..3e5a41669 100644 --- a/FS/FS/part_pkg/subscription.pm +++ b/FS/FS/part_pkg/subscription.pm @@ -66,6 +66,10 @@ use FS::part_pkg::flat; 'format' => \&FS::UI::bytecount::display_bytecount, 'parse' => \&FS::UI::bytecount::parse_bytecount, }, + 'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '. + 'over into current period', + 'type' => 'checkbox', + }, #it would be better if this had to be turned on, its confusing 'externalid' => { 'name' => 'Optional External ID', 'default' => '', @@ -80,6 +84,7 @@ use FS::part_pkg::flat; 'upbytes', 'downbytes', 'totalbytes', 'recharge_amount', 'recharge_seconds', 'recharge_upbytes', 'recharge_downbytes', 'recharge_totalbytes', + 'usage_rollover', ], 'freq' => 'm', 'weight' => 30, @@ -98,8 +103,6 @@ sub calc_recur { $$sdate = timelocal(0,0,0,$cutoff_day,$mon,$year); - $self->reset_usage($cust_pkg); - $self->option('recur_fee'); } |