( my $card_search = $nospace_search ) =~ s/\-//g;
$card_search =~ s/[x\*\.\_]/x/gi;
- if ( $nospace_search =~ /^[\dx]{16}$/i ) { #credit card search
+ if ( $card_search =~ /^[\dx]{15,16}$/i ) { #credit card search
( my $like_search = $card_search ) =~ s/x/_/g;
my $mask_search = FS::payinfo_Mixin->mask_payinfo('CARD', $card_search);
}
##
- # do the same for user
+ # parse sales person
+ ##
+
+ if ( $params->{'salesnum'} =~ /^(\d+)$/ ) {
+ push @where, ($1 > 0 ) ? "cust_main.salesnum = $1"
+ : 'cust_main.salesnum IS NULL';
+ }
+
+ ##
+ # parse usernum
##
if ( $params->{'usernum'} =~ /^(\d+)$/ and $1 ) {
##
# address
##
- if ( $params->{'address'} =~ /\S/ ) {
- my $address = dbh->quote('%'. lc($params->{'address'}). '%');
- push @where, "EXISTS(
- SELECT 1 FROM cust_location
- WHERE cust_location.custnum = cust_main.custnum
- AND (LOWER(cust_location.address1) LIKE $address OR
- LOWER(cust_location.address2) LIKE $address)
- )";
+ if ( $params->{'address'} ) {
+ # allow this to be an arrayref
+ my @values = ($params->{'address'});
+ @values = @{$values[0]} if ref($values[0]);
+ my @orwhere;
+ foreach (grep /\S/, @values) {
+ my $address = dbh->quote('%'. lc($_). '%');
+ push @orwhere,
+ "LOWER(cust_location.address1) LIKE $address",
+ "LOWER(cust_location.address2) LIKE $address";
+ }
+ if (@orwhere) {
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND (".join(' OR ',@orwhere).")
+ )";
+ }
}
##
# parse with hardcoded tax location checkbox
##
- push @where, "ship_location.geocode is not null"
+ my $tax_prefix = FS::Conf->new->exists('tax-ship_location') ? 'ship_'
+ : 'bill_';
+ push @where, "${tax_prefix}location.geocode is not null"
if $params->{'with_geocode'};
##