summaryrefslogtreecommitdiff
path: root/httemplate/graph/signupdate.cgi
blob: 823ddb89f27b4e2aefea752538ffd71529b45bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<% include('elements/report.html',
            'title'       => $agentname . 'Customer signups by time of day',
            'items'       => [ 'signupdate' ],
            'data'        => [ \@count ],
            'row_labels'  => [ 'New customers' ],
            'colors'      => [ '00cc00' ], #green
            'col_labels'  => [ map { "$_:00" } @hours ],
            'links'       => [ \@links ],
            'graph_type'  => 'Bars',
            'nototal'     => 0,
            'sprintf'     => '%u',
            'disable_money' => 1,
            ) %>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');

#XXX or virtual
my( $agentnum, $agent ) = ('', '');
if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
  $agentnum = $1;
  $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
  die "agentnum $agentnum not found!" unless $agent;
}

my $agentname = $agent ? $agent->agent.' ' : '';
my $usernum = $cgi->param('usernum');

my @hours = (0..23);
my @count = (0) x 24;
my %where;
$where{'agentnum'} = $agentnum if $agentnum;
$where{'usernum'}   = $usernum if $usernum;

my $sdate = DateTime->new(
    year       => scalar($cgi->param('start_year')),
    month      => scalar($cgi->param('start_month')),
)->epoch();

my $edate = DateTime->new(
    year       => scalar($cgi->param('end_year')),
    month      => scalar($cgi->param('end_month')),
)->add( months => 1 )->epoch();

my $where = (%where ? ' AND ' : ' WHERE ');
$where .= " signupdate >= $sdate ".
          " AND signupdate < $edate ";

foreach my $cust (qsearch({ table   => 'cust_main',
                            hashref => \%where,
                            extra_sql => $where } )) {
  next if !$cust->signupdate;
  my $hour = time2str('%H',$cust->signupdate);
  $count[$hour]++;
}

my @links = ("${p}search/cust_main.html?" . 
              join (';', map {$_.'='.$where{$_}} (keys(%where))) ).
              ";signupdate_beginning=$sdate;signupdate_ending=$edate";
push @links, map { ";signuphour=$_" } @hours;
</%init>