'classname',
sub { # report_option
my $cust_bill_pkg = shift;
- my $pkgpart = $cust_bill_pkg->pkgpart_override
- || $cust_bill_pkg->cust_pkg->pkgpart;
+ my $pkgpart = $cust_bill_pkg->pkgpart_override;
+ unless ( $pkgpart ) {
+ my $cust_pkg = $cust_bill_pkg->cust_pkg or return '';
+ $pkgpart = $cust_pkg->pkgpart;
+ }
if ( !exists($report_classes{$pkgpart}) ) {
my $part_pkg = FS::part_pkg->by_key($pkgpart);
my %opts = $part_pkg->options;
'color' => [ ('') x (5 + $x),
sub {
my $cust_pkg = shift->cust_pkg;
- $cust_pkg ? ucfirst($cust_pkg->statuscolor) : '';
+ $cust_pkg ? $cust_pkg->statuscolor : '';
},
('') x 6,
],
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
my @where = ( $agentnums_sql,
- 'cust_bill_pkg.pkgnum != 0', # exclude taxes
+ # exclude taxes
+ '(cust_bill_pkg.pkgnum != 0 OR '.
+ 'cust_bill_pkg.feepart IS NOT NULL)',
"cust_bill._date >= $beginning",
"cust_bill._date <= $ending",
);
-if ( $cgi->param('status') =~ /^([a-z]+)$/ ) {
- push @where, FS::cust_pkg->cust_status_sql . " = '$1'";
+my @status_where;
+foreach my $status ($cgi->param('status')) {
+ if ( $status =~ /^([- a-z]+)$/ ) { #"one-time charge"
+ push @status_where, "'$status'";
+ }
+}
+if ( @status_where ) {
+ push @where, '('. FS::cust_pkg->status_sql.
+ ') IN (' . join(',', @status_where) .')';
+}
+
+my @refnum;
+foreach my $refnum ($cgi->param('refnum')) {
+ if ( $refnum =~ /^\d+$/ ) {
+ push @refnum, $refnum;
+ }
+}
+if ( @refnum ) {
+ push @where, 'cust_main.refnum IN ('.join(',', @refnum).')';
+}
+
+# cust_classnum (false laziness w/ elements/cust_main_dayranges.html, elements/cust_pay_or_refund.html, prepaid_income.html, cust_bill_pay.html, cust_bill_pkg.html, unearned_detail.html, cust_credit.html, cust_credit_refund.html, cust_main::Search::search_sql)
+if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
+ my @classnums = grep /^\d*$/, $cgi->param('cust_classnum');
+ push @where, 'COALESCE( cust_main.classnum, 0) IN ( '.
+ join(',', map { $_ || '0' } @classnums ).
+ ' )'
+ if @classnums;
}
if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
if ( $use_override ) {
push @where, "(
- part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
- override.classnum $comparison AND pkgpart_override IS NOT NULL
+ (part_pkg.classnum $comparison AND pkgpart_override IS NULL) OR
+ (override.classnum $comparison AND pkgpart_override IS NOT NULL) OR
+ (part_fee.classnum $comparison AND feepart IS NOT NULL)
)";
} else {
- push @where, "part_pkg.classnum $comparison";
+ push @where,
+ "(part_pkg.classnum $comparison) OR (part_fee.classnum $comparison)";
}
}
push @orwhere, "(cust_bill_pkg.setup > 0)" if $setup;
push @orwhere, "($recur_sql > 0)" if $recur;
push @orwhere, "($usage_sql > 0)" if $usage;
-push @where, join(' OR ', @orwhere);
+push @where, '('.join(' OR ', @orwhere).')' if @orwhere;
$join_cust = ' JOIN cust_bill USING ( invnum )
LEFT JOIN cust_main USING ( custnum )
LEFT JOIN part_pkg USING ( pkgpart )
LEFT JOIN part_pkg AS override
ON pkgpart_override = override.pkgpart
+ LEFT JOIN part_fee USING ( feepart )
LEFT JOIN pkg_class ON '; #...
if ( $use_override ) {
# join to whichever pkgpart is appropriate
$join_pkg .= '
( pkgpart_override IS NULL AND part_pkg.classnum = pkg_class.classnum )
- OR ( pkgpart_override IS NOT NULL AND override.classnum = pkg_class.classnum )';
+ OR ( pkgpart_override IS NOT NULL AND override.classnum = pkg_class.classnum )
+ OR ( feepart IS NOT NULL AND part_fee.classnum = pkg_class.classnum )';
} else {
- $join_pkg .= 'part_pkg.classnum = pkg_class.classnum';
+ $join_pkg .= '
+ ( part_pkg.classnum = pkg_class.classnum )
+ OR ( part_fee.classnum = pkg_class.classnum )';
}
my $where = ' WHERE '. join(' AND ', @where);
FROM cust_bill_pay JOIN cust_bill_pay_pkg USING (billpaynum)
WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum";
-push @select, 'part_pkg.pkg',
+push @select, 'COALESCE(part_pkg.pkg, part_fee.itemdesc) AS pkg',
'part_pkg.freq',
'cust_main.custnum',
'cust_main.first',