UI for multiple named taxes w/setup & recur exemptions
[freeside.git] / httemplate / browse / agent.cgi
1 <!-- mason kludge -->
2
3 <%
4
5   #bad false laziness with search/cust_main.cgi (also needs fixing up for
6   #old mysql)
7   my $ncancelled = "
8      0 < ( SELECT COUNT(*) FROM cust_pkg
9                   WHERE cust_pkg.custnum = cust_main.custnum
10                     AND ( cust_pkg.cancel IS NULL
11                           OR cust_pkg.cancel = 0
12                         )
13               )
14        OR 0 = ( SELECT COUNT(*) FROM cust_pkg
15                   WHERE cust_pkg.custnum = cust_main.custnum
16               )
17   ";
18
19   my $ncancelled_sth = dbh->prepare("SELECT COUNT(*) FROM cust_main
20                                        WHERE agentnum = ?
21                                          AND ( $ncancelled )         ")
22     or die dbh->errstr;
23
24   my $total_sth = dbh->prepare("SELECT COUNT(*) FROM cust_main
25                                   WHERE agentnum = ?           ")
26     or die dbh->errstr;
27
28 %>
29
30 <%= header('Agent Listing', menubar(
31   'Main Menu'   => $p,
32   'Agent Types' => $p. 'browse/agent_type.cgi',
33 #  'Add new agent' => '../edit/agent.cgi'
34 )) %>
35 Agents are resellers of your service. Agents may be limited to a subset of your
36 full offerings (via their type).<BR><BR>
37 <A HREF="<%= $p %>edit/agent.cgi"><I>Add a new agent</I></A><BR><BR>
38
39 <%= table() %>
40 <TR>
41   <TH COLSPAN=2>Agent</TH>
42   <TH>Type</TH>
43   <TH>Customers</TH>
44   <TH><FONT SIZE=-1>Freq.</FONT></TH>
45   <TH><FONT SIZE=-1>Prog.</FONT></TH>
46 </TR>
47 <% 
48 #        <TH><FONT SIZE=-1>Agent #</FONT></TH>
49 #        <TH>Agent</TH>
50
51 foreach my $agent ( sort { 
52   #$a->getfield('agentnum') <=> $b->getfield('agentnum')
53   $a->getfield('agent') cmp $b->getfield('agent')
54 } qsearch('agent',{}) ) {
55
56   $ncancelled_sth->execute($agent->agentnum) or die $ncancelled_sth->errstr;
57   my $num_ncancelled = $ncancelled_sth->fetchrow_arrayref->[0];
58
59   $total_sth->execute($agent->agentnum) or die $total_sth->errstr;
60   my $num_total = $total_sth->fetchrow_arrayref->[0];
61
62   my $num_cancelled = $num_total - $num_ncancelled;
63
64 %>
65
66       <TR>
67         <TD><A HREF="<%=$p%>edit/agent.cgi?<%= $agent->agentnum %>">
68           <%= $agent->agentnum %></A></TD>
69         <TD><A HREF="<%=$p%>edit/agent.cgi?<%= $agent->agentnum %>">
70           <%= $agent->agent %></A></TD>
71         <TD><A HREF="<%=$p%>edit/agent_type.cgi?<%= $agent->typenum %>"><%= $agent->agent_type->atype %></A></TD>
72         <TD>
73           <FONT COLOR="#00CC00"><B><%= $num_ncancelled %></B></FONT>
74             active
75           <BR><FONT COLOR="#FF0000"><B><%= $num_cancelled %></B></FONT>
76             cancelled
77         </TD>
78         <TD><%= $agent->freq %></TD>
79         <TD><%= $agent->prog %></TD>
80       </TR>
81
82 <% } %>
83
84     </TABLE>
85   </BODY>
86 </HTML>