[freeside-commits] branch FREESIDE_3_BRANCH updated. 224e521224cc3dea876a40440993c84626fe5ed7
Ivan
ivan at 420.am
Sat Sep 7 02:05:57 PDT 2013
The branch, FREESIDE_3_BRANCH has been updated
via 224e521224cc3dea876a40440993c84626fe5ed7 (commit)
from 1606f8ad9cacb4066dd60a8d04df20b6f3d1201a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 224e521224cc3dea876a40440993c84626fe5ed7
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sat Sep 7 02:05:54 2013 -0700
select multiple package classes (or report classes) on sales report, RT#24776
diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index ffd2ac4..03ee273 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -325,16 +325,15 @@ sub _subtract_11mo {
sub cust_pkg_setup_cost {
my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
my $where = '';
- my $comparison = '';
- if ( $opt{'classnum'} =~ /^(\d+)$/ ) {
- if ( $1 == 0 ) {
- $comparison = 'IS NULL';
- }
- else {
- $comparison = "= $1";
- }
- $where = "AND part_pkg.classnum $comparison";
+
+ if ( $opt{'classnum'} ne '' ) {
+ my $classnums = $opt{'classnum'};
+ $classnums = [ $classnums ] if !ref($classnums);
+ @$classnums = grep /^\d+$/, @$classnums;
+ $where .= ' AND COALESCE(part_pkg.classnum,0) IN ('. join(',', @$classnums).
+ ')';
}
+
$agentnum ||= $opt{'agentnum'};
my $total_sql = " SELECT SUM(part_pkg.setup_cost) ";
@@ -357,16 +356,15 @@ sub cust_pkg_setup_cost {
sub cust_pkg_recur_cost {
my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
my $where = '';
- my $comparison = '';
- if ( $opt{'classnum'} =~ /^(\d+)$/ ) {
- if ( $1 == 0 ) {
- $comparison = 'IS NULL';
- }
- else {
- $comparison = "= $1";
- }
- $where = " AND part_pkg.classnum $comparison";
+
+ if ( $opt{'classnum'} ne '' ) {
+ my $classnums = $opt{'classnum'};
+ $classnums = [ $classnums ] if !ref($classnums);
+ @$classnums = grep /^\d+$/, @$classnums;
+ $where .= ' AND COALESCE(part_pkg.classnum,0) IN ('. join(',', @$classnums).
+ ')';
}
+
$agentnum ||= $opt{'agentnum'};
# duplication of in_time_period_and_agent
# because we do it a little differently here
@@ -592,6 +590,7 @@ sub cust_bill_pkg_detail {
sub cust_bill_pkg_discount {
my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
+ #need to do this the new multi-classnum way if it gets re-enabled
#my $where = '';
#my $comparison = '';
#if ( $opt{'classnum'} =~ /^(\d+)$/ ) {
@@ -701,24 +700,20 @@ sub for_opts {
}
sub with_classnum {
- my $self = shift;
- my ($classnum, $use_override) = @_;
- return '' unless $classnum =~ /^\d+$/;
- my $comparison;
- if ( $classnum == 0 ) {
- $comparison = 'IS NULL';
- }
- else {
- $comparison = "= $classnum";
- }
+ my ($self, $classnum, $use_override) = @_;
+ return '' if $classnum eq '';
+
+ $classnum = [ $classnum ] if !ref($classnum);
+ @$classnum = grep /^\d+$/, @$classnum;
+ my $in = 'IN ('. join(',', @$classnum). ')';
+
if ( $use_override ) {
- return "(
- part_pkg.classnum $comparison AND pkgpart_override IS NULL OR
- override.classnum $comparison AND pkgpart_override IS NOT NULL
+ "(
+ ( COALESCE(part_pkg.classnum, 0) $in AND pkgpart_override IS NULL)
+ OR ( COALESCE(override.classnum, 0) $in AND pkgpart_override IS NOT NULL )
)";
- }
- else {
- return "part_pkg.classnum $comparison";
+ } else {
+ "COALESCE(part_pkg.classnum, 0) $in";
}
}
@@ -737,14 +732,14 @@ sub with_usageclass {
}
sub with_report_option {
- my $self = shift;
+ my ($self, $num, $use_override) = @_;
# $num can be a single number, or a comma-delimited list of numbers,
- # or '0' to match only the empty set.
- #
+ # or an arrayref. 0 matches the empty set
# or the word 'multiple' for all packages with more than one report class
- my ($num, $use_override) = @_;
return '' if !defined($num);
+ $num = join(',', @$num) if ref($num);
+
# stringify the set of report options for each pkgpart
my $table = $use_override ? 'override' : 'part_pkg';
my $subselect = "
@@ -757,14 +752,18 @@ sub with_report_option {
my $comparison;
if ( $num eq 'multiple' ) {
$comparison = "(SELECT COUNT(*) FROM ($subselect) AS x) > 1";
- } elsif ( $num eq '0' ) {
- $comparison = "NOT EXISTS ($subselect)";
} else {
+
+ my @num = split(/\s*,\s*/, $num);
+
#$comparison = "(SELECT COALESCE(string_agg(num, ','), '') FROM ( #Pg 9-ism
$comparison = "(SELECT COALESCE(array_to_string(array_agg(num), ','), '')
- FROM (
- $subselect
- ) AS x) = '$num'";
+ FROM ($subselect) AS x
+ ) = '". join(',', grep $_, @num). "'";
+
+ $comparison = "( $comparison OR NOT EXISTS ($subselect) )"
+ if grep !$_, @num;
+
}
if ( $use_override ) {
# then also allow the non-override package to match
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
index b6c1573..9f26a35 100644
--- a/httemplate/elements/select-table.html
+++ b/httemplate/elements/select-table.html
@@ -37,6 +37,7 @@ Example:
'post_options' => [ 'value' => 'option' ], #after normal options
'empty_label' => '', #better specify it though, the default might change
'multiple' => 0, # bool
+ 'all_selected' => 0, # useful with multiple
'disable_empty' => 0, # bool (implied by multiple)
'label_showkey' => 0, # bool
'label_callback' => sub { my $record = shift; return "label"; },
@@ -75,8 +76,9 @@ Example:
% while ( @pre_options ) {
% my $pre_opt = shift(@pre_options);
% my $pre_label = shift(@pre_options);
-% my $selected = ( ref($value) && $value->{$pre_opt} )
-% || ( $value eq $pre_opt );
+% my $selected = $opt{'all_selected'}
+% || ( ref($value) && $value->{$pre_opt} )
+% || ( $value eq $pre_opt );
<OPTION VALUE="<% $pre_opt %>"
<% $selected ? 'SELECTED' : '' %>
><% $pre_label %>
diff --git a/httemplate/graph/cust_bill_pkg.cgi b/httemplate/graph/cust_bill_pkg.cgi
index 96404a4..01d309d 100644
--- a/httemplate/graph/cust_bill_pkg.cgi
+++ b/httemplate/graph/cust_bill_pkg.cgi
@@ -73,22 +73,19 @@ my @cust_classnums = grep /^\d+$/, $cgi->param('cust_classnum');
$bottom_link .= "cust_classnum=$_;" foreach @cust_classnums;
#classnum (here)
-# 0: all classes
-# not specified: empty class
+# not specified: no longer happens (unless you de-select all classes)
+# 0: empty class
# N: classnum
#classnum (link)
# not specified: all classes
# 0: empty class
# N: classnum
-#false lazinessish w/FS::cust_pkg::search_sql (previously search/cust_pkg.cgi)
-my $classnum = 0;
-my (@classnums, @classnames);
-my $all_class = '';
+#started out as false lazinessish w/FS::cust_pkg::search_sql (previously search/cust_pkg.cgi), but not much left the sane now after #24776
my ($class_table, $name_col, $value_col, $class_param);
-if ( $cgi->param('mode') eq 'report' ) {
+if ( $cgi->param('class_mode') eq 'report' ) {
$class_param = 'report_optionnum'; # CGI param name, also used in the report engine
$class_table = 'part_pkg_report_option'; # table containing classes
$name_col = 'name'; # the column of that table containing the label
@@ -100,50 +97,43 @@ if ( $cgi->param('mode') eq 'report' ) {
$value_col = 'classnum';
}
-if ( $cgi->param($class_param) eq 'all' ) { # all, aggregated
- $all_class = 'ALL';
- @classnums = ('');
- @classnames = ('');
-} elsif ( $cgi->param($class_param) =~ /^(\d*)$/ ) {
+my @classnums = grep /^\d+$/, $cgi->param($value_col);
+my @classnames = map { if ( $_ ) {
+ my $class = qsearchs($class_table, {$value_col=>$_} );
+ $class->classname;
+ } else {
+ '(empty class)';
+ }
+ }
+ @classnums;
- $classnum = $1;
- if ( $classnum ) { #a specific class
- my $class = qsearchs($class_table, { $value_col => $classnum })
- or die "$class_table #$classnum not found";
+$bottom_link .= "$class_param=$_;" foreach @classnums;
- $title .= ' '.$class->get($name_col);
- $bottom_link .= "$class_param=$classnum;";
+if ( $cgi->param('class_agg_break') eq 'aggregate' ) {
- @classnums = ($classnum);
- @classnames = ($class->get($name_col));
+ $link .= ";$class_param=$_" foreach @classnums;
- } elsif ( $classnum eq '0' ) { #the empty class
+ $title .= ' '. join(', ', @classnames)
+ unless scalar(@classnames) > scalar(qsearch($class_table,{'disabled'=>''}));
+ #not efficient for lots of package classes
- $title .= ' Empty class ';
- @classnums = ( '' );
- @classnames = ( '(empty class)' );
- $bottom_link .= "$class_param=0;";
+} elsif ( $cgi->param('class_agg_break') eq 'breakdown' ) {
- } elsif ( $classnum eq '' ) { #all, breakdown
+ if ( $cgi->param('mode') eq 'report' ) {
+ # In theory, a package can belong to any subset of the report classes,
+ # so the report groups should be all the _subsets_, but for now we're
+ # handling the simple case where each package belongs to one report
+ # class. Packages with multiple classes will go into one bin at the
+ # end.
+ push @classnames, '(multiple classes)';
+ push @classnums, 'multiple';
+ }
- my @classes = qsearch($class_table, {});
- @classnames = map { $_->get($name_col) } @classes;
- @classnums = map { $_->get($value_col) } @classes;
+} else {
+ die "guru meditation #434";
+}
- push @classnames, '(empty class)';
- push @classnums, '0';
-
- if ( $cgi->param('mode') eq 'report' ) {
- # In theory, a package can belong to any subset of the report classes,
- # so the report groups should be all the _subsets_, but for now we're
- # handling the simple case where each package belongs to one report
- # class. Packages with multiple classes will go into one bin at the
- # end.
- push @classnames, '(multiple classes)';
- push @classnums, 'multiple';
- }
- }
-} #eslaf
+#eslaf
my $hue = 0;
#my $hue_increment = 170;
@@ -195,9 +185,14 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
qsearch('part_referral', { 'disabled' => '' } )
) {
- for (my $i = 0; $i < scalar @classnums; $i++) {
- my $row_classnum = $classnums[$i];
- my $row_classname = $classnames[$i];
+ my @base_params = (
+ 'use_override' => $use_override,
+ 'average_per_cust_pkg' => $average_per_cust_pkg,
+ 'distribute' => $distribute,
+ );
+
+ if ( $cgi->param('class_agg_break') eq 'aggregate' ) {
+
foreach my $component ( @components ) {
push @items, 'cust_bill_pkg';
@@ -205,26 +200,26 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
push @labels,
( $all_agent || $sel_agent ? '' : $agent->agent.' ' ).
( $all_part_referral || $sel_part_referral ? '' : $part_referral->referral.' ' ).
- $row_classname . ' ' . $charge_labels{$component};
+ $charge_labels{$component};
my $row_agentnum = $all_agent || $agent->agentnum;
my $row_refnum = $all_part_referral || $part_referral->refnum;
- push @params, [ ($all_class ? () : ($class_param => $row_classnum) ),
+ push @params, [
+ @base_params,
+ $class_param => \@classnums,
($all_agent ? () : ('agentnum' => $row_agentnum) ),
($all_part_referral ? () : ('refnum' => $row_refnum) ),
- 'use_override' => $use_override,
'charges' => $component,
- 'average_per_cust_pkg' => $average_per_cust_pkg,
- 'distribute' => $distribute,
];
- push @links, "$link;".
- ($all_agent ? '' : "agentnum=$row_agentnum;").
- ($all_part_referral ? '' : "refnum=$row_refnum;").
- (join('',map {"cust_classnum=$_;"} @cust_classnums)).
- ($all_class ? '' : "$class_param=$row_classnum;").
- "distribute=$distribute;".
- "use_override=$use_override;charges=$component;";
+ my $rowlink = "$link;".
+ ($all_agent ? '' : "agentnum=$row_agentnum;").
+ ($all_part_referral ? '' : "refnum=$row_refnum;").
+ (join('',map {"cust_classnum=$_;"} @cust_classnums)).
+ "distribute=$distribute;".
+ "use_override=$use_override;charges=$component;";
+ $rowlink .= "$class_param=$_;" foreach @classnums;
+ push @links, $rowlink;
@recur_colors = ($col_scheme->colors)[0,4,8,1,5,9]
unless @recur_colors;
@@ -234,7 +229,51 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
push @no_graph, 0;
} #foreach $component
- } #foreach $row_classnum
+
+ } elsif ( $cgi->param('class_agg_break') eq 'breakdown' ) {
+
+ for (my $i = 0; $i < scalar @classnums; $i++) {
+ my $row_classnum = $classnums[$i];
+ my $row_classname = $classnames[$i];
+ foreach my $component ( @components ) {
+
+ push @items, 'cust_bill_pkg';
+
+ push @labels,
+ ( $all_agent || $sel_agent ? '' : $agent->agent.' ' ).
+ ( $all_part_referral || $sel_part_referral ? '' : $part_referral->referral.' ' ).
+ $row_classname . ' ' . $charge_labels{$component};
+
+ my $row_agentnum = $all_agent || $agent->agentnum;
+ my $row_refnum = $all_part_referral || $part_referral->refnum;
+ push @params, [
+ @base_params,
+ $class_param => $row_classnum,
+ ($all_agent ? () : ('agentnum' => $row_agentnum) ),
+ ($all_part_referral ? () : ('refnum' => $row_refnum)),
+ 'charges' => $component,
+ ];
+
+ push @links, "$link;".
+ ($all_agent ? '' : "agentnum=$row_agentnum;").
+ ($all_part_referral ? '' : "refnum=$row_refnum;").
+ (join('',map {"cust_classnum=$_;"} @cust_classnums)).
+ "$class_param=$row_classnum;".
+ "distribute=$distribute;".
+ "use_override=$use_override;charges=$component;";
+
+ @recur_colors = ($col_scheme->colors)[0,4,8,1,5,9]
+ unless @recur_colors;
+ @onetime_colors = ($col_scheme->colors)[2,6,10,3,7,11]
+ unless @onetime_colors;
+ push @colors, shift @recur_colors;
+ push @no_graph, 0;
+
+ } #foreach $component
+ } #foreach $row_classnum
+
+ } #$cgi->param('class_agg_break')
+
} #foreach $part_referral
if ( $cgi->param('agent_totals') and !$all_agent ) {
@@ -254,17 +293,19 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
"distribute=$distribute;".
"charges=$component";
- # Also apply any refnum/classnum filters
- if ( !$all_class and scalar(@classnums) == 1 ) {
- # then a specific class has been chosen, but it may be the empty class
- push @row_params, $class_param => $classnums[0];
- $row_link .= ";$class_param=".$classnums[0];
+ # package class filters
+ if ( $cgi->param('class_agg_break') eq 'aggregate' ) {
+ push @row_params, $class_param => \@classnums;
+ $row_link .= ";$class_param=".$_ foreach @classnums;
}
+
+ # refnum filters
if ( $sel_part_referral ) {
push @row_params, 'refnum' => $sel_part_referral->refnum;
$row_link .= ";refnum=".$sel_part_referral->refnum;
}
+ # customer class filters
$row_link .= ";cust_classnum=$_" foreach @cust_classnums;
push @items, 'cust_bill_pkg';
diff --git a/httemplate/graph/report_cust_bill_pkg.html b/httemplate/graph/report_cust_bill_pkg.html
index d3d8e66..c9e2567 100644
--- a/httemplate/graph/report_cust_bill_pkg.html
+++ b/httemplate/graph/report_cust_bill_pkg.html
@@ -2,7 +2,11 @@
<FORM ACTION="cust_bill_pkg.cgi" METHOD="GET">
-<TABLE>
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+<TR>
+ <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Search options') |h %></FONT></TH>
+</TR>
<% include('/elements/tr-select-from_to.html' ) %>
@@ -17,15 +21,15 @@ function enable_agent_totals(obj) {
obj.form.agent_totals.disabled = !(
obj.form.agentnum.value == '' && (
obj.form.refnum.value == '' ||
- obj.form.classnum.value == 0 ||
+ document.getElementById('class_agg_break_breakdown').checked ||
obj.form.use_setup.value == 1 ||
obj.form.use_usage.value == 1
)
);
}
-function mode_changed() {
- var options = document.getElementsByName('mode');
+function class_mode_changed() {
+ var options = document.getElementsByName('class_mode');
var mode;
for(var i=0; i < options.length; i++) {
if (options[i].checked) {
@@ -43,7 +47,7 @@ function mode_changed() {
div_report.style.display = '';
}
}
-window.onload = mode_changed;
+window.onload = class_mode_changed;
</SCRIPT>
<& /elements/tr-select-agent.html,
@@ -71,38 +75,70 @@ window.onload = mode_changed;
&>
<TR>
- <TD ALIGN="right">
- <INPUT TYPE="radio" NAME="mode" VALUE="pkg" onchange="mode_changed('pkg')" CHECKED>
+
+ <TD>
+ <INPUT TYPE="radio" NAME="class_mode" VALUE="pkg" onchange="class_mode_changed('pkg')" CHECKED>
<% emt('Package class') %>
<BR>
- <INPUT TYPE="radio" NAME="mode" VALUE="report" onchange="mode_changed('report')">
+ <INPUT TYPE="radio" NAME="class_mode" VALUE="report" onchange="class_mode_changed('report')">
<% emt('Report class') %>
</TD>
+
<TD>
- <DIV ID="pkg_class">
- <& /elements/select-pkg_class.html,
- 'field' => 'classnum',
- 'pre_options' => [ 'all' => 'all (aggregate)',
- '' => 'all (breakdown)',
- '0' => '(empty class)' ],
- 'disable_empty' => 1,
- 'onchange' => 'enable_agent_totals',
- &>
- </DIV>
- <DIV ID="report_class" STYLE="display: none">
- <& /elements/select-table.html,
- 'field' => 'report_optionnum',
- 'table' => 'part_pkg_report_option',
- 'name_col' => 'name',
- 'value_col' => 'num',
- 'pre_options' => [ 'all' => 'all (aggregate)',
- '' => 'all (breakdown)',
- '0' => '(empty class)' ],
- 'disable_empty' => 1,
- 'onchange' => 'enable_agent_totals',
- &>
- </DIV>
+ <TABLE>
+ <TR>
+
+ <TD>
+ <DIV ID="pkg_class">
+ <& /elements/select-pkg_class.html,
+ 'field' => 'classnum',
+ 'multiple' => 1,
+ 'all_selected' => 1,
+ 'pre_options' => [ #'all' => 'all (aggregate)',
+ # '' => 'all (breakdown)',
+ '0' => '(empty class)' ],
+ 'disable_empty' => 1,
+ 'onchange' => 'enable_agent_totals',
+ &>
+ </DIV>
+ <DIV ID="report_class" STYLE="display: none">
+ <& /elements/select-table.html,
+ 'field' => 'report_optionnum',
+ 'table' => 'part_pkg_report_option',
+ 'name_col' => 'name',
+ 'value_col' => 'num',
+ 'multiple' => 1,
+ 'all_selected' => 1,
+ 'pre_options' => [ #'all' => 'all (aggregate)',
+ # '' => 'all (breakdown)',
+ '0' => '(empty class)' ],
+ 'disable_empty' => 1,
+ 'onchange' => 'enable_agent_totals',
+ &>
+ </DIV>
+ </TD>
+
+ <TD>
+ <INPUT TYPE="radio" NAME="class_agg_break" ID="class_agg_break_aggregate" VALUE="aggregate" CHECKED>
+ <% emt('Aggregate') %>
+ <BR>
+ <INPUT TYPE="radio" NAME="class_agg_break" VALUE="breakdown">
+ <% emt('Breakdown') %>
+ </TD>
+
+ </TR>
+ </TABLE>
</TD>
+
+</TR>
+
+
+<TR>
+ <TH CLASS="background" COLSPAN=2> </TH>
+</TR>
+
+<TR>
+ <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1"><% mt('Display options') |h %></FONT></TH>
</TR>
<!--
diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi
index f6330e2..77faf2c 100644
--- a/httemplate/search/cust_bill_pkg.cgi
+++ b/httemplate/search/cust_bill_pkg.cgi
@@ -125,8 +125,8 @@ Filtering parameters:
- classnum: Filter on package class.
- report_optionnum: Filter on package report class. Can be a single report
- class number, a comma-separated list, the word "multiple", or an empty
- string (for "no report class").
+ class number or a comma-separated list (where 0 is "no report class"), or the
+ word "multiple".
- use_override: Apply "classnum" and "taxclass" filtering based on the
override (bundle) pkgpart, rather than always using the true pkgpart.
@@ -321,15 +321,22 @@ if ( $cgi->param('nottax') ) {
# not specified: all classes
# 0: empty class
# N: classnum
- if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
- push @where, "COALESCE($part_pkg.classnum, 0) = $1";
+ if ( grep { $_ eq 'classnum' } $cgi->param ) {
+ my @classnums = grep /^\d+$/, $cgi->param('classnum');
+ push @where, "COALESCE($part_pkg.classnum, 0) IN ( ".
+ join(',', @classnums ).
+ ' )'
+ if @classnums;
+ }
+
+ if ( grep { $_ eq 'report_optionnum' } $cgi->param ) {
+ my @nums = grep /^\w+$/, $cgi->param('report_optionnum');
+ my $num = join(',', @nums);
+ push @where, # code reuse FTW
+ FS::Report::Table->with_report_option( $num, $cgi->param('use_override'));
}
if ( $cgi->param('report_optionnum') =~ /^(\w+)$/ ) {
- # code reuse FTW
- my $num = $1;
- push @where,
- FS::Report::Table->with_report_option( $1, $cgi->param('use_override') )
;
}
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Report/Table.pm | 85 +++++++-------
httemplate/elements/select-table.html | 6 +-
httemplate/graph/cust_bill_pkg.cgi | 169 +++++++++++++++++-----------
httemplate/graph/report_cust_bill_pkg.html | 98 +++++++++++-----
httemplate/search/cust_bill_pkg.cgi | 23 +++--
5 files changed, 233 insertions(+), 148 deletions(-)
More information about the freeside-commits
mailing list