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>
9 <% $cgi->param('showdisabled')
10 ? do { $cgi->param('showdisabled', 0);
11 '( <a href="'. $cgi->self_url. '">hide disabled advertising sources</a> )'; }
12 : do { $cgi->param('showdisabled', 1);
13 '( <a href="'. $cgi->self_url. '">show disabled advertising sources</a> )'; }
16 <% include('/elements/table-grid.html') %>
17 % my $bgcolor1 = '#eeeeee';
18 % my $bgcolor2 = '#ffffff';
22 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>
24 % if ( ! $cgi->param('showdisabled') ) {
25 <TH CLASS="grid" BGCOLOR="#cccccc" ALIGN="center" ROWSPAN=2></TH>
28 % if ( $show_agentnums ) {
29 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
32 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Customers and Packages</TH>
34 % for my $period ( keys %after ) {
36 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% $period %></FONT></TH>
41 %foreach my $part_referral ( FS::part_referral->all_part_referral(1,!scalar($cgi->param('showdisabled'))) ) {
43 % if ( $bgcolor eq $bgcolor1 ) {
44 % $bgcolor = $bgcolor2;
46 % $bgcolor = $bgcolor1;
53 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
54 % if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) {
58 <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
61 <% $part_referral->refnum %><% $a ? '</A>' : '' %></TD>
62 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
65 <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
68 <% $part_referral->referral %><% $a ? '</A>' : '' %></TD>
70 % if ( ! $cgi->param('showdisabled') ) {
71 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
72 <% $part_referral->disabled
73 ? '<FONT COLOR="#FF0000"><B>DISABLED</B></FONT>'
74 : '<FONT COLOR="#00CC00"><B>Active</B></FONT>'
79 % if ( $show_agentnums ) {
81 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
83 % for my $period ( keys %after ) {
84 % my @param = ( $part_referral->refnum,
85 % $today-$after{$period},
86 % $today+$before{$period},
88 % $cust_sth->execute(@param) or die $cust_sth->errstr;
89 % my $num_cust = $cust_sth->fetchrow_arrayref->[0];
90 % $pkg_sth->execute(@param) or die $pkg_sth->errstr;
91 % my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
93 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ALIGN="right">
94 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
96 <TD ALIGN="right"><B><% $num_cust %></B></TD>
97 <TD ALIGN="left"> customers </TD>
100 <TD ALIGN="right"><B><% $num_pkg %></B></TD>
101 <TD ALIGN="left"> packages </TD>
110 % $cust_statement =~ s/AND refnum = \?//;
111 % $cust_sth = dbh->prepare($cust_statement)
112 % or die dbh->errstr;
113 % $pkg_statement =~ s/AND h_pkg_referral\.refnum = \?//;
114 % $pkg_sth = dbh->prepare($pkg_statement)
115 % or die dbh->errstr;
118 <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=<% 2 + $show_agentnums + ! $cgi->param('showdisabled') %><B>Total</B></TD>
119 % for my $period ( keys %after ) {
120 % my @param = ( $today-$after{$period},
121 % $today+$before{$period},
123 % $cust_sth->execute( @param ) or die $cust_sth->errstr;
124 % my $num_cust = $cust_sth->fetchrow_arrayref->[0];
125 % $pkg_sth->execute(@param) or die $pkg_sth->errstr;
126 % my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
128 <TD CLASS="inv" BGCOLOR="#dddddd" ALIGN="right">
129 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
131 <TD ALIGN="right"><B><% $num_cust %></B></TD>
132 <TD ALIGN="left"> customers </TD>
135 <TD ALIGN="right"><B><% $num_pkg %></B></TD>
136 <TD ALIGN="left"> packages </TD>
150 unless $FS::CurrentUser::CurrentUser->access_right('Edit advertising sources')
151 || $FS::CurrentUser::CurrentUser->access_right('Edit global advertising sources');
153 my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
155 tie my %after, 'Tie::IxHash',
157 'Yesterday' => 86400, # 60sec * 60min * 24hrs
158 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days
159 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days
160 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days
161 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days
162 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days
163 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days
167 'Today' => 86400, # 60sec * 60min * 24hrs
169 'Past week' => 86400, # 60sec * 60min * 24hrs
170 'Past 30 days' => 86400, # 60sec * 60min * 24hrs
171 'Past 60 days' => 86400, # 60sec * 60min * 24hrs
172 'Past 90 days' => 86400, # 60sec * 60min * 24hrs
173 'Past 6 months' => 86400, # 60sec * 60min * 24hrs
174 'Past year' => 86400, # 60sec * 60min * 24hrs
175 'Total' => 86400, # 60sec * 60min * 24hrs
178 my $curuser = $FS::CurrentUser::CurrentUser;
180 my $show_agentnums = ( scalar($curuser->agentnums) > 1 );
182 my $cust_statement = "SELECT COUNT(*) FROM h_cust_main
183 WHERE history_action = 'insert'
185 AND history_date >= ?
187 AND ". $curuser->agentnums_sql;
188 my $cust_sth = dbh->prepare($cust_statement)
191 my $pkg_statement = "SELECT COUNT(*) FROM h_pkg_referral
192 LEFT JOIN cust_pkg USING ( pkgnum )
193 LEFT JOIN cust_main USING ( custnum )
194 WHERE history_action = 'insert'
195 AND h_pkg_referral.refnum = ?
196 AND history_date >= ?
198 AND ". $curuser->agentnums_sql;
199 my $pkg_sth = dbh->prepare($pkg_statement)