Will things ever be the same again?
[freeside.git] / httemplate / browse / part_referral.html
1 <% include("/elements/header.html","Advertising source Listing" ) %>
2
3 Where a customer heard about your service. Tracked for informational purposes.
4 <BR><BR>
5
6 <A HREF="<% $p %>edit/part_referral.html"><I>Add a new advertising source</I></A>
7 <BR><BR>
8 %
9 %  my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
10 %  my %after;
11 %  tie %after, 'Tie::IxHash',
12 %    'Today'         =>        0,
13 %    'Yesterday'     =>    86400, # 60sec * 60min * 24hrs
14 %    'Past week'     =>   518400, # 60sec * 60min * 24hrs * 6days
15 %    'Past 30 days'  =>  2505600, # 60sec * 60min * 24hrs * 29days 
16 %    'Past 60 days'  =>  5097600, # 60sec * 60min * 24hrs * 59days 
17 %    'Past 90 days'  =>  7689600, # 60sec * 60min * 24hrs * 89days 
18 %    'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days 
19 %    'Past year'     => 31486000, # 60sec * 60min * 24hrs * 364days 
20 %    'Total'         => $today,
21 %  ;
22 %  my %before = (
23 %    'Today'         =>   86400, # 60sec * 60min * 24hrs
24 %    'Yesterday'     =>       0,
25 %    'Past week'     =>   86400, # 60sec * 60min * 24hrs
26 %    'Past 30 days'  =>   86400, # 60sec * 60min * 24hrs
27 %    'Past 60 days'  =>   86400, # 60sec * 60min * 24hrs
28 %    'Past 90 days'  =>   86400, # 60sec * 60min * 24hrs
29 %    'Past 6 months' =>   86400, # 60sec * 60min * 24hrs
30 %    'Past year'     =>   86400, # 60sec * 60min * 24hrs
31 %    'Total'         =>   86400, # 60sec * 60min * 24hrs
32 %  );
33 %
34 %  my $curuser = $FS::CurrentUser::CurrentUser;
35 %
36 %  my $statement = "SELECT COUNT(*) FROM h_cust_main
37 %                    WHERE history_action = 'insert'
38 %                      AND refnum = ?
39 %                      AND history_date >= ?
40 %                     AND history_date < ?
41 %                     AND ". $curuser->agentnums_sql;
42 %  my $sth = dbh->prepare($statement)
43 %    or die dbh->errstr;
44 %
45 %  my $show_agentnums = scalar($curuser->agentnums);
46 %
47 %
48
49
50 <% include('/elements/table-grid.html') %>
51 % my $bgcolor1 = '#eeeeee';
52 %   my $bgcolor2 = '#ffffff';
53 %   my $bgcolor = '';
54 %
55
56
57 <TR>
58   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>
59 % if ( $show_agentnums ) { 
60
61     <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
62 % } 
63
64   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Customers</TH>
65 </TR>
66 % for my $period ( keys %after ) { 
67
68   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% $period %></FONT></TH>
69 % } 
70
71 </TR>
72 %
73 %foreach my $part_referral ( FS::part_referral->all_part_referral(1) ) {
74 %
75 %  if ( $bgcolor eq $bgcolor1 ) {
76 %    $bgcolor = $bgcolor2;
77 %  } else {
78 %    $bgcolor = $bgcolor1;
79 %  }
80 %
81 %  $a = 0;
82 %
83 %
84
85       <TR>
86
87         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
88 % if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) { 
89 %            $a++;
90 %          
91
92             <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
93 % } 
94
95           <% $part_referral->refnum %><% $a ? '</A>' : '' %></TD>
96         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
97 % if ( $a ) { 
98
99             <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
100 % } 
101
102           <% $part_referral->referral %><% $a ? '</A>' : '' %></TD>
103 % if ( $show_agentnums ) { 
104
105           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
106 % } 
107 % for my $period ( keys %after ) {
108 %          $sth->execute( $part_referral->refnum,
109 %                         $today-$after{$period},
110 %                         $today+$before{$period},
111 %          ) or die $sth->errstr;
112 %          my $number = $sth->fetchrow_arrayref->[0];
113 %        
114
115           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="right"><% $number %></TD>
116 % } 
117
118       </TR>
119 % } 
120 %
121 %  $statement =~ s/AND refnum = \?//;
122 %  $sth = dbh->prepare($statement)
123 %    or die dbh->errstr;
124 %
125
126       <TR>
127         <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=3><B>Total</B></TD>
128 % for my $period ( keys %after ) {
129 %          $sth->execute( $today-$after{$period},
130 %                         $today+$before{$period},
131 %          ) or die $sth->errstr;
132 %          my $number = $sth->fetchrow_arrayref->[0];
133 %        
134
135           <TD BGCOLOR="#dddddd" ALIGN="right"><B><% $number %><B></TD>
136 % } 
137
138       </TR>
139     </TABLE>
140   </BODY>
141 </HTML>