X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FSearch.pm;h=cc23f50e067a830455a9e2d11bf4338d71db645d;hb=3b50b841a272a5cd55497958d572dd73a3339e7b;hp=bb5891d5d5aaf9885ed2e505865b85a792d38591;hpb=55a9939e17ab945d00336317b9842f17cc27ba6e;p=freeside.git diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index bb5891d5d..cc23f50e0 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -531,10 +531,12 @@ sub email_search { if $DEBUG; push @cust_main, - map $_->cust_main, + map { $_->cust_main } + map { $_->cust_contact } + map { $_->contact } qsearch( { - 'table' => 'cust_main_invoice', - 'hashref' => { 'dest' => $email }, + 'table' => 'contact_email', + 'hashref' => { 'emailaddress' => $email }, } ); @@ -608,14 +610,6 @@ listref of start date, end date listref of start date, end date -=item payby - -listref - -=item paydate_year - -=item paydate_month - =item current_balance listref (list returned by FS::UI::Web::parse_lt_gt($cgi, 'current_balance')) @@ -626,6 +620,10 @@ listref (list returned by FS::UI::Web::parse_lt_gt($cgi, 'current_balance')) bool +=item select_referral + +bool, join to part_referral and select part_referral.referral + =back =cut @@ -646,7 +644,6 @@ sub search { 'status' => '', 'address' => '', 'zip' => '', - 'paydate_year' => '', 'invoice_terms' => '', 'custbatch' => '', %$params @@ -728,6 +725,18 @@ 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/ ) { @@ -805,33 +814,39 @@ sub search { ## push @where, - 'EXISTS ( SELECT 1 FROM cust_main_invoice - WHERE cust_main_invoice.custnum = cust_main.custnum - AND length(dest) > 5 - )' # AND dest LIKE '%@%' + 'EXISTS ( SELECT 1 FROM contact_email + JOIN cust_contact USING (contactnum) + WHERE cust_contact.custnum = cust_main.custnum + )' if $params->{'with_email'}; ## # "with postal mail invoices" checkbox ## - push @where, - "EXISTS ( SELECT 1 FROM cust_main_invoice - WHERE cust_main_invoice.custnum = cust_main.custnum - AND dest = 'POST' )" + push @where, "cust_main.postal_invoice = 'Y'" if $params->{'POST'}; ## # "without postal mail invoices" checkbox ## - push @where, - "NOT EXISTS ( SELECT 1 FROM cust_main_invoice - WHERE cust_main_invoice.custnum = cust_main.custnum - AND dest = 'POST' )" + push @where, "cust_main.postal_invoice IS NULL" 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 ## @@ -887,40 +902,6 @@ sub search { } ### - # payby - ### - - if ( $params->{'payby'} ) { - - my @payby = ref( $params->{'payby'} ) - ? @{ $params->{'payby'} } - : ( $params->{'payby'} ); - - @payby = grep /^([A-Z]{4})$/, @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; - } - - ### - # paydate_year / paydate_month - ### - - if ( $params->{'paydate_year'} =~ /^(\d{4})$/ ) { - my $year = $1; - $params->{'paydate_month'} =~ /^(\d\d?)$/ - or die "paydate_year without paydate_month?"; - my $month = $1; - - push @where, - 'paydate IS NOT NULL', - "paydate != ''", - "CAST(paydate AS timestamp) < CAST('$year-$month-01' AS timestamp )" -; - } - - ### # invoice terms ### @@ -1050,6 +1031,13 @@ sub search { my(@extra_headers) = (); my(@extra_fields) = (); + if ($params->{'select_referral'}) { + $addl_from .= ' LEFT JOIN part_referral ON ( cust_main.refnum = part_referral.refnum ) '; + push @select, 'part_referral.referral'; + push @extra_headers, 'Advertising Source'; + push @extra_fields, 'referral'; + } + if ($params->{'flattened_pkgs'}) { #my $pkg_join = ''; @@ -1110,7 +1098,6 @@ sub search { 'extra_headers' => \@extra_headers, 'extra_fields' => \@extra_fields, }; - #warn Data::Dumper::Dumper($sql_query); $sql_query; }