summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_bill.pm8
-rw-r--r--FS/FS/cust_bill_event.pm6
-rw-r--r--FS/FS/cust_event.pm8
-rw-r--r--FS/FS/cust_main.pm18
-rw-r--r--FS/FS/cust_pkg.pm8
-rw-r--r--FS/FS/svc_acct.pm139
6 files changed, 163 insertions, 24 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index af70add4a..cec793539 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -4223,7 +4223,7 @@ sub re_X {
my $distinct = '';
my $orderby = 'ORDER BY cust_bill._date';
- my $extra_sql = ' WHERE '. FS::cust_bill->search_sql(\%param);
+ my $extra_sql = ' WHERE '. FS::cust_bill->search_sql_where(\%param);
my $addl_from = 'LEFT JOIN cust_main USING ( custnum )';
@@ -4313,7 +4313,7 @@ sub credited_sql {
WHERE cust_bill.invnum = cust_credit_bill.invnum )";
}
-=item search_sql HASHREF
+=item search_sql_where HASHREF
Class method which returns an SQL WHERE fragment to search for parameters
specified in HASHREF. Valid parameters are
@@ -4356,10 +4356,10 @@ Note: validates all passed-in data; i.e. safe to use with unchecked CGI params.
=cut
-sub search_sql {
+sub search_sql_where {
my($class, $param) = @_;
if ( $DEBUG ) {
- warn "$me search_sql called with params: \n".
+ warn "$me search_sql_where called with params: \n".
join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n";
}
diff --git a/FS/FS/cust_bill_event.pm b/FS/FS/cust_bill_event.pm
index 7c2ad3745..36afed040 100644
--- a/FS/FS/cust_bill_event.pm
+++ b/FS/FS/cust_bill_event.pm
@@ -201,7 +201,7 @@ sub retriable {
$self->replace($old);
}
-=item search_sql HASHREF
+=item search_sql_where HASHREF
Class method which returns an SQL WHERE fragment to search for parameters
specified in HASHREF. Valid parameters are
@@ -236,7 +236,7 @@ Specifies the user for agent virtualization
=cut
-sub search_sql {
+sub search_sql_where {
my ($class, $params) = @_;
my @search = ();
@@ -324,7 +324,7 @@ sub process_re_X {
sub re_X {
my($method, $param, $job) = @_;
- my $where = FS::cust_bill_event->search_sql($param);
+ my $where = FS::cust_bill_event->search_sql_where($param);
$where = " WHERE plan LIKE 'send%'". ( $where ? " AND $where" : "" );
my $from = 'LEFT JOIN part_bill_event USING ( eventpart )'.
diff --git a/FS/FS/cust_event.pm b/FS/FS/cust_event.pm
index bf3a5b749..d2fcfc1e2 100644
--- a/FS/FS/cust_event.pm
+++ b/FS/FS/cust_event.pm
@@ -315,7 +315,7 @@ sub join_sql {
}
-=item search_sql HASHREF
+=item search_sql_where HASHREF
Class method which returns an SQL WHERE fragment to search for parameters
specified in HASHREF. Valid parameters are
@@ -347,10 +347,10 @@ specified in HASHREF. Valid parameters are
#Note: validates all passed-in data; i.e. safe to use with unchecked CGI params.
#sub
-sub search_sql {
+sub search_sql_where {
my($class, $param) = @_;
if ( $DEBUG ) {
- warn "$me search_sql called with params: \n".
+ warn "$me search_sql_where called with params: \n".
join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n";
}
@@ -448,7 +448,7 @@ sub process_re_X {
sub re_X {
my($method, $param, $job) = @_;
- my $search_sql = FS::cust_event->search_sql($param);
+ my $search_sql = FS::cust_event->search_sql_where($param);
#maybe not...? we do want the "re-" action to match the search more closely
# # yuck! hardcoded *AND* sequential scans!
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 372aeb033..6e5bd10b4 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -8153,7 +8153,7 @@ sub _money_table_where {
}
-=item search_sql HASHREF
+=item search HASHREF
(Class method)
@@ -8196,7 +8196,7 @@ bool
=cut
-sub search_sql {
+sub search {
my ($class, $params) = @_;
my $dbh = dbh;
@@ -8396,13 +8396,13 @@ sub search_sql {
}
-=item email_search_sql HASHREF
+=item email_search_result HASHREF
(Class method)
Emails a notice to the specified customers.
-Valid parameters are those of the L<search_sql> method, plus the following:
+Valid parameters are those of the L<search> method, plus the following:
=over 4
@@ -8436,7 +8436,7 @@ retrying everything.
=cut
-sub email_search_sql {
+sub email_search_result {
my($class, $params) = @_;
my $from = delete $params->{from};
@@ -8449,7 +8449,7 @@ sub email_search_sql {
$params->{'payby'} = [ split(/\0/, $params->{'payby'}) ]
unless ref($params->{'payby'});
- my $sql_query = $class->search_sql($params);
+ my $sql_query = $class->search($params);
my $count_query = delete($sql_query->{'count_query'});
my $count_sth = dbh->prepare($count_query)
@@ -8501,7 +8501,7 @@ sub email_search_sql {
use Storable qw(thaw);
use Data::Dumper;
use MIME::Base64;
-sub process_email_search_sql {
+sub process_email_search_result {
my $job = shift;
#warn "$me process_re_X $method for job $job\n" if $DEBUG;
@@ -8513,7 +8513,7 @@ sub process_email_search_sql {
$param->{'payby'} = [ split(/\0/, $param->{'payby'}) ]
unless ref($param->{'payby'});
- my $error = FS::cust_main->email_search_sql( $param );
+ my $error = FS::cust_main->email_search_result( $param );
die $error if $error;
}
@@ -8792,7 +8792,7 @@ sub smart_search {
#getting complaints searches are not returning enough
unless ( @cust_main && $skip_fuzzy || $conf->exists('disable-fuzzy') ) {
- #still some false laziness w/search_sql (was search/cust_main.cgi)
+ #still some false laziness w/search (was search/cust_main.cgi)
#substring
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 58cca6d53..c6d98fa77 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -2291,7 +2291,7 @@ sub cancel_sql {
"cust_pkg.cancel IS NOT NULL AND cust_pkg.cancel != 0";
}
-=item search_sql HASHREF
+=item search HASHREF
(Class method)
@@ -2364,7 +2364,7 @@ specifies the user for agent virtualization
=cut
-sub search_sql {
+sub search {
my ($class, $params) = @_;
my @where = ();
@@ -2593,10 +2593,10 @@ sub search_sql {
if ($access_user) {
push @where, $access_user->agentnums_sql('table'=>'cust_main');
- }else{
+ } else {
push @where, "1=0";
}
- }else{
+ } else {
push @where, $FS::CurrentUser::CurrentUser->agentnums_sql('table'=>'cust_main');
}
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index 32dba2560..bbf2c2293 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -28,6 +28,7 @@ use FS::Conf;
use FS::Record qw( qsearch qsearchs fields dbh dbdef );
use FS::Msgcat qw(gettext);
use FS::UI::bytecount;
+use FS::UI::Web;
use FS::part_pkg;
use FS::svc_Common;
use FS::cust_svc;
@@ -2500,6 +2501,144 @@ sub virtual_maildir {
=back
+=head1 CLASS METHODS
+
+=over 4
+
+=item search HASHREF
+
+Class method which returns a qsearch hash expression to search for parameters
+specified in HASHREF. Valid parameters are
+
+=over 4
+
+=item domain
+
+=item domsvc
+
+=item unlinked
+
+=item agentnum
+
+=item pkgpart
+
+Arrayref of pkgparts
+
+=item pkgpart
+
+=item where
+
+Arrayref of additional WHERE clauses, will be ANDed together.
+
+=item order_by
+
+=item cust_fields
+
+=back
+
+=cut
+
+sub search {
+ my ($class, $params) = @_;
+
+ my @where = ();
+
+ # domain
+ if ( $params->{'domain'} ) {
+ my $svc_domain = qsearchs('svc_domain', { 'domain'=>$params->{'domain'} } );
+ #preserve previous behavior & bubble up an error if $svc_domain not found?
+ push @where, 'domsvc = '. $svc_domain->svcnum if $svc_domain;
+ }
+
+ # domsvc
+ if ( $params->{'domsvc'} =~ /^(\d+)$/ ) {
+ push @where, "domsvc = $1";
+ }
+
+ #unlinked
+ push @where, 'pkgnum IS NULL' if $params->{'unlinked'};
+
+ #agentnum
+ if ( $params->{'agentnum'} =~ /^(\d+)$/ and $1 ) {
+ push @where, "agentnum = $1";
+ }
+
+ #custnum
+ if ( $params->{'custnum'} =~ /^(\d+)$/ and $1 ) {
+ push @where, "custnum = $1";
+ }
+
+ #pkgpart
+ if ( $params->{'pkgpart'} && scalar(@{ $params->{'pkgpart'} }) ) {
+ #XXX untaint or sql quote
+ push @where,
+ 'cust_pkg.pkgpart IN ('. join(',', @{ $params->{'pkgpart'} } ). ')';
+ }
+
+ # popnum
+ if ( $params->{'popnum'} =~ /^(\d+)$/ ) {
+ push @where, "popnum = $1";
+ }
+
+ # svcpart
+ if ( $params->{'svcpart'} =~ /^(\d+)$/ ) {
+ push @where, "svcpart = $1";
+ }
+
+
+ # here is the agent virtualization
+ #if ($params->{CurrentUser}) {
+ # my $access_user =
+ # qsearchs('access_user', { username => $params->{CurrentUser} });
+ #
+ # if ($access_user) {
+ # push @where, $access_user->agentnums_sql('table'=>'cust_main');
+ # }else{
+ # push @where, "1=0";
+ # }
+ #} else {
+ push @where, $FS::CurrentUser::CurrentUser->agentnums_sql(
+ 'table' => 'cust_main',
+ 'null_right' => 'View/link unlinked services',
+ );
+ #}
+
+ push @where, @{ $params->{'where'} } if $params->{'where'};
+
+ my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
+
+ my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+ my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
+ #if ( keys %svc_acct ) {
+ # $count_query .= ' WHERE '.
+ # join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
+ # keys %svc_acct
+ # );
+ #}
+
+ my $sql_query = {
+ 'table' => 'svc_acct',
+ 'hashref' => {}, # \%svc_acct,
+ 'select' => join(', ',
+ 'svc_acct.*',
+ 'part_svc.svc',
+ 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields($params->{'cust_fields'}),
+ ),
+ 'addl_from' => $addl_from,
+ 'extra_sql' => $extra_sql,
+ 'order_by' => $params->{'order_by'},
+ 'count_query' => $count_query,
+ };
+
+}
+
+=back
+
=head1 SUBROUTINES
=over 4