cleanup
[freeside.git] / httemplate / browse / agent.cgi
1 <% include("/elements/header.html",'Agent Listing', menubar(
2   'Agent Types' => $p. 'browse/agent_type.cgi',
3 #  'Add new agent' => '../edit/agent.cgi'
4 )) %>
5 Agents are resellers of your service. Agents may be limited to a subset of your
6 full offerings (via their type).<BR><BR>
7 <A HREF="<% $p %>edit/agent.cgi"><I>Add a new agent</I></A><BR><BR>
8 % if ( dbdef->table('agent')->column('disabled') ) { 
9
10   <% $cgi->param('showdisabled')
11       ? do { $cgi->param('showdisabled', 0);
12              '( <a href="'. $cgi->self_url. '">hide disabled agents</a> )'; }
13       : do { $cgi->param('showdisabled', 1);
14              '( <a href="'. $cgi->self_url. '">show disabled agents</a> )'; }
15   %>
16 % } 
17
18
19 <% include('/elements/table-grid.html') %>
20 % my $bgcolor1 = '#eeeeee';
21 %   my $bgcolor2 = '#ffffff';
22 %   my $bgcolor = '';
23
24 <TR>
25   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% ( $cgi->param('showdisabled') || !dbdef->table('agent')->column('disabled') ) ? 2 : 3 %>>Agent</TH>
26   <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>
27   <TH CLASS="grid" BGCOLOR="#cccccc">Master Customer</TH>
28   <TH CLASS="grid" BGCOLOR="#cccccc">Access Groups</TH>
29   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice<BR>Template</FONT></TH>
30   <TH CLASS="grid" BGCOLOR="#cccccc">Customers</TH>
31   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Customer<BR>packages</FONT></TH>
32   <TH CLASS="grid" BGCOLOR="#cccccc">Reports</TH>
33   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Registration<BR>codes</FONT></TH>
34   <TH CLASS="grid" BGCOLOR="#cccccc">Prepaid cards</TH>
35
36 % if ( $conf->config('ticket_system') ) { 
37     <TH CLASS="grid" BGCOLOR="#cccccc">Ticketing</TH>
38 % } 
39
40   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment Gateway Overrides</FONT></TH>
41   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Configuration Overrides</FONT></TH>
42 </TR>
43
44 %#        <TH><FONT SIZE=-1>Agent #</FONT></TH>
45 %#        <TH>Agent</TH>
46 %foreach my $agent ( sort { 
47 %  #$a->getfield('agentnum') <=> $b->getfield('agentnum')
48 %  $a->getfield('agent') cmp $b->getfield('agent')
49 %} qsearch('agent', \%search ) ) {
50 %
51 %  my $cust_main_link = $p. 'search/cust_main.cgi?agentnum_on=1&'.
52 %                       'agentnum='. $agent->agentnum;
53 %
54 %  my $cust_pkg_link = $p. 'search/cust_pkg.cgi?agentnum='. $agent->agentnum;
55 %  
56 %  if ( $bgcolor eq $bgcolor1 ) {
57 %    $bgcolor = $bgcolor2;
58 %  } else {
59 %    $bgcolor = $bgcolor1;
60 %  }
61
62       <TR>
63
64         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
65           <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agentnum %></A>
66         </TD>
67
68 %       if ( dbdef->table('agent')->column('disabled')
69 %            && !$cgi->param('showdisabled')           ) { 
70           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
71             <% $agent->disabled ? 'DISABLED' : '' %>
72           </TD>
73 %       } 
74
75         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
76           <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agent %></A>
77         </TD>
78
79         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
80           <A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A>
81         </TD>
82
83         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
84 %         if ( $agent->agent_custnum ) {
85             <% include('/elements/small_custview.html',
86                          $agent->agent_custnum,
87                          scalar($conf->config('countrydefault')),
88                          1, #show balance
89                       )
90             %>
91 %         }
92         </TD>
93
94         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
95 %         foreach my $access_group (
96 %           map $_->access_group,
97 %               qsearch('access_groupagent', { 'agentnum' => $agent->agentnum })
98 %         ) {
99             <A HREF="<%$p%>edit/access_group.html?<% $access_group->groupnum %>"><% $access_group->groupname |h %><BR>
100 %         }
101         </TD>
102
103         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
104           <% $agent->invoice_template || '(Default)' %>
105         </TD>
106
107         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
108           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
109
110             <TR>
111               <TH ALIGN="right" WIDTH="40%">
112                 <FONT COLOR="#7e0079">
113                   <% my $num_prospect = $agent->num_prospect_cust_main %>&nbsp;
114                 </FONT>
115               </TH>
116
117               <TD>
118 % if ( $num_prospect ) { 
119
120                   <A HREF="<% $cust_main_link %>&prospect=1">
121 % } 
122 prospects
123 % if ($num_prospect ) { 
124 </A>
125 % } 
126
127               <TD>
128             </TR>
129
130             <TR>
131               <TH ALIGN="right" WIDTH="40%">
132                 <FONT COLOR="#0000CC">
133                   <% my $num_inactive = $agent->num_inactive_cust_main %>&nbsp;
134                 </FONT>
135               </TH>
136
137               <TD>
138 % if ( $num_inactive ) { 
139
140                   <A HREF="<% $cust_main_link %>&inactive=1">
141 % } 
142 inactive
143 % if ( $num_inactive ) { 
144 </A>
145 % } 
146
147               </TD>
148             </TR>
149
150             <TR>
151               <TH ALIGN="right" WIDTH="40%">
152                 <FONT COLOR="#00CC00">
153                   <% my $num_active = $agent->num_active_cust_main %>&nbsp;
154                 </FONT>
155               </TH>
156
157               <TD>
158 % if ( $num_active ) { 
159
160                   <A HREF="<% $cust_main_link %>&active=1">
161 % } 
162 active
163 % if ( $num_active ) { 
164 </A>
165 % } 
166
167               </TD>
168             </TR>
169
170             <TR>
171               <TH ALIGN="right" WIDTH="40%">
172                 <FONT COLOR="#FF9900">
173                   <% my $num_susp = $agent->num_susp_cust_main %>&nbsp;
174                 </FONT>
175               </TH>
176
177               <TD>
178 % if ( $num_susp ) { 
179
180                   <A HREF="<% $cust_main_link %>&suspended=1">
181 % } 
182 suspended
183 % if ( $num_susp ) { 
184 </A>
185 % } 
186
187               </TD>
188             </TR>
189
190             <TR>
191               <TH ALIGN="right" WIDTH="40%">
192                 <FONT COLOR="#FF0000">
193                   <% my $num_cancel = $agent->num_cancel_cust_main %>&nbsp;
194                 </FONT>
195               </TH>
196
197               <TD>
198 % if ( $num_cancel ) { 
199
200                   <A HREF="<% $cust_main_link %>&showcancelledcustomers=1&cancelled=1">
201 % } 
202 cancelled
203 % if ( $num_cancel ) { 
204 </A>
205 % } 
206
207               </TD>
208             </TR>
209
210           </TABLE>
211         </TD>
212
213         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
214           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
215
216             <TR>
217               <TH ALIGN="right" WIDTH="40%">
218                 <FONT COLOR="#0000CC">
219                   <% my $num_inactive_pkg = $agent->num_inactive_cust_pkg %>&nbsp;
220                 </FONT>
221               </TH>
222
223               <TD>
224 % if ( $num_inactive_pkg ) { 
225
226                   <A HREF="<% $cust_pkg_link %>&magic=inactive">
227 % } 
228 inactive
229 % if ( $num_inactive_pkg ) { 
230 </A>
231 % } 
232
233               </TD>
234             </TR>
235
236             <TR>
237               <TH ALIGN="right" WIDTH="40%">
238                 <FONT COLOR="#00CC00">
239                   <% my $num_active_pkg = $agent->num_active_cust_pkg %>&nbsp;
240                 </FONT>
241               </TH>
242
243               <TD>
244 % if ( $num_active_pkg ) { 
245
246                   <A HREF="<% $cust_pkg_link %>&magic=active">
247 % } 
248 active
249 % if ( $num_active_pkg ) { 
250 </A>
251 % } 
252
253               </TD>
254             </TR>
255
256             <TR>
257               <TH ALIGN="right" WIDTH="40%">
258                 <FONT COLOR="#FF9900">
259                   <% my $num_susp_pkg = $agent->num_susp_cust_pkg %>&nbsp;
260                 </FONT>
261
262               </TH>
263               <TD>
264 % if ( $num_susp_pkg ) { 
265
266                   <A HREF="<% $cust_pkg_link %>&magic=suspended">
267 % } 
268 suspended
269 % if ( $num_susp_pkg ) { 
270 </A>
271 % } 
272
273               </TD>
274             </TR>
275             
276             <TR>
277               <TH ALIGN="right" WIDTH="40%">
278                 <FONT COLOR="#FF0000">
279                   <% my $num_cancel_pkg = $agent->num_cancel_cust_pkg %>&nbsp;
280                 </FONT>
281               </TH>
282
283               <TD>
284 % if ( $num_cancel_pkg ) { 
285
286                   <A HREF="<% $cust_pkg_link %>&magic=cancelled">
287 % } 
288 cancelled
289 % if ( $num_cancel_pkg ) { 
290 </A>
291 % } 
292
293               </TD>
294             </TR>
295
296           </TABLE>
297         </TD>
298
299         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
300           <A HREF="<% $p %>graph/report_cust_pkg.html?agentnum=<% $agent->agentnum %>">Package&nbsp;Churn</A>
301           <BR><A HREF="<% $p %>search/report_cust_pay.html?agentnum=<% $agent->agentnum %>">Payments</A>
302           <BR><A HREF="<% $p %>search/report_cust_credit.html?agentnum=<% $agent->agentnum %>">Credits</A>
303           <BR><A HREF="<% $p %>search/report_receivables.cgi?agentnum=<% $agent->agentnum %>">A/R&nbsp;Aging</A>
304           <!--<BR><A HREF="<% $p %>search/money_time.cgi?agentnum=<% $agent->agentnum %>">Sales/Credits/Receipts</A>-->
305
306         </TD>
307
308         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
309           <% my $num_reg_code = $agent->num_reg_code %>
310 % if ( $num_reg_code ) { 
311
312             <A HREF="<%$p%>search/reg_code.html?agentnum=<% $agent->agentnum %>">
313 % } 
314 Unused
315 % if ( $num_reg_code ) { 
316 </A>
317 % } 
318
319           <BR><A HREF="<%$p%>edit/reg_code.cgi?agentnum=<% $agent->agentnum %>">Generate codes</A>
320         </TD>
321
322         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
323           <% my $num_prepay_credit = $agent->num_prepay_credit %>
324 % if ( $num_prepay_credit ) { 
325
326             <A HREF="<%$p%>search/prepay_credit.html?agentnum=<% $agent->agentnum %>">
327 % } 
328 Unused
329 % if ( $num_prepay_credit ) { 
330 </A>
331 % } 
332
333           <BR><A HREF="<%$p%>edit/prepay_credit.cgi?agentnum=<% $agent->agentnum %>">Generate cards</A>
334         </TD>
335 % if ( $conf->config('ticket_system') ) { 
336
337
338           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
339 % if ( $agent->ticketing_queueid ) { 
340
341               Queue: <% $agent->ticketing_queueid %>: <% $agent->ticketing_queue %><BR>
342 % } 
343
344           </TD>
345 % } 
346
347
348         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
349           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
350 % foreach my $override (
351 %                 # sort { }  want taxclass-full stuff first?  and default cards (empty cardtype)
352 %                 qsearch('agent_payment_gateway', { 'agentnum' => $agent->agentnum } )
353 %               ) {
354 %            
355
356               <TR>
357                 <TD> 
358                   <% $override->cardtype || 'Default' %> to <% $override->payment_gateway->gateway_module %> (<% $override->payment_gateway->gateway_username %>)
359                   <% $override->taxclass
360                         ? ' for '. $override->taxclass. ' only'
361                         : ''
362                   %>
363                   <FONT SIZE=-1><A HREF="javascript:areyousure('delete this payment gateway override', '<%$p%>misc/delete-agent_payment_gateway.cgi?<% $override->agentgatewaynum %>')">(delete)</A></FONT>
364                 </TD>
365               </TR>
366 % } 
367
368             <TR>
369               <TD><FONT SIZE=-1><A HREF="<%$p%>edit/agent_payment_gateway.html?agentnum=<% $agent->agentnum %>">(add override)</A></FONT></TD>
370             </TR>
371           </TABLE>
372         </TD>
373
374         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
375           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
376 % foreach my $override (
377 %                 qsearch('conf', { 'agentnum' => $agent->agentnum } )
378 %               ) {
379 %            
380
381               <TR>
382                 <TD> 
383                   <% $override->name %>&nbsp;<FONT SIZE=-1><A HREF="javascript:areyousure('delete this configuration override', '<%$p%>config/config-delete.cgi?confnum=<% $override->confnum %>')">(delete)</A></FONT>
384                 </TD>
385               </TR>
386 % } 
387
388             <TR>
389               <TD><FONT SIZE=-1><A HREF="<%$p%>config/config-view.cgi?agentnum=<% $agent->agentnum %>">(view/add/edit overrides)</A></FONT></TD>
390             </TR>
391           </TABLE>
392         </TD>
393
394       </TR>
395 % } 
396
397
398     </TABLE>
399
400 <SCRIPT TYPE="text/javascript">
401   function areyousure(what, href) {
402     if ( confirm("Are you sure you want to " + what + "?") == true )
403       window.location.href = href;
404   }
405 </SCRIPT>
406
407   </BODY>
408 </HTML>
409 <%init>
410
411 die "access denied"
412   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
413
414 my %search;
415 if ( $cgi->param('showdisabled')
416      || !dbdef->table('agent')->column('disabled') ) {
417   %search = ();
418 } else {
419   %search = ( 'disabled' => '' );
420 }
421
422 my $conf = new FS::Conf;
423
424 </%init>