X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FPackages.pm;h=7090ce7654c281d9381f10acd27d27f4c3e83a21;hb=4171d4440a6bf042f342095f13439a5f9d27487d;hp=ee5bddaca7a81205871a122c4ebed9ca692d1428;hpb=a2ecb1cf6a6c084c521710f1256da082f70ba9e5;p=freeside.git diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index ee5bddaca..7090ce765 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); @@ -602,6 +602,8 @@ this customer that are active (recurring). =cut +#recurring_pkgs? different from cust_pkg idea of "active" which has +# a setup vs not_yet_billed which doesn't sub active_pkgs { my $self = shift; grep { my $part_pkg = $_->part_pkg; @@ -617,6 +619,8 @@ are active (recurring). =cut +#ncancelled_recurring_pkgs? different from cust_pkg idea of "active" which has +# a setup vs not_yet_billed which doesn't sub ncancelled_active_pkgs { my $self = shift; grep { my $part_pkg = $_->part_pkg; @@ -701,6 +705,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 +720,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 +776,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 @@ -825,7 +875,7 @@ sub display_recurring { my $discount = $cust_pkg_discount->discount; #and only one of these for each $pkg_amount -= $discount->amount; - $pkg_amount -= $amount * $discount->percent/100; + $pkg_amount -= $pkg_amount * $discount->percent/100; } $pkg_amount *= ( $cust_pkg->quantity || 1 );