diff options
author | Mark Wells <mark@freeside.biz> | 2014-12-06 13:01:09 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-12-06 13:01:09 -0800 |
commit | 0feb608d2333f8709e02af8aa68f2da3e5deb581 (patch) | |
tree | 97580dd68914d60104e8eb440646efba3d8fe712 /FS/FS/Report | |
parent | 0eedfd553057f9fd8d69197675f33dbc893e6c51 (diff) |
avoid double-counting package-classed fees on the sales report, #32472
Diffstat (limited to 'FS/FS/Report')
-rw-r--r-- | FS/FS/Report/Table.pm | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm index 934287a..69686df 100644 --- a/FS/FS/Report/Table.pm +++ b/FS/FS/Report/Table.pm @@ -886,14 +886,24 @@ sub with_classnum { @$classnum = grep /^\d+$/, @$classnum; my $in = 'IN ('. join(',', @$classnum). ')'; - my $expr = " - ( COALESCE(part_pkg.classnum, 0) $in AND pkgpart_override IS NULL) - OR ( COALESCE(part_fee.classnum, 0) $in AND feepart IS NOT NULL )"; if ( $use_override ) { - $expr .= " - OR ( COALESCE(override.classnum, 0) $in AND pkgpart_override IS NOT NULL )"; + # then include packages if their base package is in the set and they are + # not overridden, + # or if they are overridden and their override package is in the set, + # or fees if they are in the set + return "( + ( COALESCE(part_pkg.classnum, 0) $in AND cust_pkg.pkgpart IS NOT NULL AND pkgpart_override IS NULL ) + OR ( COALESCE(override.classnum, 0) $in AND pkgpart_override IS NOT NULL ) + OR ( COALESCE(part_fee.classnum, 0) $in AND cust_bill_pkg.feepart IS NOT NULL ) + )"; + } else { + # include packages if their base package is in the set, + # or fees if they are in the set + return "( + ( COALESCE(part_pkg.classnum, 0) $in AND cust_pkg.pkgpart IS NOT NULL ) + OR ( COALESCE(part_fee.classnum, 0) $in AND cust_bill_pkg.feepart IS NOT NULL ) + )"; } - "( $expr )"; } sub with_usageclass { |