X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=461633a721f5186ad63bf36a23ec83cd325764d2;hb=e679fff4ed72a972cc650a394814e6869719f98b;hp=b52b3596a20e0fb4fc3e9bd1ed842c384a2c0755;hpb=8baa8e46e67f00f297d7e10dad02c131d286f40e;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index b52b3596a..461633a72 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -477,11 +477,12 @@ sub smart_search { push @cust_main, qsearch({ 'table' => 'cust_main', + 'addl_from' => ' JOIN cust_payby USING (custnum)', 'hashref' => {}, - 'extra_sql' => " WHERE ( payinfo LIKE '$like_search' - OR paymask = '$mask_search' + 'extra_sql' => " WHERE ( cust_payby.payinfo LIKE '$like_search' + OR cust_payby.paymask = '$mask_search' ) ". - " AND payby IN ('CARD','DCRD') ". + " AND cust_payby.payby IN ('CARD','DCRD') ". " AND $agentnums_sql", #agent virtulization }); @@ -727,6 +728,30 @@ sub search { } ## + # county + ## + if ( $params->{'county'} =~ /\S/ ) { + my $county = dbh->quote($params->{'county'}); + push @where, "EXISTS( + SELECT 1 FROM cust_location + WHERE cust_location.custnum = cust_main.custnum + AND cust_location.county = $county + )"; + } + + ## + # state + ## + if ( $params->{'state'} =~ /\S/ ) { + my $state = dbh->quote($params->{'state'}); + push @where, "EXISTS( + SELECT 1 FROM cust_location + WHERE cust_location.custnum = cust_main.custnum + AND cust_location.state = $state + )"; + } + + ## # zipcode ## if ( $params->{'zip'} =~ /\S/ ) { @@ -738,6 +763,18 @@ sub search { )"; } + ## + # country + ## + if ( $params->{'country'} =~ /^(\w\w)$/ ) { + my $country = uc($1); + push @where, "EXISTS( + SELECT 1 FROM cust_location + WHERE cust_location.custnum = cust_main.custnum + AND cust_location.country = '$country' + )"; + } + ### # refnum ### @@ -795,6 +832,18 @@ sub search { if $params->{'no_POST'}; ## + # "tax exempt" checkbox + ## + push @where, "cust_main.tax = 'Y'" + if $params->{'tax'}; + + ## + # "not tax exempt" checkbox + ## + push @where, "(cust_main.tax = '' OR cust_main.tax IS NULL )" + if $params->{'no_tax'}; + + ## # dates ## @@ -860,10 +909,10 @@ sub search { : ( $params->{'payby'} ); @payby = grep /^([A-Z]{4})$/, @payby; - - push @where, '( '. join(' OR ', map "cust_main.payby = '$_'", @payby). ' )' + my $in_payby = 'IN(' . join(',', map {"'$_'"} @payby) . ')'; + push @where, "EXISTS( SELECT 1 FROM cust_payby WHERE payby $in_payby ". + "AND cust_payby.custnum = cust_main.custnum)" if @payby; - } ### @@ -950,6 +999,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 +1017,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)"; } } } @@ -999,6 +1052,7 @@ sub search { my @select = ( 'cust_main.custnum', + 'cust_main.salesnum', # there's a good chance that we'll need these 'cust_main.bill_locationnum', 'cust_main.ship_locationnum', @@ -1247,7 +1301,7 @@ sub append_fuzzyfiles_fuzzyfield { my ($field, $table) = reverse split('\.', $fuzzyfield); $table ||= 'cust_main'; - return unless length($value); + return unless defined($value) && length($value); open(CACHE, '>>:encoding(UTF-8)', "$dir/$table.$field" ) or die "can't open $dir/$table.$field: $!";