}
+=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) = @_;
$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) = @_;
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+my $include_waived_setup = $cgi->param('include_waived_setup') || 0;
+
my $link = "${p}search/cust_bill_pkg_discount.html?";
+$link .= "include_waived_setup=Y&" if $include_waived_setup;
my $bottom_link = $link;
#XXX or virtual
$title .= 'Discount Overview';
-my $hue = 0;
+#my $hue = 0; # Start with illegible yellow-on-white
+my $hue = 255; # Start with red-on-white
#my $hue_increment = 170;
#my $hue_increment = 145;
my $hue_increment = 125;
#foreach my $pkg_class ( @pkg_class ) {
- push @items, 'cust_bill_pkg_discount';
+ push @items,
+ $include_waived_setup
+ ? 'cust_bill_pkg_discount_or_waived'
+ : 'cust_bill_pkg_discount';
push @labels,
( $sel_agent ? '' : $agent->agent.' ' );
}
# Filter: Include waived setup fees
-if ( !$cgi->param('include_waived_setup') ) {
+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";
}