summaryrefslogtreecommitdiff
path: root/httemplate/graph
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-09-29 16:36:46 -0700
committerMark Wells <mark@freeside.biz>2012-09-29 16:36:46 -0700
commit33beebf4cb42eba3e1dd868ad5e0af102de961da (patch)
tree860712543dcc74ff2402a4ed8d73e8cd553e62d4 /httemplate/graph
parent7ac86daf67b0a95153b736d5811f9050363f6553 (diff)
update address standardization for cust_location changes
Diffstat (limited to 'httemplate/graph')
-rw-r--r--httemplate/graph/cust_bill_pkg.cgi140
-rw-r--r--httemplate/graph/elements/monthly.html38
-rw-r--r--httemplate/graph/elements/report.html31
-rw-r--r--httemplate/graph/money_time.cgi31
-rw-r--r--httemplate/graph/report_cust_bill_pkg.html59
-rw-r--r--httemplate/graph/report_money_time.html7
6 files changed, 224 insertions, 82 deletions
diff --git a/httemplate/graph/cust_bill_pkg.cgi b/httemplate/graph/cust_bill_pkg.cgi
index af4d045fe..c334ae9e7 100644
--- a/httemplate/graph/cust_bill_pkg.cgi
+++ b/httemplate/graph/cust_bill_pkg.cgi
@@ -8,6 +8,7 @@
'graph_labels' => \@labels,
'colors' => \@colors,
'links' => \@links,
+ 'no_graph' => \@no_graph,
'remove_empty' => 1,
'bottom_total' => 1,
'bottom_link' => $bottom_link,
@@ -49,6 +50,21 @@ elsif ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
die "agentnum $agentnum not found!" unless $sel_agent;
}
my $title = $sel_agent ? $sel_agent->agent.' ' : '';
+
+my( $refnum, $sel_part_referral, $all_part_referral ) = ('', '', '');
+if ( $cgi->param('refnum') eq 'all' ) {
+ $refnum = 0;
+ $all_part_referral = 'ALL';
+}
+elsif ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ $refnum = $1;
+ $bottom_link .= "refnum=$refnum;";
+ $sel_part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
+ die "part_referral $refnum not found!" unless $sel_part_referral;
+}
+$title .= $sel_part_referral->referral.' '
+ if $sel_part_referral;
+
$title .= 'Sales Report (Gross)';
$title .= ', average per customer package' if $average_per_cust_pkg;
@@ -103,6 +119,7 @@ my @params = ();
my @labels = ();
my @colors = ();
my @links = ();
+my @no_graph;
my @components = ( 'SRU' );
# split/omit components as appropriate
@@ -119,6 +136,11 @@ elsif ( $use_usage == 2 ) {
$components[-1] =~ s/U//;
}
+# Categorization of line items goes
+# Agent -> Referral -> Package class -> Component (setup/recur/usage)
+# If per-agent totals are enabled, they go under the Agent level.
+# There aren't any other kinds of subtotals.
+
foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' => '' } ) ) {
my $col_scheme = Color::Scheme->new
@@ -130,43 +152,91 @@ foreach my $agent ( $all_agent || $sel_agent || qsearch('agent', { 'disabled' =>
### fixup the color handling for package classes...
### and usage
- my $n = 0;
-
- foreach my $pkg_class ( @pkg_class ) {
- foreach my $component ( @components ) {
-
- push @items, 'cust_bill_pkg';
-
- push @labels,
- ( $all_agent || $sel_agent ? '' : $agent->agent.' ' ).
- ( $classnum eq '0'
- ? ( ref($pkg_class) ? $pkg_class->classname : $pkg_class )
- : ''
- ).
- ' '.$charge_labels{$component};
-
- my $row_classnum = ref($pkg_class) ? $pkg_class->classnum : 0;
- my $row_agentnum = $all_agent || $agent->agentnum;
- push @params, [ ($all_class ? () : ('classnum' => $row_classnum) ),
- ($all_agent ? () : ('agentnum' => $row_agentnum) ),
- '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_class ? '' : "classnum=$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;
+ foreach my $part_referral (
+ $all_part_referral ||
+ $sel_part_referral ||
+ qsearch('part_referral', { 'disabled' => '' } )
+ ) {
+
+ foreach my $pkg_class ( @pkg_class ) {
+ 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.' ' ).
+ ( $classnum eq '0'
+ ? ( ref($pkg_class) ? $pkg_class->classname : $pkg_class )
+ : ''
+ ).
+ ' '.$charge_labels{$component};
+
+ my $row_classnum = ref($pkg_class) ? $pkg_class->classnum : 0;
+ my $row_agentnum = $all_agent || $agent->agentnum;
+ my $row_refnum = $all_part_referral || $part_referral->refnum;
+ push @params, [ ($all_class ? () : ('classnum' => $row_classnum) ),
+ ($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;").
+ ($all_class ? '' : "classnum=$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 $pkg_class
+ } #foreach $part_referral
+
+ if ( $cgi->param('agent_totals') and !$all_agent ) {
+ my $row_agentnum = $agent->agentnum;
+ # Include all components that are anywhere on this report
+ my $component = join('', @components);
+
+ my @row_params = ( 'agentnum' => $row_agentnum,
+ 'use_override' => $use_override,
+ 'average_per_cust_pkg' => $average_per_cust_pkg,
+ 'distribute' => $distribute,
+ 'charges' => $component,
+ );
+ my $row_link = "$link;".
+ "agentnum=$row_agentnum;".
+ "distribute=$distribute;".
+ "charges=$component";
+
+ # Also apply any refnum/classnum filters
+ if ( !$all_class and scalar(@pkg_class) == 1 ) {
+ # then a specific class has been chosen, but it may be the empty class
+ my $row_classnum = ref($pkg_class[0]) ? $pkg_class[0]->classnum : 0;
+ push @row_params, 'classnum' => $row_classnum;
+ $row_link .= ";classnum=$row_classnum";
}
+ if ( $sel_part_referral ) {
+ push @row_params, 'refnum' => $sel_part_referral->refnum;
+ $row_link .= ";refnum=".$sel_part_referral->refnum;
+ }
+
+ push @items, 'cust_bill_pkg';
+ push @labels, mt('[_1] - Subtotal', $agent->agent);
+ push @params, \@row_params;
+ push @links, $row_link;
+ push @colors, '000000'; # better idea?
+ push @no_graph, 1;
}
$hue += $hue_increment;
diff --git a/httemplate/graph/elements/monthly.html b/httemplate/graph/elements/monthly.html
index 86530dd39..c736de696 100644
--- a/httemplate/graph/elements/monthly.html
+++ b/httemplate/graph/elements/monthly.html
@@ -20,6 +20,7 @@ Example:
'link_fromparam' => 'param_from', #defaults to 'begin'
'link_toparam' => 'param_to', #defaults to 'end'
'daily' => 1, # omit for monthly granularity
+ 'no_graph' => \@no_graph, # items to leave off the graph (subtotals)
#optional, pulled from CGI params if not specified
'start_month' => $smonth,
@@ -35,6 +36,7 @@ Example:
#optional
'agentnum' => $agentnum,
+ 'refnum' => $refnum,
'nototal' => 1,
'graph_type' => 'LinesPoints',
'remove_empty' => 1,
@@ -48,18 +50,19 @@ Example:
'items' => $data->{'items'},
'data' => $data->{'data'},
'row_labels' => $data->{'item_labels'},
- 'graph_labels' => $opt{'graph_labels'} || $data->{'item_labels'},
+ 'graph_labels' => \@graph_labels,
'col_labels' => $col_labels,
'axis_labels' => $data->{label},
- 'colors' => $data->{colors},
+ 'colors' => \@colors,
'links' => \@links,
+ 'no_graph' => \@no_graph,
'bottom_link' => \@bottom_link,
'transpose' => $opt{'daily'},
- map { $_, $opt{$_} } (qw(title
- nototal
- graph_type
- bottom_total
- sprintf
+ map { $_, $opt{$_} } (qw(title
+ nototal
+ graph_type
+ bottom_total
+ sprintf
disable_money
chart_options)),
) %>
@@ -102,7 +105,7 @@ if ( $opt{'daily'} ) { # daily granularity
my %reportopts = (
'items' => \@items,
'params' => $opt{'params'},
- 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
+ 'item_labels' => ( $cgi->param('_type') =~ /^(png)$/
? $opt{'graph_labels'}
: $opt{'labels'}
),
@@ -117,6 +120,7 @@ my %reportopts = (
'end_year' => $opt{'end_year'},
'projection' => $opt{'projection'},
'agentnum' => $opt{'agentnum'},
+ 'refnum' => $opt{'refnum'},
'remove_empty' => $opt{'remove_empty'},
'doublemonths' => $opt{'doublemonths'},
);
@@ -138,12 +142,20 @@ my $col_labels = [ map { my $m = $_; $m =~ s/^(\d+)\//$mon[$1-1] / ; $m }
@{$data->{label}} ];
$col_labels = $data->{label} if $opt{'daily'};
+my @colors;
+my @graph_labels;
+my @no_graph;
if ( $opt{'remove_empty'} ) {
- # need to filter out series labels for collapsed rows
- $opt{'graph_labels'} = [
- map { $opt{'graph_labels'}[$_] }
- @{ $data->{indices} }
- ];
+ # then filter out per-item things for collapsed rows
+ foreach my $i (@{ $data->{'indices'} }) {
+ push @colors, $opt{'colors'}[$i];
+ push @graph_labels, $opt{'graph_labels'}[$i];
+ push @no_graph, $opt{'no_graph'}[$i];
+ }
+} else {
+ @colors = @{ $opt{'colors'} };
+ @graph_labels = @{ $opt{'graph_labels'} };
+ @no_graph = @{ $opt{'no_graph'} || [] };
}
my @links;
diff --git a/httemplate/graph/elements/report.html b/httemplate/graph/elements/report.html
index 3600f2c66..98b477826 100644
--- a/httemplate/graph/elements/report.html
+++ b/httemplate/graph/elements/report.html
@@ -14,6 +14,7 @@ Example:
'graph_labels' => \@graph_labels, #defaults to row_labels
'links' => \@links, #optional
+ 'no_graph' => \@no_graph, #optional
#these run parallel to the elements of each @item
'col_labels' => \@col_labels, #required
@@ -77,15 +78,16 @@ any delimiter and linked from the elements in @data.
% }
%
% } elsif ( $cgi->param('_type') =~ /(xls)$/ ) {
-%
-% #http_header('Content-Type' => 'application/excel' ); #eww
-% http_header('Content-Type' => 'application/vnd.ms-excel' );
-% #http_header('Content-Type' => 'application/msexcel' ); #alas
-% http_header('Content-Disposition' => "attachment;filename=$filename.xls");
+% #false laziness w/ search/elements/search-xls
+% my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format;
+% $filename .= $format->{extension};
+%
+% http_header('Content-Type' => $format->{mime_type} );
+% http_header('Content-Disposition' => qq!attachment;filename="$filename"! );
%
% my $output = '';
% my $XLS = new IO::Scalar \$output;
-% my $workbook = Spreadsheet::WriteExcel->new($XLS)
+% my $workbook = $format->{class}->new($XLS)
% or die "Error opening .xls file: $!";
%
% my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
@@ -127,7 +129,19 @@ any delimiter and linked from the elements in @data.
%
<% $output %>
% } elsif ( $cgi->param('_type') eq 'png' ) {
-%
+% # delete any items that shouldn't be on the graph
+% if ( my $no_graph = $opt{'no_graph'} ) {
+% my $i = 0;
+% while (@$no_graph) {
+% if ( shift @$no_graph ) {
+% splice @data, $i, 1;
+% splice @{$opt{'graph_labels'}}, $i, 1;
+% splice @{$opt{'colors'}}, $i, 1;
+% $i--; # because everything is shifted down
+% }
+% $i++;
+% }
+% }
% my $graph_type = 'LinesPoints';
% if ( $opt{'graph_type'} =~ /^(LinesPoints|Mountain|Bars)$/ ) {
% $graph_type = $1;
@@ -304,9 +318,6 @@ td.cell {
<% include('/elements/footer.html') %>
% }
-<%once>
-
-</%once>
<%init>
my(%opt) = @_;
diff --git a/httemplate/graph/money_time.cgi b/httemplate/graph/money_time.cgi
index cde71be76..166735fc6 100644
--- a/httemplate/graph/money_time.cgi
+++ b/httemplate/graph/money_time.cgi
@@ -1,5 +1,5 @@
<% include('elements/monthly.html',
- 'title' => $agentname.
+ 'title' => $agentname. $referralname.
'Sales, Credits and Receipts Summary',
'items' => \@items,
'labels' => \%label,
@@ -7,6 +7,7 @@
'colors' => \%color,
'links' => \%link,
'agentnum' => $agentnum,
+ 'refnum' => $refnum,
'nototal' => scalar($cgi->param('12mo')),
)
%>
@@ -22,9 +23,17 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
$agent = qsearchs('agent', { 'agentnum' => $agentnum } );
die "agentnum $agentnum not found!" unless $agent;
}
-
my $agentname = $agent ? $agent->agent.' ' : '';
+my( $refnum, $part_referral ) = ('', '');
+if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
+ $refnum = $1;
+ $part_referral = qsearchs('part_referral', { 'refnum' => $refnum } );
+ die "refnum $refnum not found!" unless $part_referral;
+}
+my $referralname = $part_referral ? $part_referral->referral.' ' : '';
+
+
my @items = qw( invoiced netsales
credits netcredits
payments receipts
@@ -83,15 +92,17 @@ my %color = (
$color{$_.'_12mo'} = $color{$_}
foreach keys %color;
+my $ar = "agentnum=$agentnum;refnum=$refnum";
+
my %link = (
- 'invoiced' => "${p}search/cust_bill.html?agentnum=$agentnum;",
- 'netsales' => "${p}search/cust_bill.html?agentnum=$agentnum;net=1;",
- 'credits' => "${p}search/cust_credit.html?agentnum=$agentnum;",
- 'netcredits' => "${p}search/cust_credit_bill.html?agentnum=$agentnum;",
- 'payments' => "${p}search/cust_pay.html?magic=_date;agentnum=$agentnum;",
- 'receipts' => "${p}search/cust_bill_pay.html?agentnum=$agentnum;",
- 'refunds' => "${p}search/cust_refund.html?magic=_date;agentnum=$agentnum;",
- 'netrefunds' => "${p}search/cust_credit_refund.html?agentnum=$agentnum;",
+ 'invoiced' => "${p}search/cust_bill.html?$ar;",
+ 'netsales' => "${p}search/cust_bill.html?$ar;net=1;",
+ 'credits' => "${p}search/cust_credit.html?$ar;",
+ 'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
+ 'payments' => "${p}search/cust_pay.html?magic=_date;$ar;",
+ 'receipts' => "${p}search/cust_bill_pay.html?$ar;",
+ 'refunds' => "${p}search/cust_refund.html?magic=_date;$ar;",
+ 'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
);
# XXX link 12mo?
diff --git a/httemplate/graph/report_cust_bill_pkg.html b/httemplate/graph/report_cust_bill_pkg.html
index 07d4421e8..31792e8dd 100644
--- a/httemplate/graph/report_cust_bill_pkg.html
+++ b/httemplate/graph/report_cust_bill_pkg.html
@@ -11,20 +11,45 @@
<TD>Show projected data for future months</TD>
</TR>
-<% include('/elements/tr-select-agent.html',
- 'label' => 'For agent: ',
- 'disable_empty' => 0,
- 'pre_options' => [ 'all' => 'all (aggregate)' ],
- 'empty_label' => 'all (breakdown)',
- )
-%>
-
-<% include('/elements/tr-select-pkg_class.html',
- 'pre_options' => [ 'all' => 'all (aggregate)',
- '0' => 'all (breakdown)' ],
- 'empty_label' => '(empty class)',
- )
-%>
+<SCRIPT TYPE="text/javascript">
+function enable_agent_totals(obj) {
+%# enable it iff we are breaking down by agent AND something else
+ obj.form.agent_totals.disabled = !(
+ obj.form.agentnum.value == '' && (
+ obj.form.refnum.value == '' ||
+ obj.form.classnum.value == 0 ||
+ obj.form.use_setup.value == 1 ||
+ obj.form.use_usage.value == 1
+ )
+ );
+}
+</SCRIPT>
+
+<& /elements/tr-select-agent.html,
+ 'field' => 'agentnum',
+ 'label' => 'Agent ',
+ 'disable_empty' => 0,
+ 'pre_options' => [ 'all' => 'all (aggregate)' ],
+ 'empty_label' => 'all (breakdown)',
+ 'onchange' => 'enable_agent_totals',
+&>
+
+<& /elements/tr-select-part_referral.html,
+ 'field' => 'refnum',
+ 'label' => 'Advertising source ',
+ 'disable_empty' => 0,
+ 'pre_options' => [ 'all' => 'all (aggregate)' ],
+ 'empty_label' => 'all (breakdown)',
+ 'onchange' => 'enable_agent_totals'
+&>
+
+<& /elements/tr-select-pkg_class.html,
+ 'field' => 'classnum',
+ 'pre_options' => [ 'all' => 'all (aggregate)',
+ '0' => 'all (breakdown)' ],
+ 'empty_label' => '(empty class)',
+ 'onchange' => 'enable_agent_totals',
+&>
<!--
<TR>
@@ -39,10 +64,16 @@
'field' => 'use_'.lc($_),
'options' => [ 0, 1, 2 ],
'labels' => { 0 => 'Combine', 1 => 'Separate', 2 => 'Do not show' },
+ 'onchange'=> 'enable_agent_totals',
&>
% }
<TR>
+ <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="agent_totals" VALUE="1" DISABLED="1"></TD>
+ <TD>Show per-agent subtotals</TD>
+</TR>
+
+<TR>
<TD ALIGN="right"><INPUT TYPE="checkbox" NAME="use_override" VALUE="1"></TD>
<TD>Separate sub-packages from parents</TD>
</TR>
diff --git a/httemplate/graph/report_money_time.html b/httemplate/graph/report_money_time.html
index b85bb6552..97876c996 100644
--- a/httemplate/graph/report_money_time.html
+++ b/httemplate/graph/report_money_time.html
@@ -24,6 +24,13 @@
)
%>
+<% include('/elements/tr-select-part_referral.html',
+ 'label' => 'Advertising source ',
+ 'disable_empty' => 0,
+ 'empty_label' => 'all',
+ )
+%>
+
<TR>
<TD ALIGN="right"><INPUT TYPE="checkbox" NAME="12mo" VALUE="1"></TD>
<TD>Show 12 month totals instead of monthly values</TD>