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
});
}
}
+ ##
+ # 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
##
)";
}
+ ##
+ # 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
###
AND dest = 'POST' )"
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
##
: ( $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;
-
}
###
}
# pkg_classnum
+ # all_pkg_classnums
+ # any_pkg_status
if ( $params->{'pkg_classnum'} ) {
my @pkg_classnums = ref( $params->{'pkg_classnum'} ) ?
@{ $params->{'pkg_classnum'} } :
'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)";
}
}
}
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',
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: $!";