summaryrefslogtreecommitdiff
path: root/httemplate/browse/part_referral.html
blob: 27eb5454266f2d5c110a5c124f8187a7bf27dcac (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<& /elements/header.html, "Advertising source Listing" &>

Where a customer heard about your service. Tracked for informational purposes.
<BR><BR>

<A HREF="<% $p %>edit/part_referral.html"><I>Add a new advertising source</I></A>
<BR><BR>

<% $cgi->param('showdisabled')
    ? do { $cgi->param('showdisabled', 0);
           '( <a href="'. $cgi->self_url. '">hide disabled advertising sources</a> )'; }
    : do { $cgi->param('showdisabled', 1);
           '( <a href="'. $cgi->self_url. '">show disabled advertising sources</a> )'; }
%>

% ###
% # Header
% ###

<& /elements/table-grid.html &>
% my $bgcolor1 = '#eeeeee';
%   my $bgcolor2 = '#ffffff';
%   my $bgcolor = '';

<TR>
  <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>

%       if ( ! $cgi->param('showdisabled') ) { 
          <TH CLASS="grid" BGCOLOR="#cccccc" ALIGN="center" ROWSPAN=2></TH>
%       }

% if ( $show_agentnums ) { 
    <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
% } 

  <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Prospects, Customers and Packages</TH>
</TR>
% for my $period ( keys %after ) { 

  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% $period %></FONT></TH>
% } 

</TR>

% ###
% # Rows
% ###

%foreach my $part_referral ( FS::part_referral->all_part_referral(1,!scalar($cgi->param('showdisabled'))) ) {
%
%  if ( $bgcolor eq $bgcolor1 ) {
%    $bgcolor = $bgcolor2;
%  } else {
%    $bgcolor = $bgcolor1;
%  }
%
%  $a = 0;

      <TR>

        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
% if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) { 
%            $a++;
%          

            <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
% } 

          <% $part_referral->refnum %><% $a ? '</A>' : '' %></TD>
        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
% if ( $a ) { 

            <A HREF="<% $p %>edit/part_referral.html?<% $part_referral->refnum %>">
% } 

          <% $part_referral->referral %><% $a ? '</A>' : '' %></TD>

%       if ( ! $cgi->param('showdisabled') ) { 
          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
            <% $part_referral->disabled
                 ? '<FONT COLOR="#FF0000"><B>DISABLED</B></FONT>'
                 : '<FONT COLOR="#00CC00"><B>Active</B></FONT>'
            %>
          </TD>
%       }

% if ( $show_agentnums ) { 

          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
% } 
% for my $period ( keys %after ) {
%          my @param = ( $part_referral->refnum,
%                        $today-$after{$period},
%                        $today+$before{$period},
%                      );
%          $prospect_sth->execute(@param) or die $prospect_sth->errstr;
%          my $num_prospect = $prospect_sth->fetchrow_arrayref->[0];
%          $cust_sth->execute(@param) or die $cust_sth->errstr;
%          my $num_cust = $cust_sth->fetchrow_arrayref->[0];
%          $pkg_sth->execute(@param) or die $pkg_sth->errstr;
%          my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];

          <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ALIGN="right">
            <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
              <TR>
                <TD ALIGN="right"><B><% $num_prospect %></B></TD>
                <TD ALIGN="left">&nbsp;prospects&nbsp;</TD>
              </TR>
              <TR>
                <TD ALIGN="right"><B><% $num_cust %></B></TD>
                <TD ALIGN="left">&nbsp;customers&nbsp;</TD>
              </TR>
              <TR>
                <TD ALIGN="right"><B><% $num_pkg %></B></TD>
                <TD ALIGN="left">&nbsp;packages&nbsp;</TD>
              </TR>
            </TABLE>
          </TD>
% } 

      </TR>
% } 


% ###
% # Bottom Totals
% ###

%  $prospect_statement =~ s/AND refnum = \?//;
%  $prospect_sth = dbh->prepare($prospect_statement)
%    or die dbh->errstr;
%
%  $cust_statement =~ s/AND refnum = \?//;
%  $cust_sth = dbh->prepare($cust_statement)
%    or die dbh->errstr;
%
%  $pkg_statement =~ s/AND h_pkg_referral\.refnum = \?//;
%  $pkg_sth = dbh->prepare($pkg_statement)
%    or die dbh->errstr;

      <TR>
        <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=<% 2 + $show_agentnums + ! $cgi->param('showdisabled') %><B>Total</B></TD>
