8261257f39a5e2e9638ddb2539aa40a48802ad8a
[freeside.git] / httemplate / graph / signupdate.cgi
1 <% include('elements/report.html',
2             'title'       => $agentname . 'Customer signups by time of day',
3             'items'       => [ 'signupdate' ],
4             'data'        => [ \@count ],
5             'row_labels'  => [ 'New customers' ],
6             'colors'      => [ '00cc00' ], #green
7             'col_labels'  => [ map { "$_:00" } @hours ],
8             'links'       => [ \@links ],
9             'graph_type'  => 'Bars',
10             'nototal'     => 0,
11             'sprintf'     => '%u',
12             'disable_money' => 1,
13             ) %>
14 <%init>
15
16 die "access denied"
17   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
18
19 #XXX or virtual
20 my( $agentnum, $agent ) = ('', '');
21 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
22   $agentnum = $1;
23   $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
24   die "agentnum $agentnum not found!" unless $agent;
25 }
26
27 my $agentname = $agent ? $agent->agent.' ' : '';
28 my $usernum = $cgi->param('usernum');
29
30 my @hours = (0..23);
31 my @count = (0) x 24;
32 my %where;
33 $where{'agentnum'} = $agentnum if $agentnum;
34 $where{'usernum'}   = $usernum if $usernum;
35
36 my $sdate = DateTime->new(
37     year       => $cgi->param('start_year'),
38     month      => $cgi->param('start_month'),
39 )->epoch();
40
41 my $edate = DateTime->new(
42     year       => $cgi->param('end_year'),
43     month      => $cgi->param('end_month')
44 )->add( months => 1 )->epoch();
45
46 my $where = (%where ? ' AND ' : ' WHERE ');
47 $where .= " signupdate >= $sdate ".
48           " AND signupdate < $edate ";
49
50 foreach my $cust (qsearch({ table   => 'cust_main',
51                             hashref => \%where,
52                             extra_sql => $where } )) {
53   next if !$cust->signupdate;
54   my $hour = time2str('%H',$cust->signupdate);
55   $count[$hour]++;
56 }
57
58 my @links = ("${p}search/cust_main.html?" . 
59               join (';', map {$_.'='.$where{$_}} (keys(%where))) ).
60               ";signupdate_beginning=$sdate;signupdate_ending=$edate";
61 push @links, map { ";signuphour=$_" } @hours;
62 </%init>