Reverted menu-left-example.png back to original and cleaned up menu-top-example to...
[freeside.git] / httemplate / browse / agent.cgi
index 7648915..751e8b6 100755 (executable)
@@ -20,13 +20,12 @@ full offerings (via their type).<BR><BR>
 % my $bgcolor1 = '#eeeeee';
 %   my $bgcolor2 = '#ffffff';
 %   my $bgcolor = '';
-%
-
 
 <TR>
   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% ( $cgi->param('showdisabled') || !dbdef->table('agent')->column('disabled') ) ? 2 : 3 %>>Agent</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Master Customer</TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc">Commissions</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Access Groups</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice<BR>Template</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Customers</TH>
@@ -34,18 +33,21 @@ full offerings (via their type).<BR><BR>
   <TH CLASS="grid" BGCOLOR="#cccccc">Reports</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Registration<BR>codes</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Prepaid cards</TH>
-% if ( $conf->config('ticket_system') ) { 
 
+% if ( $conf->config('ticket_system') ) { 
     <TH CLASS="grid" BGCOLOR="#cccccc">Ticketing</TH>
 % } 
 
-  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment Gateway Overrides</FONT></TH>
+% if ( $conf->config('currencies') ) { 
+    <TH CLASS="grid" BGCOLOR="#cccccc">Currencies</TH>
+% } 
+
+  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment Gateway Override</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Configuration Overrides</FONT></TH>
 </TR>
-% 
+
 %#        <TH><FONT SIZE=-1>Agent #</FONT></TH>
 %#        <TH>Agent</TH>
-%
 %foreach my $agent ( sort { 
 %  #$a->getfield('agentnum') <=> $b->getfield('agentnum')
 %  $a->getfield('agent') cmp $b->getfield('agent')
@@ -61,42 +63,89 @@ full offerings (via their type).<BR><BR>
 %  } else {
 %    $bgcolor = $bgcolor1;
 %  }
-%
-%
-
 
       <TR>
 
+%       ##
+%       # agentnum
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agentnum %></A>
         </TD>
 
-%       if ( dbdef->table('agent')->column('disabled')
-%            && !$cgi->param('showdisabled')           ) { 
-          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
-            <% $agent->disabled ? 'DISABLED' : '' %>
+%       ##
+%       # disabled
+%       ##
+%       if ( ! $cgi->param('showdisabled') ) { 
+          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="center">
+            <% $agent->disabled ? '<FONT COLOR="#FF0000"><B>DISABLED</B></FONT>'
+                                : '<FONT COLOR="#00CC00"><B>Active</B></FONT>'
+            %>
           </TD>
 %       } 
 
+%       ##
+%       # agent
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agent %></A>
         </TD>
 
+%       ##
+%       # type
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A>
         </TD>
 
+%       ##
+%       # master customer
+%       ##
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
 %         if ( $agent->agent_custnum ) {
-            <% include('/elements/small_custview.html',
-                         $agent->agent_custnum,
-                         scalar($conf->config('countrydefault')),
-                         1, #show balance
-                      )
-            %>
+            <& /elements/small_custview.html,
+                 $agent->agent_custnum,
+                 scalar($conf->config('countrydefault')),
+                 1, #show balance
+                 $p.'view/cust_main.cgi',
+            &>
 %         }
         </TD>
 
+%       ##
+%       # commissions
+%       ##
+
+        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+
+          <TABLE>
+
+%           #surprising amount of false laziness w/ edit/process/agent.cgi
+%           my @pkg_class = qsearch('pkg_class', { 'disabled'=>'' });
+%           foreach my $pkg_class ( '', @pkg_class ) {
+%             my %agent_pkg_class = ( 'agentnum' => $agent->agentnum,
+%                                     'classnum' => $pkg_class ? $pkg_class->classnum : ''
+%                                   );
+%             my $agent_pkg_class =
+%               qsearchs( 'agent_pkg_class', \%agent_pkg_class )
+%               || new FS::agent_pkg_class   \%agent_pkg_class;
+%             my $param = 'classnum'. $agent_pkg_class{classnum};
+
+              <TR>
+                <TD><% $agent_pkg_class->commission_percent || 0 %>%</TD>
+                <TD><% $pkg_class ? $pkg_class->classname : mt('(no package class)') |h %>
+                </TD>
+              </TR>
+
+%           }
+
+          </TABLE>
+
+        </TD>
+
+%       ##
+%       # access groups
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
 %         foreach my $access_group (
 %           map $_->access_group,
@@ -106,211 +155,127 @@ full offerings (via their type).<BR><BR>
 %         }
         </TD>
 
+%       ##
+%       # invoice template
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <% $agent->invoice_template || '(Default)' %>
         </TD>
 
+%       ##
+%       # customers
+%       ##
+
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
 
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#7e0079">
-                  <% my $num_prospect = $agent->num_prospect_cust_main %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_prospect ) { 
-
-                  <A HREF="<% $cust_main_link %>&prospect=1">
-% } 
-prospects
-% if ($num_prospect ) { 
-</A>
-% } 
-
-              <TD>
-            </TR>
-
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#0000CC">
-                  <% my $num_inactive = $agent->num_inactive_cust_main %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_inactive ) { 
+%           my @cust_status =
+%             qw( prospect inactive ordered active suspended cancelled );
+%           my %method = ( 'suspended' => 'susp',
+%                          'cancelled' => 'cancel'
+%                        );
+%           my %PL = ( 'prospect' => 'prospects', );
+%           my %link = ( 'cancelled' => 'showcancelledcustomers=1&cancelled' );
+%           my $statuscolor = FS::cust_main->statuscolors;
+%
+%           foreach my $status ( @cust_status ) {
+%             my $meth = exists($method{$status}) ? $method{$status} : $status;
+%             $meth = 'num_'. $meth. '_cust_main';
+%             my $link = exists($link{$status}) ? $link{$status} : $status;
 
-                  <A HREF="<% $cust_main_link %>&inactive=1">
+              <TR>
+%               my $num = 0;
+%               unless ( $disable_counts ) {
+                  <TH ALIGN="right" WIDTH="40%">
+                    <FONT COLOR="#<% $statuscolor->{$status} %>">
+                      <% $num = $agent->$meth() %>&nbsp;
+                    </FONT>
+                  </TH>
+%               }
+                <TD>
+% if ( $num || $disable_counts ) { 
+%                 
+
+                  <A HREF="<% $cust_main_link. "&$link=1" %>">
 % } 
-inactive
-% if ( $num_inactive ) { 
+<% exists($PL{$status}) ? $PL{$status} : $status %>
+% if ($num || $disable_counts ) {
 </A>
 % } 
 
-              </TD>
-            </TR>
-
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#00CC00">
-                  <% my $num_active = $agent->num_active_cust_main %>&nbsp;
-                </FONT>
-              </TH>
-
               <TD>
-% if ( $num_active ) { 
-
-                  <A HREF="<% $cust_main_link %>&active=1">
-% } 
-active
-% if ( $num_active ) { 
-</A>
-% } 
-
-              </TD>
             </TR>
 
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#FF9900">
-                  <% my $num_susp = $agent->num_susp_cust_main %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_susp ) { 
-
-                  <A HREF="<% $cust_main_link %>&suspended=1">
-% } 
-suspended
-% if ( $num_susp ) { 
-</A>
-% } 
-
-              </TD>
-            </TR>
-
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#FF0000">
-                  <% my $num_cancel = $agent->num_cancel_cust_main %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_cancel ) { 
-
-                  <A HREF="<% $cust_main_link %>&showcancelledcustomers=1&cancelled=1">
-% } 
-cancelled
-% if ( $num_cancel ) { 
-</A>
-% } 
-
-              </TD>
-            </TR>
+%           }
 
           </TABLE>
         </TD>
 
+%       ##
+%       # customer packages
+%       ##
+
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="bottom">
           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
 
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#0000CC">
-                  <% my $num_inactive_pkg = $agent->num_inactive_cust_pkg %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_inactive_pkg ) { 
-
-                  <A HREF="<% $cust_pkg_link %>&magic=inactive">
-% } 
-inactive
-% if ( $num_inactive_pkg ) { 
-</A>
-% } 
-
-              </TD>
-            </TR>
-
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#00CC00">
-                  <% my $num_active_pkg = $agent->num_active_cust_pkg %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_active_pkg ) { 
-
-                  <A HREF="<% $cust_pkg_link %>&magic=active">
-% } 
-active
-% if ( $num_active_pkg ) { 
-</A>
-% } 
-
-              </TD>
-            </TR>
+%           #my @pkg_status = FS::cust_pkg->statuses;
+%           my @pkg_status = ( 'on hold', 'one-time charge', 'not yet billed',
+%                              qw( active suspended cancelled ) );
+%           my %method = ( 'one-time charge' => 'inactive',
+%                          'suspended'       => 'susp',
+%                          'cancelled'       => 'cancel',
+%                        );
+%           my $statuscolor = FS::cust_pkg->statuscolors;
+%
+%           foreach my $status ( @pkg_status ) {
+%             my $magic = exists($method{$status}) ? $method{$status} : $status;
+%             $magic =~ s/ /_/g;
+%             my $meth = 'num_'. $magic. '_cust_pkg';
+%             ( my $label = $status ) =~ s/ /&nbsp;/g;
 
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#FF9900">
-                  <% my $num_susp_pkg = $agent->num_susp_cust_pkg %>&nbsp;
-                </FONT>
+              <TR>
+%               my $num = 0;
+%               unless ( $disable_counts ) {
+                  <TH ALIGN="right" WIDTH="40%">
+                    <FONT COLOR="#<% $statuscolor->{$status} %>">
+                      <% $num = $agent->$meth() %>&nbsp;
+                    </FONT>
+                  </TH>
+%               }
 
-              </TH>
               <TD>
-% if ( $num_susp_pkg ) { 
+% if ( $num || $disable_counts ) { 
 
-                  <A HREF="<% $cust_pkg_link %>&magic=suspended">
+                  <A HREF="<% $cust_pkg_link %>&magic=<% $magic %>">
 % } 
-suspended
-% if ( $num_susp_pkg ) { 
+<% $label %>
+% if ( $num || $disable_counts ) { 
 </A>
 % } 
 
               </TD>
             </TR>
-            
-            <TR>
-              <TH ALIGN="right" WIDTH="40%">
-                <FONT COLOR="#FF0000">
-                  <% my $num_cancel_pkg = $agent->num_cancel_cust_pkg %>&nbsp;
-                </FONT>
-              </TH>
-
-              <TD>
-% if ( $num_cancel_pkg ) { 
 
-                  <A HREF="<% $cust_pkg_link %>&magic=cancelled">
-% } 
-cancelled
-% if ( $num_cancel_pkg ) { 
-</A>
-% } 
-
-              </TD>
-            </TR>
+%           }
 
           </TABLE>
         </TD>
 
+%       ##
+%       # reports
+%       ##
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <A HREF="<% $p %>graph/report_cust_pkg.html?agentnum=<% $agent->agentnum %>">Package&nbsp;Churn</A>
           <BR><A HREF="<% $p %>search/report_cust_pay.html?agentnum=<% $agent->agentnum %>">Payments</A>
           <BR><A HREF="<% $p %>search/report_cust_credit.html?agentnum=<% $agent->agentnum %>">Credits</A>
           <BR><A HREF="<% $p %>search/report_receivables.cgi?agentnum=<% $agent->agentnum %>">A/R&nbsp;Aging</A>
           <!--<BR><A HREF="<% $p %>search/money_time.cgi?agentnum=<% $agent->agentnum %>">Sales/Credits/Receipts</A>-->
-
         </TD>
 
+%       ##
+%       # registration codes
+%       ##
+
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <% my $num_reg_code = $agent->num_reg_code %>
 % if ( $num_reg_code ) { 
@@ -325,6 +290,10 @@ Unused
           <BR><A HREF="<%$p%>edit/reg_code.cgi?agentnum=<% $agent->agentnum %>">Generate codes</A>
         </TD>
 
+%       ##
+%       # prepaid cards
+%       ##
+
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <% my $num_prepay_credit = $agent->num_prepay_credit %>
 % if ( $num_prepay_credit ) { 
@@ -338,45 +307,55 @@ Unused
 
           <BR><A HREF="<%$p%>edit/prepay_credit.cgi?agentnum=<% $agent->agentnum %>">Generate cards</A>
         </TD>
-% if ( $conf->config('ticket_system') ) { 
-
 
+%       ##
+%       # ticketing
+%       ##
+% if ( $conf->config('ticket_system') ) { 
           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
-% if ( $agent->ticketing_queueid ) { 
-
-              Queue: <% $agent->ticketing_queueid %>: <% $agent->ticketing_queue %><BR>
+%         if ( $agent->ticketing_queueid ) { 
+              Queue: <% $agent->ticketing_queueid %>:
+                     <% $agent->ticketing_queue %>
+              <BR>
+%         } 
+          </TD>
 % } 
 
+%       ##
+%       # currencies
+%       ##
+% if ( $conf->config('currencies') ) { 
+          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+            <% join('<BR>', sort keys %{ $agent->agent_currency_hashref } ) %>
           </TD>
 % } 
 
+%       ##
+%       # payment gateway override
+%       ##
 
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
-% foreach my $override (
-%                 # sort { }  want taxclass-full stuff first?  and default cards (empty cardtype)
-%                 qsearch('agent_payment_gateway', { 'agentnum' => $agent->agentnum } )
-%               ) {
-%            
-
+% my $gw_override = qsearchs('agent_payment_gateway', { 'agentnum' => $agent->agentnum } );
+% if ($gw_override) {
               <TR>
                 <TD> 
-                  <% $override->cardtype || 'Default' %> to <% $override->payment_gateway->gateway_module %> (<% $override->payment_gateway->gateway_username %>)
-                  <% $override->taxclass
-                        ? ' for '. $override->taxclass. ' only'
-                        : ''
-                  %>
-                  <FONT SIZE=-1><A HREF="<%$p%>misc/delete-agent_payment_gateway.cgi?<% $override->agentgatewaynum %>">(delete)</A></FONT>
+                  <% $gw_override->payment_gateway->gateway_module %> (<% $gw_override->payment_gateway->gateway_username %>)
+                  <FONT SIZE=-1><A HREF="javascript:areyousure('delete this payment gateway override', '<%$p%>misc/delete-agent_payment_gateway.cgi?<% $gw_override->agentgatewaynum %>')">(delete)</A></FONT>
                 </TD>
               </TR>
-% } 
-
+% } else {
             <TR>
               <TD><FONT SIZE=-1><A HREF="<%$p%>edit/agent_payment_gateway.html?agentnum=<% $agent->agentnum %>">(add override)</A></FONT></TD>
             </TR>
+% }
           </TABLE>
         </TD>
 
+%       ##
+%       # configuration overrides
+%       ##
+
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
 % foreach my $override (
@@ -386,14 +365,13 @@ Unused
 
               <TR>
                 <TD> 
-                  <% $override->name %>
-                  <FONT SIZE=-1><A HREF="<%$p%>config/config-delete.cgi?<% $override->confnum %>">(delete)</A></FONT>
+                  <% $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>
                 </TD>
               </TR>
 % } 
 
             <TR>
-              <TD><FONT SIZE=-1><A HREF="<%$p%>config/config-view.cgi?agentnum=<% $agent->agentnum %>">(add override)</A></FONT></TD>
+              <TD><FONT SIZE=-1><A HREF="<%$p%>config/config-view.cgi?agentnum=<% $agent->agentnum %>">(view/add/edit overrides)</A></FONT></TD>
             </TR>
           </TABLE>
         </TD>
@@ -403,6 +381,14 @@ Unused
 
 
     </TABLE>
+
+<SCRIPT TYPE="text/javascript">
+  function areyousure(what, href) {
+    if ( confirm("Are you sure you want to " + what + "?") == true )
+      window.location.href = href;
+  }
+</SCRIPT>
+
   </BODY>
 </HTML>
 <%init>
@@ -419,5 +405,6 @@ if ( $cgi->param('showdisabled')
 }
 
 my $conf = new FS::Conf;
+my $disable_counts = $conf->exists('agent-disable_counts');
 
 </%init>