summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main/Packages.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2016-03-02 15:03:29 -0800
committerIvan Kohler <ivan@freeside.biz>2016-03-02 15:03:29 -0800
commitbfd986f4a210fe26768d77304d3fd50dd3334f45 (patch)
tree1f30dc81275e2892a40631594026ce48a2849bd4 /FS/FS/cust_main/Packages.pm
parenteb2e2acb25912c6bdcc7f94709ca83cabfccf572 (diff)
page large customer package lists, RT#39822
Diffstat (limited to 'FS/FS/cust_main/Packages.pm')
-rw-r--r--FS/FS/cust_main/Packages.pm42
1 files changed, 34 insertions, 8 deletions
diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index ead97f2..6a69517 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -629,29 +629,55 @@ customer.
=cut
sub num_cancelled_pkgs {
- shift->num_pkgs("cust_pkg.cancel IS NOT NULL AND cust_pkg.cancel != 0");
+ my $self = shift;
+ my $opt = shift || {};
+ $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql};
+ $opt->{extra_sql} .= "cust_pkg.cancel IS NOT NULL AND cust_pkg.cancel != 0";
+ $self->num_pkgs($opt);
}
sub num_ncancelled_pkgs {
- shift->num_pkgs("( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )");
+ my $self = shift;
+ my $opt = shift || {};
+ $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql};
+ $opt->{extra_sql} .= "( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )";
+ $self->num_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 ");
+ my $self = shift;
+ my $opt = shift || {};
+ $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql};
+ $opt->{extra_sql} .= " ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+ AND cust_pkg.susp IS NOT NULL AND cust_pkg.susp != 0 ";
+ $self->num_pkgs($opt);
}
sub num_unsuspended_pkgs {
- shift->num_pkgs(" ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
- AND ( cust_pkg.susp IS NULL OR cust_pkg.susp = 0 ) ");
+ my $self = shift;
+ my $opt = shift || {};
+ $opt->{extra_sql} .= ' AND ' if $opt->{extra_sql};
+ $opt->{extra_sql} .= " ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+ AND ( cust_pkg.susp IS NULL OR cust_pkg.susp = 0 )";
+ $self->num_pkgs($opt);
}
sub num_pkgs {
my( $self ) = shift;
- my $sql = scalar(@_) ? shift : '';
+ my $addl_from = '';
+ my $sql = '';
+ if ( @_ ) {
+ if ( ref($_[0]) ) {
+ my $opt = shift;
+ $sql = $opt->{extra_sql} if exists($opt->{extra_sql});
+ $addl_from = $opt->{addl_from} if exists($opt->{addl_from});
+ } else {
+ $sql = shift;
+ }
+ }
$sql = "AND $sql" if $sql && $sql !~ /^\s*$/ && $sql !~ /^\s*AND/i;
my $sth = dbh->prepare(
- "SELECT COUNT(*) FROM cust_pkg WHERE custnum = ? $sql"
+ "SELECT COUNT(*) FROM cust_pkg $addl_from WHERE custnum = ? $sql"
) or die dbh->errstr;
$sth->execute($self->custnum) or die $sth->errstr;
$sth->fetchrow_arrayref->[0];