+
+# Filter: User
+if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
+ push @where,
+ "( cust_pkg_discount.usernum = $1 OR cust_pkg_discount.usernum IS NULL )";
+}
+
+# Filter: Include waived setup fees
+if ( $cgi->param('include_waived_setup') ) {
+ # Filter a hidden fee attached to a package with a waived setup fee from
+ # causing the waived-fee for that package to be double-counted
+ push @where, 'cust_bill_pkg.pkgpart_override IS NULL';
+} else {
+ push @where, "cust_bill_pkg_discount.pkgdiscountnum IS NOT NULL";
+}
+
+# Filter: Discount Class
+if ( grep { $_ eq 'discount_classnum' } $cgi->param ) {
+
+# my @classnum = ();
+# if ( ref($params->{'discount_classnum'}) ) {
+#
+# if ( ref($params->{'discount_classnum'}) eq 'HASH' ) {
+# @classnum = grep $params->{'discount_classnum'}{$_}, keys %{ $params->{'discount_classnum'} };
+# } elsif ( ref($params->{'discount_classnum'}) eq 'ARRAY' ) {
+# @classnum = @{ $params->{'discount_classnum'} };
+# } else {
+# die 'unhandled discount_classnum ref '. $params->{'discount_classnum'};
+# }
+#
+#
+# } elsif ( $params->{'discount_classnum'} =~ /^(\d*)$/ && $1 ne '0' ) {
+# @classnum = ( $1 );
+# }
+#
+# if ( @classnum ) {
+
+ if ( $cgi->param('discount_classnum') =~ /^(\d*)$/ && $1 ne '0' ) {
+ my @classnum = ( $1 );
+
+ $join .= ' LEFT JOIN discount USING (discountnum) ';
+
+ my @c_where = ();
+ my @nums = grep $_, @classnum;
+ push @c_where, 'discount.classnum IN ('. join(',',@nums). ')' if @nums;
+ my $null = scalar( grep { $_ eq '' } @classnum );
+ push @c_where, 'discount.classnum IS NULL' if $null;
+
+ if ( scalar(@c_where) == 1 ) {
+ push @where, @c_where;
+ } elsif ( @c_where ) {
+ push @where, ' ( '. join(' OR ', @c_where). ' ) ';
+ }
+
+ }
+
+}
+
+# #(package) classnum