backport cust_svc_unsorted method from master, RT#26097
[freeside.git] / httemplate / edit / cust_main / top_misc.html
index 5aaa0b0..4d2f24b 100644 (file)
@@ -1,19 +1,74 @@
 <% &ntable("#cccccc") %>
 
+%# tags
+<& /elements/tr-select-cust_tag.html,
+             'custnum' => $custnum,
+             'cgi'     => $cgi,
+&>
+
+<SCRIPT TYPE="text/javascript">
+var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
+var ship_fields = ['address1', 'city', 'state', 
+  'zip', 'country', 'latitude', 'longitude'];
+function agent_changed(what) {
+  var agentnum = what.value;
+  var f = what.form;
+  if ( ship_locked_agents[agentnum] ) {
+    f['same'].checked = false;
+    samechanged(f['same']); // enable everything, then...
+    f['same'].disabled = true;
+    for(var x in ship_locked_agents[agentnum]) {
+      f['ship_'+x].value = ship_locked_agents[agentnum][x];
+      f['ship_'+x].disabled = true;
+      f['ship_'+x].style.backgroundColor = '#dddddd';
+    }
+    f['ship_address2'].disabled = false;
+    f['ship_address2'].style.backgroundColor = '#ffffff';
+  } else {
+    if ( f['same'].disabled ) { // only if switching from a locked agent
+      f['same'].disabled = false;
+      f['same'].checked = true;
+      samechanged(f['same']); // re-enable everything
+    }
+  }
+}
+window.onload = function() {
+  samechanged(document.getElementById('same'));
+  agent_changed(document.getElementById('agentnum'));
+};
+</SCRIPT>
 %# agent
-<% include('/elements/tr-select-agent.html', 
-              'curr_value'    => $cust_main->agentnum,
-              'label'         => "<B>${r}Agent</B>",
-              'empty_label'   => 'Select agent',
-              'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
-           )
-%>
+% if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
+%
+%   my $agentnum = $1;
+%   $cust_main->agentnum($agentnum);
+
+    <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
+    <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
+      VALUE="<% $agentnum %>">
+    <TR>
+      <TD ALIGN="right"><% mt('Agent') |h %></TD>
+      <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
+    </TR>
+
+% } else {
+
+  <& /elements/tr-select-agent.html, 
+                'curr_value'    => $cust_main->agentnum,
+                'label'         => "<B>${r}".emt('Agent')."</B>",
+                'empty_label'   => emt('Select agent'),
+                'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
+                'viewall_right' => emt('None'), 
+                'onchange'      => 'agent_changed(this)',
+  &>
+
+% }
 
 %# agent_custid
 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
 
     <TR>
-      <TD ALIGN="right">Customer identifier</TD>
+      <TD ALIGN="right"><% mt('Customer identifier') |h %></TD>
       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
     </TR>
 
 
 % }
 
+%# class
+<& /elements/tr-select-cust_class.html,
+             'curr_value'  => $cust_main->classnum,
+             'label'       => emt("Class"),
+&>
+
 %# referral (advertising source)
 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
 %if ( $custnum && ! $conf->exists('editreferrals') ) {
 
 % } else { 
 
-   <% include('/elements/tr-select-part_referral.html',
+   <& /elements/tr-select-part_referral.html,
                 'curr_value' => $refnum
-             )
-   %>
+   &>
 % } 
 
 
 %if ( $cust_main->referral_custnum
 %     and $referring_cust_main =
 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
+%     and ! $curuser->access_right('Edit referring customer')
 %) {
 
   <TR>
-    <TD ALIGN="right">Referring customer</TD>
+    <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
     <TD>
-      <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
+      <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
     </TD>
   </TR>
   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
-% } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
 
+% } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
 
   <TR>
-    <TD ALIGN="right">Referring customer</TD>
+    <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
     <TD>
-      <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
-      <% include('/elements/search-cust_main.html',
+      <& /elements/search-cust_main.html,
                     'field_name' => 'referral_custnum',
-                 )
-      %>
+                    'curr_value' => $cust_main->referral_custnum,
+      &>
     </TD>
   </TR>
-% } else { 
-
 
+% } else { 
   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
 % } 
 
+%# signup date
+% if ( $conf->exists('cust_main-edit_signupdate') ) {
+    <& /elements/tr-input-date-field.html, {
+                  'name'        => 'signupdate',
+                  'value'       => $cust_main->signupdate,
+                  'label'       => emt('Signup date'),
+                  'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
+              }
+    &>
+% }
+
+% # permission to edit ticket subjects
+% if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
+  <TR>
+    <TD ALIGN="right">
+      <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
+        $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
+    <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
+  </TR>
+% } else {
+  <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
+% }
+
+% # permission to edit
+% if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
+  <TR>
+    <TD ALIGN="right">
+      <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
+        $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
+    <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
+  </TR>
+% } else {
+  <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
+% }
 
 </TABLE>
 
@@ -82,6 +175,22 @@ my $custnum = $opt{'custnum'};
 
 my $conf = new FS::Conf;
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
 
+# which agents lock the service address, if any
+my %ship_locked_agents;
+foreach (qsearch('agent',{})) {
+  my $agentnum = $_->agentnum;
+  next unless $conf->exists('agent-ship_address', $_->agentnum);
+  my $agent_cust_main = $_->agent_cust_main or next;
+  my $pre = '';
+  $pre = 'ship_' if $agent_cust_main->has_ship_address;
+  $ship_locked_agents{$agentnum} = +{
+    map { $_ => $agent_cust_main->get($pre.$_) }
+    qw(address1 city state zip country latitude longitude)
+  };
+}
+
 </%init>