X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FPackages.pm;h=3f4792e1a7afe8da70633af6ef6d6c1c1769d5e0;hp=ee5bddaca7a81205871a122c4ebed9ca692d1428;hb=cee98c61a9317a0ce86fd7e625235c302cc0f056;hpb=a2ecb1cf6a6c084c521710f1256da082f70ba9e5 diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index ee5bddaca..3f4792e1a 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -155,7 +155,7 @@ sub order_pkg { } $cust_pkg->locationnum($opt->{'cust_location'}->locationnum); - } else { + } elsif ( ! $cust_pkg->locationnum ) { $cust_pkg->locationnum($self->ship_locationnum); @@ -701,6 +701,13 @@ sub num_cancelled_pkgs { $self->num_pkgs($opt); } +=item num_ncancelled_pkgs + +Returns the number of packages that have not been cancelled (see L) for this +customer. + +=cut + sub num_ncancelled_pkgs { my $self = shift; my $opt = shift || {}; @@ -709,6 +716,23 @@ sub num_ncancelled_pkgs { $self->num_pkgs($opt); } +=item num_billing_pkgs + +Returns the number of packages that have not been cancelled +and have a non-zero billing frequency (see L) +for this customer. + +=cut + +sub num_billing_pkgs { + my $self = shift; + my $opt = shift || {}; + $opt->{addl_from} .= ' LEFT JOIN part_pkg USING (pkgpart)'; + $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql}; + $opt->{extra_sql} .= "freq IS NOT NULL AND freq != '0'"; + $self->num_ncancelled_pkgs($opt); +} + sub num_suspended_pkgs { my $self = shift; my $opt = shift || {}; @@ -748,6 +772,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); +} + =item display_recurring Returns an array of hash references, one for each recurring freq