From: Mark Wells Date: Thu, 27 Oct 2016 19:19:32 +0000 (-0700) Subject: add calc_units to plans other than voip_cdr, #39639 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d82acd06f8f8a431c69c3b14e3c5cb8252edb02d add calc_units to plans other than voip_cdr, #39639 --- diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 008ba8a86..35f178e25 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -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'; } diff --git a/FS/FS/part_pkg/global_Mixin.pm b/FS/FS/part_pkg/global_Mixin.pm index e82602e1a..59eaaaaec 100644 --- a/FS/FS/part_pkg/global_Mixin.pm +++ b/FS/FS/part_pkg/global_Mixin.pm @@ -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 diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 420026dcb..9ecdba685 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -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 ''; diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm index e911439c8..15af706c1 100644 --- a/FS/FS/part_pkg/voip_inbound.pm +++ b/FS/FS/part_pkg/voip_inbound.pm @@ -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;