default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / graph / cust_signup.html
1 <& elements/monthly.html,
2   'title'           => $title,
3   'items'           => \@items,
4   'labels'          => \@labels,
5   'graph_labels'    => \@labels,
6   'params'          => \@params,
7   'colors'          => \@colors,
8   'links'           => \@links,
9   'agentnum'        => $agentnum,
10   'sprintf'         => '%u',
11   'disable_money'   => 1,
12   'bottom_total'    => (scalar @items > 1 && !$indirect ? 1 : 0),
13   'bottom_link'     => $bottom_link,
14   'link_fromparam'  => 'signupdate_begin',
15   'link_toparam'    => 'signupdate_end',
16   'chart_options'   => { precision => 0 },
17 &>
18 <%init>
19
20 #XXX use a different ACL for package churn?
21 die "access denied"
22   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
23
24 #false laziness w/money_time.cgi, cust_bill_pkg.cgi
25 my $title = 'Customer Signup',
26
27 #XXX or virtual
28 my( $agentnum, $agent ) = ('', '');
29 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
30   $agentnum = $1;
31   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
32   die "agentnum $agentnum not found!" unless $agent;
33 }
34
35 my $agentname = $agent ? $agent->agent.' ' : '';
36 $title = "$agentname $title" if $agentname;
37
38 my $link = $p.'search/cust_main.html?';
39 $link .= "agentnum=$agentnum;" if $agentnum;
40
41 my %global_params;
42 # cust_classnum
43 my @classnums = grep /^\d+$/, $cgi->param('cust_classnum');
44 if (@classnums) {
45   $global_params{'cust_classnum'} = [ @classnums ];
46   # classnum here, not cust_classnum, for cust_main.html
47   $link .= "classnum=$_;" foreach @classnums;
48 }
49 # pkg_classnum
50 @classnums = grep /^\d+$/, $cgi->param('pkg_classnum');
51 if (@classnums) {
52   $global_params{'pkg_classnum'} = [ @classnums ];
53   $link .= "pkg_classnum=$_;" foreach @classnums;
54   $link .= 'any_pkg_status=1;';
55   # because we report any customer that had the package at any time, not
56   # only those for whom it's still active
57 }
58
59 my $bottom_link = $link;
60
61 my @referral;
62 my $all_referral = 0;
63 if ( $cgi->param('refnum') eq 'all' ) {
64   @referral = ('');
65   $all_referral = 1;
66 }
67 elsif ( $cgi->param('refnum') =~ /^(\d*)$/ ) {
68   if ( $1 ) {
69     @referral = ( qsearchs('part_referral', { 'refnum' => $1 } ) );
70     die "refnum $1 not found!" unless @referral;
71     $title .= ' - '.$referral[0]->referral;
72     $bottom_link .= ";refnum=$1";
73   }
74   else { #refnum = ''
75     @referral = qsearch('part_referral', {});
76     $title .= ' by Advertising Source';
77   }
78 }
79
80 my $indirect = ($cgi->param('indirect') eq 'Y' ? 1 : 0);
81
82 my (@items, @labels, @colors, @params, @links);
83
84 my $hue = 0;
85 my $hue_increment = 75;
86 my @signup_colors;
87
88 foreach my $referral (@referral) {
89   my %params = %global_params;
90   $params{'refnum'} = $referral->refnum unless $all_referral;
91
92   push @items, 'signups';
93   push @labels, ( $all_referral ? 'Signups' : $referral->referral );
94   push @params, [ %params ];
95   push @links, $link . ($all_referral ? '' : "refnum=".$referral->refnum.';');
96   # rotate hue for each referral type
97   @signup_colors = Color::Scheme->new->from_hue($hue)->colors;
98   $hue += $hue_increment;
99   push @colors, $signup_colors[0];
100   if ( $indirect ) {
101     push @items, 'signups';
102     push @labels, $all_referral ?
103                   'Referrals' : 
104                   $referral->referral . ' referrals';
105     push @params, [ %params, 'indirect' => 1 ];
106     push @links, '';
107     push @colors, $signup_colors[1];
108   }
109 }
110
111 </%init>