X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=22b8495bc8ca965707801c4c4bcb9f7a1a9045fd;hb=063ced0a93e31b662d9aef69ee2c10b117f90784;hp=b52b3596a20e0fb4fc3e9bd1ed842c384a2c0755;hpb=39bd5b53c899df1f543ef85dac206cdc135e9f3f;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index b52b3596a..22b8495bc 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -727,6 +727,42 @@ sub search { } ## + # city + ## + if ( $params->{'city'} =~ /\S/ ) { + my $city = dbh->quote($params->{'city'}); + push @where, "EXISTS( + SELECT 1 FROM cust_location + WHERE cust_location.custnum = cust_main.custnum + AND cust_location.city = $city + )"; + } + + ## + # 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 +774,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 +843,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 ## @@ -950,6 +1010,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 +1028,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)"; } } } @@ -995,10 +1059,15 @@ sub search { '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 = ( 'cust_main.custnum', + 'cust_main.salesnum', # there's a good chance that we'll need these 'cust_main.bill_locationnum', 'cust_main.ship_locationnum',