add a master custnum field to agents, RT#2933 (roundabout)
authorivan <ivan>
Sun, 19 Oct 2008 00:38:09 +0000 (00:38 +0000)
committerivan <ivan>
Sun, 19 Oct 2008 00:38:09 +0000 (00:38 +0000)
FS/FS/Schema.pm
FS/FS/agent.pm
httemplate/browse/agent.cgi
httemplate/edit/agent.cgi
httemplate/elements/search-cust_main.html

index 0b121db..941eafc 100644 (file)
@@ -332,17 +332,17 @@ sub tables_hashref {
         'agentnum',          'serial',    '',       '', '', '', 
         'agent',            'varchar',    '',  $char_d, '', '', 
         'typenum',              'int',    '',       '', '', '', 
-        'disabled',            'char', 'NULL',       1, '', '', 
         'ticketing_queueid',    'int', 'NULL',      '', '', '', 
         'invoice_template', 'varchar', 'NULL', $char_d, '', '',
+        'agent_custnum',        'int', 'NULL',      '', '', '',
+        'disabled',            'char', 'NULL',       1, '', '', 
         'username',         'varchar', 'NULL', $char_d, '', '', #deprecated
         '_password',        'varchar', 'NULL', $char_d, '', '', #deprecated
         'freq',              'int', 'NULL', '', '', '', #deprecated (never used)
         'prog',                     @perl_type, '', '', #deprecated (never used)
-
       ],
       'primary_key' => 'agentnum',
-      'unique' => [],
+      'unique' => [ [ 'agent_custnum' ] ], #one agent per customer?
       'index' => [ ['typenum'], ['disabled'] ],
     },
 
index 57cc945..4166a7c 100644 (file)
@@ -48,17 +48,23 @@ from FS::Record.  The following fields are currently supported:
 
 =item agent - Text name of this agent
 
-=item typenum - Agent type.  See L<FS::agent_type>
+=item typenum - Agent type (see L<FS::agent_type>)
 
-=item prog - For future use.
+=item ticketing_queueid - Ticketing Queue
 
-=item freq - For future use.
+=item invoice_template - Invoice template name
+
+=item agent_custnum - Optional agent customer (see L<FS::cust_main>)
 
 =item disabled - Disabled flag, empty or 'Y'
 
-=item username - Username for the Agent interface
+=item prog - Deprecated (never used)
+
+=item freq - Deprecated (never used)
+
+=item username - (Deprecated) Username for the Agent interface
 
-=item _password - Password for the Agent interface
+=item _password - (Deprecated) Password for the Agent interface
 
 =back
 
@@ -118,6 +124,7 @@ sub check {
       || $self->ut_numbern('freq')
       || $self->ut_textn('prog')
       || $self->ut_textn('invoice_template')
+      || $self->ut_foreign_keyn('agent_custnum', 'cust_main', 'custnum' )
   ;
   return $error if $error;
 
@@ -156,6 +163,18 @@ sub agent_type {
   qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
 }
 
+=item agent_cust_main
+
+Returns the FS::cust_main object (see L<FS::cust_main>), if any, for this
+agent.
+
+=cut
+
+sub agent_cust_main {
+  my $self = shift;
+  qsearchs( 'cust_main', { 'custnum' => $self->agent_custnum } );
+}
+
 =item pkgpart_hashref
 
 Returns a hash reference.  The keys of the hash are pkgparts.  The value is
index 234bfa7..89739f0 100755 (executable)
@@ -26,6 +26,7 @@ full offerings (via their type).<BR><BR>
 <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"><FONT SIZE=-1>Invoice<BR>Template</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Customers</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Customer<BR>packages</FONT></TH>
@@ -84,6 +85,17 @@ full offerings (via their type).<BR><BR>
           <A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A>
         </TD>
 
+        <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
+%         if ( $agent->agent_custnum ) {
+            <% include('/elements/small_custview.html',
+                         $agent->agent_custnum,
+                         scalar($conf->config('countrydefault')),
+                         1, #show balance
+                      )
+            %>
+%         }
+        </TD>
+
         <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
           <% $agent->invoice_template || '(Default)' %>
         </TD>
index 11bfc59..0c25205 100755 (executable)
@@ -30,6 +30,18 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
   </TR>
 
   <TR>
+    <TH ALIGN="right">Master customer</TH>
+    <TD>
+      <% include('/elements/search-cust_main.html',
+                   'field_name'  => 'agent_custnum',
+                   'curr_value'  => $agent->agent_custnum,
+                   'find_button' => 1,
+                )
+      %>
+    </TD>
+  </TR>
+
+  <TR>
     <TD ALIGN="right">Disable</TD>
     <TD><INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $agent->disabled eq 'Y' ? ' CHECKED' : '' %>></TD>
   </TR>
index f2b17ea..dbcc2ed 100644 (file)
@@ -1,23 +1,24 @@
-%
-%  my( %opt ) = @_;
-%  $opt{'field_name'} ||= 'custnum';
-%
-%  my $cust_main = '';
-%  if ( $opt{'value'} ) {
-%    $cust_main = qsearchs(
-%      'table'     => 'cust_main',
-%      'hashref'   => { 'custnum' => $opt{'value'} },
-%      'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
-%    );
-%  }
-%
-
-
-<INPUT TYPE="hidden" NAME="<% $opt{'field_name'} %>" VALUE="<% $opt{'value'} %>">
+<INPUT TYPE="hidden" NAME="<% $opt{'field_name'} %>" VALUE="<% $value %>">
 
 <!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
 
-<INPUT TYPE="text" NAME="<% $opt{'field_name'} %>_search" ID="<% $opt{'field_name'} %>_search" SIZE="32" VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' %>" onFocus="clearhint_<% $opt{'field_name'} %>_search(this);" onClick="clearhint_<% $opt{'field_name'} %>_search(this);" onChange="smart_<% $opt{'field_name'} %>_search(this);">
+<INPUT TYPE = "text"
+       NAME = "<% $opt{'field_name'} %>_search"
+       ID   = "<% $opt{'field_name'} %>_search"
+       SIZE = "32"
+       VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' %>"
+       onFocus="clearhint_<% $opt{'field_name'} %>_search(this);"
+       onClick="clearhint_<% $opt{'field_name'} %>_search(this);"
+       onChange="smart_<% $opt{'field_name'} %>_search(this);"
+>
+
+% if ( $opt{'find_button'} ) {
+    <INPUT TYPE    = "button"
+           VALUE   = 'Find',
+           NAME    = "<% $opt{'field_name'} %>_findbutton"
+           onClick = "smart_<% $opt{'field_name'} %>_search(this.form.<% $opt{'field_name'} %>_search);"
+    >
+% }
 
 <SELECT NAME="<% $opt{'field_name'} %>_select" ID="<% $opt{'field_name'} %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $opt{'field_name'} %>(this);">
 </SELECT>
   }
 
 </SCRIPT>
+<%init>
 
+my( %opt ) = @_;
+$opt{'field_name'} ||= 'custnum';
+
+my $value = $opt{'curr_value'} || $opt{'value'};
+
+my $cust_main = '';
+if ( $value ) {
+  $cust_main = qsearchs({
+    'table'     => 'cust_main',
+    'hashref'   => { 'custnum' => $value },
+    'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
+  });
+}
+
+</%init>