}
###
- # parse refnum (advertising source)
+ # parse (customer) refnum (advertising source)
###
if ( exists($params->{'refnum'}) ) {
@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;
}
###
my $op = $params->{location_cust} ? '=' : '!=';
push @where, "cust_location.locationnum $op cust_main.ship_locationnum";
}
- if ( $params->{location_census} xor $params->{location_nocensus} ) {
- my $op = $params->{location_census} ? "IS NOT NULL" : "IS NULL";
- push @where, "cust_location.censustract $op";
+ if ( $params->{location_census} ) {
+ push @where, "cust_location.censustract IS NOT NULL",
+ "cust_location.censusyear = '2020' ";
+ } elsif ( $params->{location_nocensus} ) {
+ push @where, "( cust_location.censustract IS NULL ".
+ " OR cust_location.censusyear != '2020' )";
}
if ( $params->{location_geocode} xor $params->{location_nogeocode} ) {
my $op = $params->{location_geocode} ? "IS NOT NULL" : "IS NULL";
push @where, $FS::CurrentUser::CurrentUser->agentnums_sql('table'=>'cust_main');
}
+ push @where, "cust_pkg_reason.reasonnum = '".$params->{reasonnum}."'" if $params->{reasonnum};
+
my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
my $addl_from = 'LEFT JOIN part_pkg USING ( pkgpart ) '.
'LEFT JOIN cust_location USING ( locationnum ) '.
FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
+ if ($params->{reasonnum}) {
+ $addl_from .= 'LEFT JOIN cust_pkg_reason ON (cust_pkg_reason.pkgnum = cust_pkg.pkgnum) ';
+ }
+
my $select;
my $count_query;
if ( $params->{'select_zip5'} ) {