not enough sleep to support multiple internal_prefixen, RT#3985
[freeside.git] / FS / FS / part_pkg / voip_cdr.pm
index bbba7c7..794ae01 100644 (file)
@@ -27,6 +27,11 @@ tie my %rating_method, 'Tie::IxHash',
 #                'Asterisk (or other?) CDR table',
 #;
 
+tie my %temporalities, 'Tie::IxHash',
+  'upcoming'  => "Upcoming (future)",
+  'preceding' => "Preceding (past)",
+;
+
 %info = (
   'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
   'shortname' => 'VoIP/telco CDR rating (standard)',
@@ -37,6 +42,13 @@ tie my %rating_method, 'Tie::IxHash',
     'recur_fee'     => { 'name' => 'Base recurring fee for this package',
                          'default' => 0,
                        },
+
+    #false laziness w/flat.pm
+    'recur_temporality' => { 'name' => 'Charge recurring fee for period',
+                             'type' => 'select',
+                             'select_options' => \%temporalities,
+                           },
+
     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
                                    ' of service at cancellation',
                          'type' => 'checkbox',
@@ -68,7 +80,7 @@ tie my %rating_method, 'Tie::IxHash',
 #                                    'type' => 'checkbox',
 #                                  },
 
-    'international_prefix' => { 'name'    => 'Destination prefix for international CDR records',
+    'international_prefix' => { 'name'    => 'Destination prefix(es) for international CDR records.  Separate multiple options with commas.',
                                 'default' => '011',
                               },
 
@@ -130,7 +142,7 @@ tie my %rating_method, 'Tie::IxHash',
 
   },
   'fieldorder' => [qw(
-                       setup_fee recur_fee unused_credit
+                       setup_fee recur_fee recur_temporality unused_credit
                        rating_method ratenum 
                        default_prefix
                        disable_src
@@ -153,7 +165,11 @@ sub calc_setup {
 sub calc_recur {
   my($self, $cust_pkg, $sdate, $details, $param ) = @_;
 
-  my $last_bill = $cust_pkg->last_bill;
+  #my $last_bill = $cust_pkg->last_bill;
+  my $last_bill = $cust_pkg->get('last_bill'); #->last_bill falls back to setup
+
+  return 0
+    if $self->option('recur_temporality', 1) eq 'preceding' && $last_bill == 0;
 
   my $ratenum = $cust_pkg->part_pkg->option('ratenum');
 
@@ -261,13 +277,23 @@ sub calc_recur {
 #          $dest =~ s/\@(.*)$// and $siphost = $1; # @10.54.32.1, @sip.example.com
 
           my $intl = $self->option('international_prefix') || '011';
+          my @intl = ();
+          if ( $intl =~ /,/ ) {
+            @intl = split(/\s*,\s*/, $intl);
+          } else {
+            @intl = ($intl);
+          }
 
           #determine the country code
+          my $intl_match = 0;
+          foreach my $i (@intl) {
+            if ( $number =~ /^$i(((\d)(\d))(\d))(\d+)$/ ) {
+              $intl_match++;
+              last;
+            }
+          }
           my $countrycode;
-          if (    $number =~ /^$intl(((\d)(\d))(\d))(\d+)$/
-               || $number =~ /^\+(((\d)(\d))(\d))(\d+)$/
-             )
-          {
+          if ( $intl_match || $number =~ /^\+(((\d)(\d))(\d))(\d+)$/ ) {
 
             my( $three, $two, $one, $u1, $u2, $rest ) = ( $1,$2,$3,$4,$5,$6 );
             #first look for 1 digit country code