#substring
- my @company_hashrefs = (
- { 'company' => { op=>'ILIKE', value=>"%$value%" }, },
- { 'ship_company' => { op=>'ILIKE', value=>"%$value%" }, },
- );
+ my @company_hashrefs = ();
+ if ( length($value) >= 4 ) {
+ @company_hashrefs = (
+ { 'company' => { op=>'ILIKE', value=>"%$value%" }, },
+ { 'ship_company' => { op=>'ILIKE', value=>"%$value%" }, },
+ );
+ }
my @hashrefs = ();
-
if ( $first && $last ) {
@hashrefs = (
},
);
- } else {
+ } elsif ( length($value) >= 4 ) {
@hashrefs = (
{ 'first' => { op=>'ILIKE', value=>"%$value%" }, },
{ 'last' => { op=>'ILIKE', value=>"%$value%" }, },
);
+
}
foreach my $hashref ( @company_hashrefs, @hashrefs ) {
}
- if ( $conf->exists('address1-search') ) {
+ if ( $conf->exists('address1-search') && length($value) >= 4 ) {
push @cust_main, qsearch( {
table => 'cust_main',
'contact.first' => $first }, #
%fuzopts
);
- }
+ }
+
foreach my $field ( 'first', 'last', 'company', 'ship_company' ) {
push @cust_main, FS::cust_main::Search->fuzzy_search(
{ $field => $value },
sub email_search {
my %options = @_;
- local($DEBUG) = 1;
-
my $email = delete $options{'email'};
- #we're only being used by RT at the moment... no agent virtualization yet
+ #no agent virtualization yet
#my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
my @cust_main = ();
push @where, FS::cust_main->$method();
}
+ my $current = '';
+ unless ( $params->{location_history} ) {
+ $current = '
+ AND ( cust_location.locationnum IN ( cust_main.bill_locationnum,
+ cust_main.ship_locationnum
+ )
+ OR cust_location.locationnum IN (
+ SELECT locationnum FROM cust_pkg
+ WHERE cust_pkg.custnum = cust_main.custnum
+ AND locationnum IS NOT NULL
+ AND '. FS::cust_pkg->ncancelled_recurring_sql.'
+ )
+ )';
+ }
+
##
# address
##
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND (".join(' OR ',@orwhere).")
+ $current
)";
}
}
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND cust_location.city = $city
+ $current
)";
}
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND cust_location.county = $county
+ $current
)";
}
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND cust_location.state = $state
+ $current
)";
}
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND cust_location.zip LIKE $zip
+ $current
)";
}
SELECT 1 FROM cust_location
WHERE cust_location.custnum = cust_main.custnum
AND cust_location.country = '$country'
+ $current
)";
}
push @where, "(cust_main.tax = '' OR cust_main.tax IS NULL )"
if $params->{'no_tax'};
+ ##
+ # with referrals
+ ##
+ if ( $params->{'with_referrals'} ) {
+ push @where,
+ ' EXISTS ( SELECT 1 FROM cust_main AS referred_cust_main
+ WHERE cust_main.custnum = referred_cust_main.referral_custnum )';
+ }
+
##
# dates
##
'ON (cust_main.'.$pre.'locationnum = '.$pre.'location.locationnum) ';
}
+ # always make referral available in results
+ # (maybe we should be using FS::UI::Web::join_cust_main instead?)
+ $addl_from .= ' LEFT JOIN (select refnum, referral from part_referral) AS part_referral_x ON (cust_main.refnum = part_referral_x.refnum) ';
+
my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from $extra_sql";
my @select = (
}
+ if ( $params->{'with_referrals'} ) {
+
+ #XXX next: num for each customer status
+
+ push @select,
+ '( SELECT COUNT(*) FROM cust_main AS referred_cust_main
+ WHERE cust_main.custnum = referred_cust_main.referral_custnum
+ ) AS num_referrals';
+
+ unshift @extra_headers, 'Referrals';
+ unshift @extra_fields, 'num_referrals';
+
+ }
+
my $select = join(', ', @select);
my $sql_query = {