From 2f7258c405692391d07ae96efef2e471a71849f9 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 23 Apr 2009 20:34:13 +0000 Subject: [PATCH] add subscription option to voip_cdr --- FS/FS/Upgrade.pm | 3 +++ FS/FS/part_pkg/voip_cdr.pm | 50 ++++++++++++++++++++++++++++++++++++---------- FS/FS/part_pkg_option.pm | 7 ++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 7cf4051aa..7aecf45d8 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -132,6 +132,9 @@ sub upgrade_data { #change tax_rate column types 'tax_rate' => [], + #change recur_flat and enable_prorate + 'part_pkg_option' => [], + ; \%hash; diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index e25bba5b4..d89a68440 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -4,6 +4,7 @@ use strict; use vars qw(@ISA $DEBUG %info); use Date::Format; use Tie::IxHash; +use Time::Local; use FS::Conf; use FS::Record qw(qsearchs qsearch); use FS::part_pkg::flat; @@ -22,6 +23,12 @@ tie my %rating_method, 'Tie::IxHash', 'upstream_simple' => 'Simply pass through and charge the "upstream_price" amount.', ; +tie my %recur_method, 'Tie::IxHash', + 'anniversary' => 'Charge the recurring fee at the frequency specified above', + 'prorate' => 'Charge a prorated fee the first time (selectable billing date)', + 'subscription' => 'Charge the full fee for the first partial period (selectable billing date)', +; + #tie my %cdr_location, 'Tie::IxHash', # 'internal' => 'Internal: CDR records imported into the internal CDR table', # 'external' => 'External: CDR records queried directly from an external '. @@ -55,14 +62,18 @@ tie my %temporalities, 'Tie::IxHash', 'type' => 'checkbox', }, - 'enable_prorate' => { 'name' => 'Enable prorating of the first month', - 'type' => 'checkbox', - }, - - 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating ', + 'cutoff_day' => { 'name' => 'Billing Day (1 - 28) for prorating or '. + 'subscription', 'default' => '1', }, + 'recur_method' => { 'name' => 'Recurring fee method', + #'type' => 'radio', + #'options' => \%recur_method, + 'type' => 'select', + 'select_options' => \%recur_method, + }, + 'rating_method' => { 'name' => 'Region rating method', 'type' => 'radio', 'options' => \%rating_method, @@ -187,7 +198,7 @@ tie my %temporalities, 'Tie::IxHash', }, 'fieldorder' => [qw( setup_fee recur_fee recur_temporality unused_credit - enable_prorate cutoff_day + recur_method cutoff_day rating_method ratenum ignore_unrateable default_prefix disable_src @@ -558,12 +569,31 @@ sub calc_recur { } #if ( $spool_cdr && length($downstream_cdr) ) if ($param->{'increment_next_bill'}) { - if ( $self->option('enable_prorate', 1) ) { + my $recur_method = $self->option('recur_method', 1) || 'anniversary'; + + if ( $recur_method eq 'prorate' ) { + $charges += $self->SUPER::calc_recur(@_); + } else { - $charges += $self->option('recur_fee') - } - } + + $charges += $self->option('recur_fee'); + + if ( $recur_method eq 'subscription' ) { + + my $cutoff_day = $self->option('cutoff_day', 1) || 1; + my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ]; + + if ( $day < $cutoff_day ) { + if ( $mon == 0 ) { $mon=11; $year--; } + else { $mon--; } + } + + $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year); + + }#$recur_method eq 'subscription' + }#$recur_method eq 'prorate' + }#increment_next_bill $charges; } diff --git a/FS/FS/part_pkg_option.pm b/FS/FS/part_pkg_option.pm index 9708f11bc..3cb330b1f 100644 --- a/FS/FS/part_pkg_option.pm +++ b/FS/FS/part_pkg_option.pm @@ -127,11 +127,16 @@ sub check { sub _upgrade_data { # class method my ($class, %opts) = @_; - my $sql = "UPDATE part_pkg_option SETUP optionname = 'recur_fee'". + my $sql = "UPDATE part_pkg_option SET optionname = 'recur_fee'". " WHERE optionname = 'recur_flat'"; my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; + $sql = "UPDATE part_pkg_option SET optionname = 'recur_method',". + "optionvalue = 'prorate' WHERE optionname = 'enable_prorate'"; + $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + ''; } -- 2.11.0