diff options
author | Mark Wells <mark@freeside.biz> | 2014-04-17 10:06:43 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-04-17 10:06:43 -0700 |
commit | cd6489220a4cebb8c76a07c470fddd544c78999b (patch) | |
tree | 4a36b393dc336aca2f54158de291c5daf3a87c4f /FS | |
parent | d63803bbc79722f255b40f3fb4a060a241a43230 (diff) |
customer signup report, filter by customer and package class, #28025
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Report/Table.pm | 24 | ||||
-rw-r--r-- | FS/FS/cust_main/Search.pm | 12 |
2 files changed, 29 insertions, 7 deletions
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm index 17b12ae23..8c45ae145 100644 --- a/FS/FS/Report/Table.pm +++ b/FS/FS/Report/Table.pm @@ -32,9 +32,14 @@ options in %opt. =over 4 -=item signups: The number of customers signed up. Options are "refnum" -(limit by advertising source) and "indirect" (boolean, tells us to limit -to customers that have a referral_custnum that matches the advertising source). +=item signups: The number of customers signed up. Options are: + +- cust_classnum: limit to this customer class +- pkg_classnum: limit to customers with a package of this class. If this is + an arrayref, it's an ANY match. +- refnum: limit to this advertising source +- indirect: boolean; limit to customers that have a referral_custnum that + matches the advertising source =cut @@ -57,6 +62,19 @@ sub signups { } push @where, $self->with_cust_classnum(%opt); + if ( $opt{'pkg_classnum'} ) { + my $classnum = $opt{'pkg_classnum'}; + $classnum = [ $classnum ] unless ref $classnum; + @$classnum = grep /^\d+$/, @$classnum; + if (@$classnum) { + my $in = 'IN ('. join(',', @$classnum). ')'; + push @where, + "EXISTS(SELECT 1 FROM cust_pkg JOIN part_pkg USING (pkgpart) ". + "WHERE cust_pkg.custnum = cust_main.custnum ". + "AND part_pkg.classnum $in". + ")"; + } + } $self->scalar_sql( "SELECT COUNT(*) FROM cust_main $join WHERE ".join(' AND ', @where) diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index b52b3596a..140e63f87 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -950,6 +950,8 @@ sub search { } # pkg_classnum + # all_pkg_classnums + # any_pkg_status if ( $params->{'pkg_classnum'} ) { my @pkg_classnums = ref( $params->{'pkg_classnum'} ) ? @{ $params->{'pkg_classnum'} } : @@ -966,11 +968,13 @@ sub search { 'part_pkg.classnum IN('. join(',', @pkg_classnums).')'; } foreach (@pkg_where) { - push @where, "EXISTS(". + my $select_pkg = "SELECT 1 FROM cust_pkg JOIN part_pkg USING (pkgpart) WHERE ". - "cust_pkg.custnum = cust_main.custnum AND ". - $_ . ' AND ' . FS::cust_pkg->active_sql . - ')'; + "cust_pkg.custnum = cust_main.custnum AND $_ "; + if ( not $params->{'any_pkg_status'} ) { + $select_pkg .= 'AND '.FS::cust_pkg->active_sql; + } + push @where, "EXISTS($select_pkg)"; } } } |