1 <& elements/monthly.html,
2 'title' => $agentname. 'Package Churn',
5 'graph_labels' => \@labels,
9 'agentnum' => $agentnum,
10 'sprintf' => ( $normalize ? '%0.1f%%' : '%u'),
11 'sprintf_fields' => $sprintf_fields,
12 'normalize' => ( $normalize ? 0 : undef ),
14 'remove_empty' => (scalar(@group_keys) > 1 ? 1 : 0),
16 'no_graph' => [ 1, 0, 0, 0, 0, 1 ], # don't graph 'active, total_revenue'
20 #XXX use a different ACL for package churn?
21 my $curuser = $FS::CurrentUser::CurrentUser;
23 unless $curuser->access_right('Financial reports');
25 #false laziness w/money_time.cgi, cust_bill_pkg.cgi
28 my( $agentnum, $agent ) = ('', '');
29 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
31 $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
32 die "agentnum $agentnum not found!" unless $agent;
35 my $agentname = $agent ? $agent->agent.' ' : '';
37 my @base_items = qw( active_pkg setup_pkg susp_pkg unsusp_pkg cancel_pkg total_revenue_pkg );
40 'active_pkg' => 'Active packages',
41 'setup_pkg' => 'New orders',
42 'susp_pkg' => 'Suspensions',
43 'unsusp_pkg' => 'Unsuspensions',
44 'cancel_pkg' => 'Cancellations',
45 'total_revenue_pkg' => 'Total Revenue'
49 'active_pkg' => '000000', #black
50 'setup_pkg' => '00cc00', #green
51 'susp_pkg' => 'ff9900', #yellow
52 'unsusp_pkg' => '44ff44', #light green
53 'cancel_pkg' => 'cc0000', #red
54 'total_revenue_pkg' => '0000ff', #blue
57 my $sprintf_fields = {
58 'total_revenue_pkg' => '%.2f', #format to 2 decimal places
62 foreach my $status (qw(active setup cancel susp unsusp)) {
63 $base_links{$status.'_pkg'} =
64 "${p}search/cust_pkg_churn.html?agentnum=$agentnum;status=$status;";
68 # not agentnum, that's elsewhere
69 'refnum' => [ $cgi->param('refnum') ],
70 'classnum' => [ $cgi->param('classnum') ],
71 'towernum' => [ $cgi->param('towernum') ],
73 if ( $cgi->param('zip') =~ /^(\w+)/ ) {
74 $filter_params{zip} = $1;
76 foreach my $link (values %base_links) {
77 foreach my $key (keys(%filter_params)) {
78 my $value = $filter_params{$key};
80 $value = join(',', @$value);
82 $link .= "$key=$value;" if length($value);
87 # In order to keep this from being the same trainwreck as cust_bill_pkg.cgi,
88 # we allow ONE breakdown axis, besides the setup/susp/cancel inherent in
91 my $breakdown = $cgi->param('breakdown_by');
92 my ($name_col, $table);
93 if ($breakdown eq 'classnum') {
95 $name_col = 'classname';
96 } elsif ($breakdown eq 'refnum') {
97 $table = 'part_referral';
98 $name_col = 'referral';
99 } elsif ($breakdown eq 'towernum') {
101 $name_col = 'towername';
102 } elsif ($breakdown) {
103 die "unknown breakdown column '$breakdown'\n";
110 if ( $cgi->param($breakdown) ) {
111 foreach my $key ($cgi->param($breakdown)) {
112 next if $key =~ /\D/;
113 push @groups, qsearch( $table, { $breakdown => $key });
116 @groups = qsearch( $table );
119 push @group_keys, $_->get($breakdown);
120 push @group_labels, $_->get($name_col);
124 my (@items, @labels, @colors, @links, @params);
125 if (scalar(@group_keys) > 1) {
127 foreach my $key (@group_keys) {
128 # this gives a decent level of contrast as long as there aren't too many
130 my $scheme = Color::Scheme->new
134 my $label = shift @group_labels;
135 my $i = 0; # item index
136 foreach (@base_items) {
144 # and a label prefixed with the group label
145 push @labels, "$label - $base_labels{$_}";
147 push @colors, $scheme->colorset->[$i]->[1];
149 my $this_link = $base_links{$_};
150 $this_link .= "$breakdown=$key;";
151 push @links, $this_link;
153 } #foreach (@base_items
155 } # foreach @group_keys
157 @items = @base_items;
158 @labels = @base_labels{@base_items};
159 @colors = @base_colors{@base_items};
160 @links = @base_links{@base_items};
161 @params = map { [ %filter_params ] } @base_items;
164 my $normalize = $cgi->param('normalize');