% for my $period ( keys %after ) {
%          my @param = ( $today-$after{$period},
%                        $today+$before{$period},
%                      );
%          $prospect_sth->execute(@param) or die $prospect_sth->errstr;
%          my $num_prospect = $prospect_sth->fetchrow_arrayref->[0];
%          $cust_sth->execute( @param ) or die $cust_sth->errstr;
%          my $num_cust = $cust_sth->fetchrow_arrayref->[0];
%          $pkg_sth->execute(@param) or die $pkg_sth->errstr;
%          my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];

          <TD CLASS="inv" BGCOLOR="#dddddd" ALIGN="right">
            <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
              <TR>
                <TD ALIGN="right"><B><% $num_prospect %></B></TD>
                <TD ALIGN="left">&nbsp;prospects&nbsp;</TD>
              </TR>
              <TR>
                <TD ALIGN="right"><B><% $num_cust %></B></TD>
                <TD ALIGN="left">&nbsp;customers&nbsp;</TD>
              </TR>
              <TR>
                <TD ALIGN="right"><B><% $num_pkg %></B></TD>
                <TD ALIGN="left">&nbsp;packages&nbsp;</TD>
              </TR>
            </TABLE>
          </TD>

% } 

      </TR>
    </TABLE>

<& /elements/footer.html &>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Edit advertising sources')
      || $FS::CurrentUser::CurrentUser->access_right('Edit global advertising sources');

my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );

tie my %after, 'Tie::IxHash',
  'Today'         =>        0,
  'Yesterday'     =>    86400, # 60sec * 60min * 24hrs
  'Past week'     =>   518400, # 60sec * 60min * 24hrs * 6days
  'Past 30 days'  =>  2505600, # 60sec * 60min * 24hrs * 29days 
  'Past 60 days'  =>  5097600, # 60sec * 60min * 24hrs * 59days 
  'Past 90 days'  =>  7689600, # 60sec * 60min * 24hrs * 89days 
  'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days 
  'Past year'     => 31486000, # 60sec * 60min * 24hrs * 364days 
  'Total'         => $today,
;
my %before = (
  'Today'         =>   86400, # 60sec * 60min * 24hrs
  'Yesterday'     =>       0,
  'Past week'     =>   86400, # 60sec * 60min * 24hrs
  'Past 30 days'  =>   86400, # 60sec * 60min * 24hrs
  'Past 60 days'  =>   86400, # 60sec * 60min * 24hrs
  'Past 90 days'  =>   86400, # 60sec * 60min * 24hrs
  'Past 6 months' =>   86400, # 60sec * 60min * 24hrs
  'Past year'     =>   86400, # 60sec * 60min * 24hrs
  'Total'         =>   86400, # 60sec * 60min * 24hrs
);

my $curuser = $FS::CurrentUser::CurrentUser;

my $show_agentnums = ( scalar($curuser->agentnums) > 1 );

my $prospect_statement = "SELECT COUNT(*) FROM h_prospect_main
                           WHERE history_action = 'insert'
                             AND refnum = ?
                             AND history_date >= ?
                             AND history_date < ?
                             AND ". $curuser->agentnums_sql;
my $prospect_sth = dbh->prepare($prospect_statement)
  or die dbh->errstr;

my $cust_statement = "SELECT COUNT(*) FROM h_cust_main
                       WHERE history_action = 'insert'
                         AND refnum = ?
                         AND history_date >= ?
                         AND history_date < ?
                         AND ". $curuser->agentnums_sql;
my $cust_sth = dbh->prepare($cust_statement)
  or die dbh->errstr;

my $pkg_statement = "SELECT COUNT(*) FROM h_pkg_referral
                       LEFT JOIN cust_pkg  USING ( pkgnum )
                       LEFT JOIN cust_main USING ( custnum )
                       WHERE history_action = 'insert'
                         AND h_pkg_referral.refnum = ?
                         AND history_date >= ?
                         AND history_date < ?
                         AND ". $curuser->agentnums_sql;
my $pkg_sth = dbh->prepare($pkg_statement)
  or die dbh->errstr;

</%init>