X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg%2FSearch.pm;h=311dbdbe11648611ba8c203289b98ff9d48990a6;hb=8f35bf476386cfd746ab9fd27d584a4d89d3eeb9;hp=89809de6cb35ca3c1a3cb24e85342f6bce942ea3;hpb=fa0223015fe6c03491b1d0d43524e03ac5fdb899;p=freeside.git diff --git a/FS/FS/cust_pkg/Search.pm b/FS/FS/cust_pkg/Search.pm index 89809de6c..311dbdbe1 100644 --- a/FS/FS/cust_pkg/Search.pm +++ b/FS/FS/cust_pkg/Search.pm @@ -281,7 +281,7 @@ sub search { } ### - # parse refnum (advertising source) + # parse (customer) refnum (advertising source) ### if ( exists($params->{'refnum'}) ) { @@ -292,7 +292,7 @@ sub search { @refnum = ( $params->{'refnum'} ); } my $in = join(',', grep /^\d+$/, @refnum); - push @where, "refnum IN($in)" if length $in; + push @where, "cust_main.refnum IN($in)" if length $in; } ### @@ -450,7 +450,8 @@ sub search { '' => {}, ); - if( exists($params->{'active'} ) ) { + if ( exists($params->{'active'} ) ) { + # This overrides all the other date-related fields, and includes packages # that were active at some time during the interval. It excludes: # - packages that were set up after the end of the interval @@ -464,40 +465,51 @@ sub search { "(cust_pkg.cancel IS NULL OR cust_pkg.cancel >= $beginning )", "(cust_pkg.susp IS NULL OR cust_pkg.susp >= $beginning )", "NOT (".FS::cust_pkg->onetime_sql . ")"; - } - else { + + } else { + my $exclude_change_from = 0; my $exclude_change_to = 0; foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end change_date cancel )) { - next unless exists($params->{$field}); + if ( $params->{$field.'_null'} ) { + + push @where, "cust_pkg.$field IS NULL"; + # this should surely be obsoleted by now: OR cust_pkg.$field == 0 ) - my($beginning, $ending) = @{$params->{$field}}; + } else { - next if $beginning == 0 && $ending == 4294967295; + next unless exists($params->{$field}); + + my($beginning, $ending) = @{$params->{$field}}; + + next if $beginning == 0 && $ending == 4294967295; + + push @where, + "cust_pkg.$field IS NOT NULL", + "cust_pkg.$field >= $beginning", + "cust_pkg.$field <= $ending"; + + $orderby ||= "ORDER BY cust_pkg.$field"; + + if ( $field eq 'setup' ) { + $exclude_change_from = 1; + } elsif ( $field eq 'cancel' ) { + $exclude_change_to = 1; + } elsif ( $field eq 'change_date' ) { + # if we are given setup and change_date ranges, and the setup date + # falls in _both_ ranges, then include the package whether it was + # a change or not + $exclude_change_from = 0; + } - push @where, - "cust_pkg.$field IS NOT NULL", - "cust_pkg.$field >= $beginning", - "cust_pkg.$field <= $ending"; - - $orderby ||= "ORDER BY cust_pkg.$field"; - - if ( $field eq 'setup' ) { - $exclude_change_from = 1; - } elsif ( $field eq 'cancel' ) { - $exclude_change_to = 1; - } elsif ( $field eq 'change_date' ) { - # if we are given setup and change_date ranges, and the setup date - # falls in _both_ ranges, then include the package whether it was - # a change or not - $exclude_change_from = 0; } + } if ($exclude_change_from) { - push @where, "change_pkgnum IS NULL"; + push @where, "cust_pkg.change_pkgnum IS NULL"; } if ($exclude_change_to) { # a join might be more efficient here @@ -506,6 +518,7 @@ sub search { WHERE cust_pkg.pkgnum = changed_to_pkg.change_pkgnum )"; } + } $orderby ||= 'ORDER BY bill';