summaryrefslogtreecommitdiff
path: root/FS/FS/Report
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2018-04-15 22:48:58 -0500
committerMitch Jackson <mitch@freeside.biz>2018-04-15 22:48:58 -0500
commitc5386b4378bcad35867beabec1c344c0a596aecb (patch)
treebfa677eb992906b5ae2e638b477497915d6b129e /FS/FS/Report
parentadfc623691f9de2feacdb62b5b596112509e2ce9 (diff)
RT# 79353 Update discount graph - include waived setup fees
Diffstat (limited to 'FS/FS/Report')
-rw-r--r--FS/FS/Report/Table.pm60
1 files changed, 60 insertions, 0 deletions
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index 0c4d9bf..cef7813 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -745,6 +745,12 @@ sub cust_bill_pkg_detail {
}
+=item cust_bill_pkg_discount: Discounts issued
+
+Arguments: agentnum, refnum, cust_classnum
+
+=cut
+
sub cust_bill_pkg_discount {
my $self = shift;
my ($speriod, $eperiod, $agentnum, %opt) = @_;
@@ -770,6 +776,60 @@ sub cust_bill_pkg_discount {
$self->scalar_sql($total_sql);
}
+=item cust_bill_pkg_discount_or_waived: Discounts and waived fees issued
+
+Arguments: agentnum, refnum, cust_classnum
+
+=cut
+
+sub cust_bill_pkg_discount_or_waived {
+
+ my $self = shift;
+ my ($speriod, $eperiod, $agentnum, %opt) = @_;
+
+ $agentnum ||= $opt{'agentnum'};
+
+ my $total_sql = "
+ SELECT
+ COALESCE(
+ SUM(
+ COALESCE(
+ cust_bill_pkg_discount.amount,
+ CAST(( SELECT optionvalue
+ FROM part_pkg_option
+ WHERE
+ part_pkg_option.pkgpart = cust_pkg.pkgpart
+ AND optionname = 'setup_fee'
+ ) AS NUMERIC )
+ )
+ ),
+ 0
+ )
+ FROM cust_bill_pkg
+ LEFT JOIN cust_bill_pkg_discount USING (billpkgnum)
+ LEFT JOIN cust_pkg ON cust_bill_pkg.pkgnum = cust_pkg.pkgnum
+ LEFT JOIN part_pkg USING (pkgpart)
+ LEFT JOIN cust_bill USING ( invnum )
+ LEFT JOIN cust_main ON cust_pkg.custnum = cust_main.custnum
+ WHERE
+ (
+ cust_bill_pkg_discount.billpkgdiscountnum IS NOT NULL
+ OR (
+ cust_pkg.setup = cust_bill_pkg.sdate
+ AND cust_pkg.waive_setup = 'Y'
+ )
+ )
+ AND cust_bill_pkg.pkgpart_override IS NULL
+ " . join "\n",
+ map { " AND ( $_ ) " }
+ grep { $_ }
+ $self->with_classnum($opt{'classnum'}, $opt{'use_override'}),
+ $self->with_report_option(%opt),
+ $self->in_time_period_and_agent($speriod, $eperiod, $agentnum);
+
+ $self->scalar_sql($total_sql);
+}
+
sub cust_bill_pkg_taxes {
my $self = shift;
my ($speriod, $eperiod, $agentnum, %opt) = @_;