X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FPackages.pm;h=8f96f81aa146527e1a94fcfa4c1d121b80e8c9fb;hb=f6a37fa1d6a30484ce8a268de170ecc8d5c31a23;hp=343112da1a18188890447af5c732592989cc09f8;hpb=7b5d2054b431a0fedf269bb98909a3c4cf8e1ba2;p=freeside.git diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index 343112da1..8f96f81aa 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -684,6 +684,28 @@ sub num_pkgs { $sth->fetchrow_arrayref->[0]; } +=item num_usage_pkgs + +Returns the number of packages for this customer that have services that +can have RADIUS usage statistics. + +=cut + +sub num_usage_pkgs { + my $self = shift; + # have to enumerate exportnums but it's not bad + my @exportnums = map { $_->exportnum } + grep { $_->can('usage_sessions') } + qsearch('part_export'); + return 0 if !@exportnums; + my $in_exportnums = join(',', @exportnums); + my $sql = "SELECT COUNT(DISTINCT pkgnum) FROM cust_pkg + JOIN cust_svc USING (pkgnum) + JOIN export_svc USING (svcpart) + WHERE exportnum IN( $in_exportnums ) AND custnum = ?"; + FS::Record->scalar_sql($sql, $self->custnum); +} + =back =head1 BUGS