optimize CDR rating after timed rate perf regression, RT#15739
[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 ( ! $cgi->param('showdisabled') ) { 
69           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
70             <% $agent->disabled ? '<FONT COLOR="#FF0000"><B>DISABLED</B></FONT>'
71                                 : '<FONT COLOR="#00CC00"><B>Active</B></FONT>'
72             %>
73           </TD>
74 %       } 
75
76         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
77           <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agent %></A>
78         </TD>
79
80         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
81           <A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A>
82         </TD>
83
84         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
85 %         if ( $agent->agent_custnum ) {
86             <% include('/elements/small_custview.html',
87                          $agent->agent_custnum,
88                          scalar($conf->config('countrydefault')),
89                          1, #show balance
90                       )
91             %>
92 %         }
93         </TD>
94
95         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
96 %         foreach my $access_group (
97 %           map $_->access_group,
98 %               qsearch('access_groupagent', { 'agentnum' => $agent->agentnum })
99 %         ) {
100             <A HREF="<%$p%>edit/access_group.html?<% $access_group->groupnum %>"><% $access_group->groupname |h %><BR>
101 %         }
102         </TD>
103
104         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
105           <% $agent->invoice_template || '(Default)' %>
106         </TD>
107
108         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
109           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
110
111             <TR>
112               <TH ALIGN="right" WIDTH="40%">
113                 <FONT COLOR="#7e0079">
114                   <% my $num_prospect = $agent->num_prospect_cust_main %>&nbsp;
115                 </FONT>
116               </TH>
117
118               <TD>
119 % if ( $num_prospect ) { 
120
121                   <A HREF="<% $cust_main_link %>&prospect=1">
122 % } 
123 prospects
124 % if ($num_prospect ) { 
125 </A>
126 % } 
127
128               <TD>
129             </TR>
130
131             <TR>
132               <TH ALIGN="right" WIDTH="40%">
133                 <FONT COLOR="#0000CC">
134                   <% my $num_inactive = $agent->num_inactive_cust_main %>&nbsp;
135                 </FONT>
136               </TH>
137
138               <TD>
139 % if ( $num_inactive ) { 
140
141                   <A HREF="<% $cust_main_link %>&inactive=1">
142 % } 
143 inactive
144 % if ( $num_inactive ) { 
145 </A>
146 % } 
147
148               </TD>
149             </TR>
150
151             <TR>
152               <TH ALIGN="right" WIDTH="40%">
153                 <FONT COLOR="#00CC00">
154                   <% my $num_active = $agent->num_active_cust_main %>&nbsp;
155                 </FONT>
156               </TH>
157
158               <TD>
159 % if ( $num_active ) { 
160
161                   <A HREF="<% $cust_main_link %>&active=1">
162 % } 
163 active
164 % if ( $num_active ) { 
165 </A>
166 % } 
167
168               </TD>
169             </TR>
170
171             <TR>
172               <TH ALIGN="right" WIDTH="40%">
173                 <FONT COLOR="#FF9900">
174                   <% my $num_susp = $agent->num_susp_cust_main %>&nbsp;
175                 </FONT>
176               </TH>
177
178               <TD>
179 % if ( $num_susp ) { 
180
181                   <A HREF="<% $cust_main_link %>&suspended=1">
182 % } 
183 suspended
184 % if ( $num_susp ) { 
185 </A>
186 % } 
187
188               </TD>
189             </TR>
190
191             <TR>
192               <TH ALIGN="right" WIDTH="40%">
193                 <FONT COLOR="#FF0000">
194                   <% my $num_cancel = $agent->num_cancel_cust_main %>&nbsp;
195                 </FONT>
196               </TH>
197
198               <TD>
199 % if ( $num_cancel ) { 
200
201                   <A HREF="<% $cust_main_link %>&showcancelledcustomers=1&cancelled=1">
202 % } 
203 cancelled
204 % if ( $num_cancel ) { 
205 </A>
206 % } 
207
208               </TD>
209             </TR>
210
211           </TABLE>
212         </TD>
213
214         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
215           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
216
217             <TR>
218               <TH ALIGN="right" WIDTH="40%">
219                 <FONT COLOR="#0000CC">
220                   <% my $num_inactive_pkg = $agent->num_inactive_cust_pkg %>&nbsp;
221                 </FONT>
222               </TH>
223
224               <TD>
225 % if ( $num_inactive_pkg ) { 
226
227                   <A HREF="<% $cust_pkg_link %>&magic=inactive">
228 % } 
229 inactive
230 % if ( $num_inactive_pkg ) { 
231 </A>
232 % } 
233
234               </TD>
235             </TR>
236
237             <TR>
238               <TH ALIGN="right" WIDTH="40%">
239                 <FONT COLOR="#00CC00">
240                   <% my $num_active_pkg = $agent->num_active_cust_pkg %>&nbsp;
241                 </FONT>
242               </TH>
243
244               <TD>
245 % if ( $num_active_pkg ) { 
246
247                   <A HREF="<% $cust_pkg_link %>&magic=active">
248 % } 
249 active
250 % if ( $num_active_pkg ) { 
251 </A>
252 % } 
253
254               </TD>
255             </TR>
256
257             <TR>
258               <TH ALIGN="right" WIDTH="40%">
259                 <FONT COLOR="#FF9900">
260                   <% my $num_susp_pkg = $agent->num_susp_cust_pkg %>&nbsp;
261                 </FONT>
262
263               </TH>
264               <TD>
265 % if ( $num_susp_pkg ) { 
266
267                   <A HREF="<% $cust_pkg_link %>&magic=suspended">
268 % } 
269 suspended
270 % if ( $num_susp_pkg ) { 
271 </A>
272 % } 
273
274               </TD>
275             </TR>
276             
277             <TR>
278               <TH ALIGN="right" WIDTH="40%">
279                 <FONT COLOR="#FF0000">
280                   <% my $num_cancel_pkg = $agent->num_cancel_cust_pkg %>&nbsp;
281                 </FONT>
282               </TH>
283
284               <TD>
285 % if ( $num_cancel_pkg ) { 
286
287                   <A HREF="<% $cust_pkg_link %>&magic=cancelled">
288 % } 
289 cancelled
290 % if ( $num_cancel_pkg ) { 
291 </A>
292 % } 
293
294               </TD>
295             </TR>
296
297           </TABLE>
298         </TD>
299
300         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
301           <A HREF="<% $p %>graph/report_cust_pkg.html?agentnum=<% $agent->agentnum %>">Package&nbsp;Churn</A>
302           <BR><A HREF="<% $p %>search/report_cust_pay.html?agentnum=<% $agent->agentnum %>">Payments</A>
303           <BR><A HREF="<% $p %>search/report_cust_credit.html?agentnum=<% $agent->agentnum %>">Credits</A>
304           <BR><A HREF="<% $p %>search/report_receivables.cgi?agentnum=<% $agent->agentnum %>">A/R&nbsp;Aging</A>
305           <!--<BR><A HREF="<% $p %>search/money_time.cgi?agentnum=<% $agent->agentnum %>">Sales/Credits/Receipts</A>-->
306
307         </TD>
308
309         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
310           <% my $num_reg_code = $agent->num_reg_code %>
311 % if ( $num_reg_code ) { 
312
313             <A HREF="<%$p%>search/reg_code.html?agentnum=<% $agent->agentnum %>">
314 % } 
315 Unused
316 % if ( $num_reg_code ) { 
317 </A>
318 % } 
319
320           <BR><A HREF="<%$p%>edit/reg_code.cgi?agentnum=<% $agent->agentnum %>">Generate codes</A>
321         </TD>
322
323         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
324           <% my $num_prepay_credit = $agent->num_prepay_credit %>
325 % if ( $num_prepay_credit ) { 
326
327             <A HREF="<%$p%>search/prepay_credit.html?agentnum=<% $agent->agentnum %>">
328 % } 
329 Unused
330 % if ( $num_prepay_credit ) { 
331 </A>
332 % } 
333
334           <BR><A HREF="<%$p%>edit/prepay_credit.cgi?agentnum=<% $agent->agentnum %>">Generate cards</A>
335         </TD>
336 % if ( $conf->config('ticket_system') ) { 
337
338
339           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
340 % if ( $agent->ticketing_queueid ) { 
341
342               Queue: <% $agent->ticketing_queueid %>: <% $agent->ticketing_queue %><BR>
343 % } 
344
345           </TD>
346 % } 
347
348
349         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
350           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
351 % foreach my $override (
352 %                 # sort { }  want taxclass-full stuff first?  and default cards (empty cardtype)
353 %                 qsearch('agent_payment_gateway', { 'agentnum' => $agent->agentnum } )
354 %               ) {
355 %            
356
357               <TR>
358                 <TD> 
359                   <% $override->cardtype || 'Default' %> to <% $override->payment_gateway->gateway_module %> (<% $override->payment_gateway->gateway_username %>)
360                   <% $override->taxclass
361                         ? ' for '. $override->taxclass. ' only'
362                         : ''
363                   %>
364                   <FONT SIZE=-1><A HREF="javascript:areyousure('delete this payment gateway override', '<%$p%>misc/delete-agent_payment_gateway.cgi?<% $override->agentgatewaynum %>')">(delete)</A></FONT>
365                 </TD>
366               </TR>
367 % } 
368
369             <TR>
370               <TD><FONT SIZE=-1><A HREF="<%$p%>edit/agent_payment_gateway.html?agentnum=<% $agent->agentnum %>">(add override)</A></FONT></TD>
371             </TR>
372           </TABLE>
373         </TD>
374
375         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
376           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
377 % foreach my $override (
378 %                 qsearch('conf', { 'agentnum' => $agent->agentnum } )
379 %               ) {
380 %            
381
382               <TR>
383                 <TD> 
384                   <% $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>
385                 </TD>
386               </TR>
387 % } 
388
389             <TR>
390               <TD><FONT SIZE=-1><A HREF="<%$p%>config/config-view.cgi?agentnum=<% $agent->agentnum %>">(view/add/edit overrides)</A></FONT></TD>
391             </TR>
392           </TABLE>
393         </TD>
394
395       </TR>
396 % } 
397
398
399     </TABLE>
400
401 <SCRIPT TYPE="text/javascript">
402   function areyousure(what, href) {
403     if ( confirm("Are you sure you want to " + what + "?") == true )
404       window.location.href = href;
405   }
406 </SCRIPT>
407
408   </BODY>
409 </HTML>
410 <%init>
411
412 die "access denied"
413   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
414
415 my %search;
416 if ( $cgi->param('showdisabled')
417      || !dbdef->table('agent')->column('disabled') ) {
418   %search = ();
419 } else {
420   %search = ( 'disabled' => '' );
421 }
422
423 my $conf = new FS::Conf;
424
425 </%init>