summaryrefslogtreecommitdiff
path: root/FS/FS/part_pkg.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-10-27 12:19:32 -0700
committerMark Wells <mark@freeside.biz>2016-10-27 12:19:49 -0700
commit40f3374957a5b709df2a54a69f7c9883d4b9ca38 (patch)
tree68c542dfb9f5d64a74ade33f1267a8ce731422a0 /FS/FS/part_pkg.pm
parent840c45f3ae5661130f9a6068ae5c9e03c47c9f39 (diff)
add calc_units to plans other than voip_cdr, #39639
Diffstat (limited to 'FS/FS/part_pkg.pm')
-rw-r--r--FS/FS/part_pkg.pm20
1 files changed, 17 insertions, 3 deletions
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 008ba8a..35f178e 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'; }