summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2016-03-02 15:03:27 -0800
committerIvan Kohler <ivan@freeside.biz>2016-03-02 15:03:27 -0800
commit4b2b65e322f09922513d6d23fc50bfe3b69af36d (patch)
treeabaed1349fe6e68a35a3ff9b1bccb7d0f0ee74ca /FS
parent8b70832328eb02dc9253dab7b436c6479b588162 (diff)
page large customer package lists, RT#39822
Diffstat (limited to 'FS')
-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 ead97f2c3..6a69517d5 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];