[freeside-commits] freeside/FS/FS/part_pkg voip_cdr.pm,1.65,1.66

Jeff Finucane,420,, jeff at wavetail.420.am
Thu Apr 23 13:34:15 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv12931/FS/FS/part_pkg

Modified Files:
	voip_cdr.pm 
Log Message:
add subscription option to voip_cdr

Index: voip_cdr.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/voip_cdr.pm,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- voip_cdr.pm	7 Apr 2009 01:20:38 -0000	1.65
+++ voip_cdr.pm	23 Apr 2009 20:34:13 -0000	1.66
@@ -4,6 +4,7 @@
 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 @@
   '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 @@
                          '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 @@
   },
   '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 @@
   } #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;
 }



More information about the freeside-commits mailing list