add calc_units to plans other than voip_cdr, #39639
authorMark Wells <mark@freeside.biz>
Thu, 27 Oct 2016 19:19:32 +0000 (12:19 -0700)
committerMark Wells <mark@freeside.biz>
Thu, 27 Oct 2016 19:19:32 +0000 (12:19 -0700)
FS/FS/part_pkg.pm
FS/FS/part_pkg/global_Mixin.pm
FS/FS/part_pkg/voip_cdr.pm
FS/FS/part_pkg/voip_inbound.pm

index 008ba8a..35f178e 100644 (file)
@@ -1917,13 +1917,27 @@ sub calc_remain { 0; }
 =item calc_units CUST_PKG
 
 This returns the number of provisioned svc_phone records, or, of the package
-count_available_phones option is set, the number available to be provisoined
+count_available_phones option is set, the number available to be provisioned
 in the package.
 
 =cut
 
-#fallback that returns 0 for old legacy packages with no plan
-sub calc_units  { 0; }
+sub calc_units {
+  my($self, $cust_pkg ) = @_;
+  my $count = 0;
+  if ( $self->option('count_available_phones', 1)) {
+    foreach my $pkg_svc ($cust_pkg->part_pkg->pkg_svc) {
+      if ($pkg_svc->part_svc->svcdb eq 'svc_phone') { # svc_pbx?
+        $count += $pkg_svc->quantity || 0;
+      }
+    }
+    $count *= $cust_pkg->quantity;
+  } else {
+    $count =
+      scalar(grep { $_->part_svc->svcdb eq 'svc_phone' } $cust_pkg->cust_svc);
+  }
+  $count;
+}
 
 #fallback for everything not based on flat.pm
 sub recur_temporality { 'upcoming'; }
index e82602e..59eaaaa 100644 (file)
@@ -30,6 +30,10 @@ sub validate_moneyn {
   return '';
 }
 
+tie my %count_available_phones, 'Tie::IxHash', (
+  0 => 'Provisioned phone services',
+  1 => 'All available phone services',
+);
 
 %info = (
   'disabled' => 1,
@@ -63,6 +67,11 @@ sub validate_moneyn {
       'name' => 'Automatic suspension period before cancelling (configuration setting part_pkg-delay_cancel-days)',
       'type' => 'checkbox',
     },
+    'count_available_phones' => { 'name' => 'Count taxable phone lines',
+      'type' => 'radio',
+      'options' => \%count_available_phones,
+      'default' => 0,
+    },
 
     # miscellany--maybe put this in a separate module?
 
@@ -134,6 +143,8 @@ sub validate_moneyn {
     unused_credit_change
     delay_cancel
 
+    count_available_phones
+
     a2billing_tariff
     a2billing_type
     a2billing_simultaccess
index 420026d..9ecdba6 100644 (file)
@@ -289,10 +289,6 @@ tie my %accountcode_tollfree_field, 'Tie::IxHash',
                                'type' => 'checkbox',
                              },
 
-    'count_available_phones' => { 'name' => 'Consider for tax purposes the number of lines to be svc_phones that may be provisioned rather than those that actually are.',
-                           'type' => 'checkbox',
-                         },
-
     #XXX also have option for an external db?  these days we suck them into ours
 #    'cdr_location' => { 'name' => 'CDR database location'
 #                        'type' => 'select',
@@ -353,7 +349,7 @@ tie my %accountcode_tollfree_field, 'Tie::IxHash',
                        usage_mandate usage_section summarize_usage 
                        usage_showzero bill_every_call bill_inactive_svcs
                        bill_only_pkg_dates
-                       count_available_phones suspend_bill 
+                       suspend_bill 
                      )
                   ],
   'weight' => 41,
@@ -656,25 +652,6 @@ sub is_free {
   0;
 }
 
-#  This equates svc_phone records; perhaps svc_phone should have a field
-#  to indicate it represents a line
-sub calc_units {    
-  my($self, $cust_pkg ) = @_;
-  my $count = 0;
-  if ( $self->option('count_available_phones', 1)) {
-    foreach my $pkg_svc ($cust_pkg->part_pkg->pkg_svc) {
-      if ($pkg_svc->part_svc->svcdb eq 'svc_phone') { # svc_pbx?
-        $count += $pkg_svc->quantity || 0;
-      }
-    }
-    $count *= $cust_pkg->quantity;
-  } else {
-    $count = 
-      scalar(grep { $_->part_svc->svcdb eq 'svc_phone' } $cust_pkg->cust_svc);
-  }
-  $count;
-}
-
 sub reset_usage {
   my ($self, $cust_pkg, %opt) = @_;
   my @part_pkg_usage = $self->part_pkg_usage or return '';
index e911439..15af706 100644 (file)
@@ -399,15 +399,5 @@ sub is_free {
   0;
 }
 
-#  This equates svc_phone records; perhaps svc_phone should have a field
-#  to indicate it represents a line
-#  #XXX no count_available_phones?
-sub calc_units {    
-  my($self, $cust_pkg ) = @_;
-  my $count = 
-      scalar(grep { $_->part_svc->svcdb eq 'svc_phone' } $cust_pkg->cust_svc);
-  $count;
-}
-
 1;