X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FPackages.pm;h=fec9fd348e9b0fc7152a949c70faf529f1d98c1b;hb=9f3d40d71b076c664b38c1cfa4b60c12d42c473a;hp=4d0eee7ed7821863ca24735b907314580e6f30de;hpb=f61619b95f05b576518ea698ad7e22267b4c36c4;p=freeside.git diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm index 4d0eee7ed..fec9fd348 100644 --- a/FS/FS/cust_main/Packages.pm +++ b/FS/FS/cust_main/Packages.pm @@ -149,7 +149,7 @@ sub order_pkg { } $cust_pkg->locationnum($opt->{'cust_location'}->locationnum); - } else { + } elsif ( ! $cust_pkg->locationnum ) { $cust_pkg->locationnum($self->ship_locationnum); @@ -593,6 +593,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; @@ -608,6 +610,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; @@ -659,10 +663,34 @@ sub num_cancelled_pkgs { shift->num_pkgs("cust_pkg.cancel IS NOT NULL AND cust_pkg.cancel != 0"); } +=item num_ncancelled_pkgs + +Returns the number of packages that have not been cancelled (see L) for this +customer. + +=cut + sub num_ncancelled_pkgs { shift->num_pkgs("( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )"); } +=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 { shift->num_pkgs(" ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 ) AND cust_pkg.susp IS NOT NULL AND cust_pkg.susp != 0 "); @@ -783,7 +811,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 );