1 <& /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> )'; }
20 <& /elements/table-grid.html &>
21 % my $bgcolor1 = '#eeeeee';
22 % my $bgcolor2 = '#ffffff';
26 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>
28 % if ( ! $cgi->param('showdisabled') ) {
29 <TH CLASS="grid" BGCOLOR="#cccccc" ALIGN="center" ROWSPAN=2></TH>
32 % if ( $show_agentnums ) {
33 <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
36 <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Prospects, Customers and Packages</TH>
38 % for my $period ( keys %after ) {
40 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% $period %></FONT></TH>
49 %foreach my $part_referral ( FS::part_referral->all_part_referral(1,!scalar($cgi->param('showdisabled'))) ) {
51 % if ( $bgcolor eq $bgcolor1 ) {
52 % $bgcolor = $bgcolor2;
54 % $bgcolor = $bgcolor1;
61 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
62 % if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) {
66 <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
69 <% $part_referral->refnum %><% $a ? '</A>' : '' %></TD>
70 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
73 <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
76 <% $part_referral->referral %><% $a ? '</A>' : '' %></TD>
78 % if ( ! $cgi->param('showdisabled') ) {
79 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
80 <% $part_referral->disabled
81 ? '<FONT COLOR="#FF0000"><B>DISABLED</B></FONT>'
82 : '<FONT COLOR="#00CC00"><B>Active</B></FONT>'
87 % if ( $show_agentnums ) {
89 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
91 % for my $period ( keys %after ) {
92 % my @param = ( $part_referral->refnum,
93 % $today-$after{$period},
94 % $today+$before{$period},
96 % $prospect_sth->execute(@param) or die $prospect_sth->errstr;
97 % my $num_prospect = $prospect_sth->fetchrow_arrayref->[0];
98 % $cust_sth->execute(@param) or die $cust_sth->errstr;
99 % my $num_cust = $cust_sth->fetchrow_arrayref->[0];
100 % $pkg_sth->execute(@param) or die $pkg_sth->errstr;
101 % my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
103 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ALIGN="right">
104 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
106 <TD ALIGN="right"><B><% $num_prospect %></B></TD>
107 <TD ALIGN="left"> prospects </TD>
110 <TD ALIGN="right"><B><% $num_cust %></B></TD>
111 <TD ALIGN="left"> customers </TD>
114 <TD ALIGN="right"><B><% $num_pkg %></B></TD>
115 <TD ALIGN="left"> packages </TD>
129 % $prospect_statement =~ s/AND refnum = \?//;
130 % $prospect_sth = dbh->prepare($prospect_statement)
131 % or die dbh->errstr;
133 % $cust_statement =~ s/AND refnum = \?//;
134 % $cust_sth = dbh->prepare($cust_statement)
135 % or die dbh->errstr;
137 % $pkg_statement =~ s/AND h_pkg_referral\.refnum = \?//;
138 % $pkg_sth = dbh->prepare($pkg_statement)
139 % or die dbh->errstr;
142 <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=<% 2 + $show_agentnums + ! $cgi->param('showdisabled') %><B>Total</B></TD>
143 % for my $period ( keys %after ) {
144 % my @param = ( $today-$after{$period},
145 % $today+$before{$period},
147 % $prospect_sth->execute(@param) or die $prospect_sth->errstr;
148 % my $num_prospect = $prospect_sth->fetchrow_arrayref->[0];
149 % $cust_sth->execute( @param ) or die $cust_sth->errstr;
150 % my $num_cust = $cust_sth->fetchrow_arrayref->[0];
151 % $pkg_sth->execute(@param) or die $pkg_sth->errstr;
152 % my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
154 <TD CLASS="inv" BGCOLOR="#dddddd" ALIGN="right">
155 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
157 <TD ALIGN="right"><B><% $num_prospect %></B></TD>
158 <TD ALIGN="left"> prospects </TD>
161 <TD ALIGN="right"><B><% $num_cust %></B></TD>
162 <TD ALIGN="left"> customers </TD>
165 <TD ALIGN="right"><B><% $num_pkg %></B></TD>
166 <TD ALIGN="left"> packages </TD>
176 <& /elements/footer.html &>
180 unless $FS::CurrentUser::CurrentUser->access_right('Edit advertising sources')
181 || $FS::CurrentUser::CurrentUser->access_right('Edit global advertising sources');
183 my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
185 tie my %after, 'Tie::IxHash',
187 'Yesterday' => 86400, # 60sec * 60min * 24hrs
188 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days
189 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days
190 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days
191 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days
192 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days
193 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days
197 'Today' => 86400, # 60sec * 60min * 24hrs
199 'Past week' => 86400, # 60sec * 60min * 24hrs
200 'Past 30 days' => 86400, # 60sec * 60min * 24hrs
201 'Past 60 days' => 86400, # 60sec * 60min * 24hrs
202 'Past 90 days' => 86400, # 60sec * 60min * 24hrs
203 'Past 6 months' => 86400, # 60sec * 60min * 24hrs
204 'Past year' => 86400, # 60sec * 60min * 24hrs
205 'Total' => 86400, # 60sec * 60min * 24hrs
208 my $curuser = $FS::CurrentUser::CurrentUser;
210 my $show_agentnums = ( scalar($curuser->agentnums) > 1 );
212 my $prospect_statement = "SELECT COUNT(*) FROM h_prospect_main
213 WHERE history_action = 'insert'
215 AND history_date >= ?
217 AND ". $curuser->agentnums_sql;
218 my $prospect_sth = dbh->prepare($prospect_statement)
221 my $cust_statement = "SELECT COUNT(*) FROM h_cust_main
222 WHERE history_action = 'insert'
224 AND history_date >= ?
226 AND ". $curuser->agentnums_sql;
227 my $cust_sth = dbh->prepare($cust_statement)
230 my $pkg_statement = "SELECT COUNT(*) FROM h_pkg_referral
231 LEFT JOIN cust_pkg USING ( pkgnum )
232 LEFT JOIN cust_main USING ( custnum )
233 WHERE history_action = 'insert'
234 AND h_pkg_referral.refnum = ?
235 AND history_date >= ?
237 AND ". $curuser->agentnums_sql;
238 my $pkg_sth = dbh->prepare($pkg_statement)