From 2e1d2a91264e8441bc31583be7352ae1b3c31bb8 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 19 Aug 2009 06:15:14 +0000 Subject: [PATCH] option to count subpackages outside packages in sales report #5588 --- FS/FS/Report/Table/Monthly.pm | 15 +++++++++++++-- httemplate/graph/cust_bill_pkg.cgi | 11 ++++++++--- httemplate/graph/report_cust_bill_pkg.html | 5 +++++ httemplate/search/cust_bill_pkg.cgi | 23 ++++++++++++++++++----- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/FS/FS/Report/Table/Monthly.pm b/FS/FS/Report/Table/Monthly.pm index d75f0be79..d015f9116 100644 --- a/FS/FS/Report/Table/Monthly.pm +++ b/FS/FS/Report/Table/Monthly.pm @@ -311,11 +311,21 @@ sub cust_bill_pkg { my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_; my $where = ''; + my $comparison = ''; if ( $opt{'classnum'} =~ /^(\d+)$/ ) { if ( $1 == 0 ) { - $where = "classnum IS NULL"; + $comparison = "IS NULL"; } else { - $where = "classnum = $1"; + $comparison = "= $1"; + } + + if ( $opt{'use_override'} ) { + $where = "( + part_pkg.classnum $comparison AND pkgpart_override IS NULL OR + override.classnum $comparison AND pkgpart_override IS NOT NULL + )"; + } else { + $where = "part_pkg.classnum $comparison"; } } @@ -328,6 +338,7 @@ sub cust_bill_pkg { LEFT JOIN cust_main USING ( custnum ) LEFT JOIN cust_pkg USING ( pkgnum ) LEFT JOIN part_pkg USING ( pkgpart ) + LEFT JOIN part_pkg AS override ON pkgpart_override = override.pkgpart WHERE pkgnum != 0 AND $where AND ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum) diff --git a/httemplate/graph/cust_bill_pkg.cgi b/httemplate/graph/cust_bill_pkg.cgi index b655f1f01..021189abb 100644 --- a/httemplate/graph/cust_bill_pkg.cgi +++ b/httemplate/graph/cust_bill_pkg.cgi @@ -68,6 +68,9 @@ if ( $cgi->param('classnum') =~ /^(\d*)$/ ) { } #eslaf +my $use_override = 0; +$use_override = 1 if ( $cgi->param('use_override') ); + my $hue = 0; #my $hue_increment = 170; #my $hue_increment = 145; @@ -104,11 +107,13 @@ foreach my $agent ( $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) { my $row_classnum = ref($pkg_class) ? $pkg_class->classnum : 0; my $row_agentnum = $agent->agentnum; - push @params, [ 'classnum' => $row_classnum, - 'agentnum' => $row_agentnum, + push @params, [ 'classnum' => $row_classnum, + 'agentnum' => $row_agentnum, + 'use_override' => $use_override, ]; - push @links, "$link;agentnum=$row_agentnum;classnum=$row_classnum;"; + push @links, "$link;agentnum=$row_agentnum;classnum=$row_classnum;". + "use_override=$use_override;"; @recur_colors = ($col_scheme->colors)[0,4,8,1,5,9] unless @recur_colors; diff --git a/httemplate/graph/report_cust_bill_pkg.html b/httemplate/graph/report_cust_bill_pkg.html index 5193bf4a3..073f86773 100644 --- a/httemplate/graph/report_cust_bill_pkg.html +++ b/httemplate/graph/report_cust_bill_pkg.html @@ -25,6 +25,11 @@ --> + + + Separate sub-packages from parents + +
diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 4a31611cd..8654585b4 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -16,8 +16,8 @@ 'fields' => [ 'billpkgnum', sub { $_[0]->pkgnum > 0 - ? $_[0]->get('pkg') - : $_[0]->get('itemdesc') + ? $_[0]->get('pkg') # possibly use override.pkg + : $_[0]->get('itemdesc') # but i think this correct }, #strikethrough or "N/A ($amount)" or something these when # they're not applicable to pkg_tax search @@ -87,11 +87,22 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { # not specified: all classes # 0: empty class # N: classnum +my $use_override = $cgi->param('use_override'); if ( $cgi->param('classnum') =~ /^(\d+)$/ ) { + my $comparison = ''; if ( $1 == 0 ) { - push @where, "classnum IS NULL"; + $comparison = "IS NULL"; } else { - push @where, "classnum = $1"; + $comparison = "= $1"; + } + + if ( $use_override ) { + push @where, "( + part_pkg.classnum $comparison AND pkgpart_override IS NULL OR + override.classnum $comparison AND pkgpart_override IS NOT NULL + )"; + } else { + push @where, "part_pkg.classnum $comparison"; } } @@ -372,7 +383,9 @@ my $join_pkg; if ( $cgi->param('nottax') ) { $join_pkg = ' LEFT JOIN cust_pkg USING ( pkgnum ) - LEFT JOIN part_pkg USING ( pkgpart ) '; + LEFT JOIN part_pkg USING ( pkgpart ) + LEFT JOIN part_pkg AS override + ON pkgpart_override = override.pkgpart '; $join_pkg .= ' LEFT JOIN cust_location USING ( locationnum ) ' if $conf->exists('tax-pkg_address'); -- 2.11.0