1 <%= include("/elements/header.html","Advertising source Listing" ) %>
3 Where a customer heard about your service. Tracked for informational purposes.
6 <A HREF="<%= $p %>edit/part_referral.html"><I>Add a new advertising source</I></A>
10 my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
12 tie %after, 'Tie::IxHash',
14 'Yesterday' => 86400, # 60sec * 60min * 24hrs
15 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days
16 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days
17 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days
18 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days
19 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days
20 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days
24 'Today' => 86400, # 60sec * 60min * 24hrs
26 'Past week' => 86400, # 60sec * 60min * 24hrs
27 'Past 30 days' => 86400, # 60sec * 60min * 24hrs
28 'Past 60 days' => 86400, # 60sec * 60min * 24hrs
29 'Past 90 days' => 86400, # 60sec * 60min * 24hrs
30 'Past 6 months' => 86400, # 60sec * 60min * 24hrs
31 'Past year' => 86400, # 60sec * 60min * 24hrs
32 'Total' => 86400, # 60sec * 60min * 24hrs
35 my $curuser = $FS::CurrentUser::CurrentUser;
36 my $extra_sql = $curuser->agentnums_sql;
37 $extra_sql .= ' OR agentnum IS NULL '
38 if $curuser->access_right('Edit global advertising sources');
40 $extra_sql = " WHERE $extra_sql";
42 my $statement = "SELECT COUNT(*) FROM h_cust_main
43 WHERE history_action = 'insert'
47 AND ". $curuser->agentnums_sql;
48 my $sth = dbh->prepare($statement)
51 my $show_agentnums = scalar($curuser->agentnums);
55 <%= include('/elements/table-grid.html') %>
57 <% my $bgcolor1 = '#eeeeee';
58 my $bgcolor2 = '#ffffff';
63 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>
64 <% if ( $show_agentnums ) { %>
65 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
67 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<%= scalar(keys %after) %>>Customers</TH>
69 <% for my $period ( keys %after ) { %>
70 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><%= $period %></FONT></TH>
75 foreach my $part_referral (
78 'table' => 'part_referral',
79 'extra_sql' => "$extra_sql ORDER BY refnum",
84 if ( $bgcolor eq $bgcolor1 ) {
93 <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>">
94 <%= $part_referral->refnum %></A></TD>
95 <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>">
96 <%= $part_referral->referral %></A></TD>
98 <% if ( $show_agentnums ) { %>
99 <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><%= $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
102 <% for my $period ( keys %after ) {
103 $sth->execute( $part_referral->refnum,
104 $today-$after{$period},
105 $today+$before{$period},
106 ) or die $sth->errstr;
107 my $number = $sth->fetchrow_arrayref->[0];
109 <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ALIGN="right"><%= $number %></TD>
115 $statement =~ s/AND refnum = \?//;
116 $sth = dbh->prepare($statement)
120 <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=3><B>Total</B></TD>
121 <% for my $period ( keys %after ) {
122 $sth->execute( $today-$after{$period},
123 $today+$before{$period},
124 ) or die $sth->errstr;
125 my $number = $sth->fetchrow_arrayref->[0];
127 <TD BGCOLOR="#dddddd" ALIGN="right"><B><%= $number %><B></TD>