From 64852c30f3025d1aafa3c9d5c81f6b20dddd1a36 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 18 Sep 2007 06:32:51 +0000 Subject: [PATCH] allow assignment of auto recharge values AND rollover --- FS/FS/cust_pkg.pm | 20 ++++++++++++++++++++ FS/FS/part_pkg/base_rate.pm | 9 --------- FS/FS/part_pkg/flat.pm | 12 ++++++++++-- FS/FS/part_pkg/prorate.pm | 8 +++++--- FS/FS/part_pkg/subscription.pm | 5 +++++ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 77438c124..a37abe239 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1754,6 +1754,26 @@ sub set_usage { } } +=item recharge USAGE_VALUE_HASHREF + +USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts +to which they should be set (see L). Currently seconds, +upbytes, downbytes, and totalbytes are appropriate keys. + +All svc_accts which are part of this package have their values incremented. + +=cut + +sub recharge { + my ($self, $valueref) = @_; + + foreach my $cust_svc ($self->cust_svc){ + my $svc_x = $cust_svc->svc_x; + $svc_x->recharge($valueref) + if $svc_x->can("recharge"); + } +} + =back =head1 BUGS diff --git a/FS/FS/part_pkg/base_rate.pm b/FS/FS/part_pkg/base_rate.pm index 9e64184ab..04896e0fd 100644 --- a/FS/FS/part_pkg/base_rate.pm +++ b/FS/FS/part_pkg/base_rate.pm @@ -43,7 +43,6 @@ sub calc_setup { sub calc_recur { my($self, $cust_pkg) = @_; - $self->reset_usage($cust_pkg); $self->base_recur($cust_pkg); } @@ -91,12 +90,4 @@ sub is_prepaid { 0; #no, we're postpaid } -sub reset_usage { - my($self, $cust_pkg) = @_; - my %values = map { $_, $self->option($_) } - grep { $self->option($_, 'hush') } - qw(seconds upbytes downbytes totalbytes); - $cust_pkg->set_usage(\%values); -} - 1; diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 6d1fbde4d..471f216ba 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -63,12 +63,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, ); @@ -141,7 +145,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 02ce6b9a7..6b7c61532 100644 --- a/FS/FS/part_pkg/prorate.pm +++ b/FS/FS/part_pkg/prorate.pm @@ -61,6 +61,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' => '', @@ -70,7 +74,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, ); @@ -83,8 +87,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 00d15cd0c..7f4dbcab9 100644 --- a/FS/FS/part_pkg/subscription.pm +++ b/FS/FS/part_pkg/subscription.pm @@ -57,6 +57,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' => '', @@ -71,6 +75,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, -- 2.11.0