enforce agent-ship_address in backend interface, #21327
[freeside.git] / httemplate / edit / cust_main / top_misc.html
1 <TABLE CLASS="fsinnerbox">
2
3 <TR>
4   <TD ALIGN="right">Residential</TD>
5   <TD><INPUT TYPE     = "radio"
6              NAME     = "residential_commercial"
7              ID       = "residential_commercial_Residential"
8              VALUE    = "Residential"
9              onChange = "rescom_changed(this)"
10        <% $cust_main->residential_commercial eq 'Commercial' ? '' : 'CHECKED' %>
11   ></TD>
12 </TR>
13 <TR>
14   <TD ALIGN="right">Commercial</TD>
15   <TD><INPUT TYPE     = "radio"
16              NAME     = "residential_commercial"
17              ID       = "residential_commercial_Commercial"
18              VALUE    = "Commercial"
19              onChange = "rescom_changed(this)"
20        <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
21   ></TD>
22 </TR>
23 <SCRIPT TYPE="text/javascript">
24   function rescom_changed(what) {
25     if ( what.checked == (what.value == 'Commercial' ) ) {
26       document.getElementById('company_row').style.display = '';
27       document.getElementById('contacts_div').style.display = '';
28     } else {
29       if ( document.getElementById('company').value.length == 0 ) {
30         document.getElementById('company_row').style.display = 'none';
31       }
32       document.getElementById('contacts_div').style.display = 'none';
33     }
34   }
35
36   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
37   var ship_fields = ['address1', 'city', 'state', 'zip', 'country', 
38     'latitude', 'longitude', 'district'];
39   function agent_changed(what) {
40     var agentnum = what.value;
41     var f = what.form;
42     if ( ship_locked_agents[agentnum] ) {
43       for(var x in ship_locked_agents[agentnum]) {
44         f['ship_'+x].value = ship_locked_agents[agentnum][x];
45         f['ship_'+x].disabled = true;
46       }
47       f['same'].checked = false;
48       f['same'].disabled = true;
49     } else {
50       for(var i=0; i<ship_fields.length; i++) {
51         x = ship_fields[i];
52         f['ship_'+x].value = '';
53         f['ship_'+x].disabled = false;
54       }
55       f['same'].checked = true;
56       f['same'].disabled = false;
57     }
58     samechanged(f['same']);
59   }
60   window.onload = function() {
61     agent_changed(document.getElementById('agentnum'));
62   }
63  
64 </SCRIPT>
65
66 % foreach my $field ($cust_main->virtual_fields) {
67     <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
68 % }
69
70 %# tags
71 <& /elements/tr-select-cust_tag.html,
72              'custnum' => $custnum,
73              'cgi'     => $cgi,
74 &>
75
76 %# agent
77 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
78 %
79 %   my $agentnum = $1;
80 %   $cust_main->agentnum($agentnum);
81
82     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
83     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
84       VALUE="<% $agentnum %>">
85     <TR>
86       <TD ALIGN="right"><% mt('Agent') |h %></TD>
87       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
88     </TR>
89
90 % } else {
91
92   <& /elements/tr-select-agent.html, 
93                 'curr_value'    => $cust_main->agentnum,
94                 'label'         => "<B>${r}".emt('Agent')."</B>",
95                 'empty_label'   => emt('Select agent'),
96                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
97                 'viewall_right' => emt('None'), 
98                 'onchange'      => 'agent_changed(this)',
99   &>
100
101 % }
102
103 %# agent_custid
104 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
105
106     <TR>
107       <TD ALIGN="right"><% mt('Customer identifier') |h %></TD>
108       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
109     </TR>
110
111 % } else {
112
113     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
114
115 % }
116
117 %# class
118 <& /elements/tr-select-cust_class.html,
119              'curr_value'  => $cust_main->classnum,
120              'label'       => emt("Class"),
121 &>
122
123 %# referral (advertising source)
124 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
125 %if ( $custnum && ! $conf->exists('editreferrals') ) {
126
127   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
128
129 % } else { 
130
131    <& /elements/tr-select-part_referral.html,
132                 'curr_value' => $refnum
133    &>
134 % } 
135
136
137 %# referring customer
138 %my $referring_cust_main = '';
139 %if ( $cust_main->referral_custnum
140 %     and $referring_cust_main =
141 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
142 %     and ! $curuser->access_right('Edit referring customer')
143 %) {
144
145   <TR>
146     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
147     <TD>
148       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
149     </TD>
150   </TR>
151   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
152
153 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
154
155   <TR>
156     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
157     <TD>
158       <& /elements/search-cust_main.html,
159                     'field_name' => 'referral_custnum',
160                     'curr_value' => $cust_main->referral_custnum,
161       &>
162     </TD>
163   </TR>
164
165 % } else { 
166   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
167 % } 
168
169 %# signup date
170 % if ( $conf->exists('cust_main-edit_signupdate') ) {
171     <& /elements/tr-input-date-field.html, {
172                   'name'        => 'signupdate',
173                   'value'       => $cust_main->signupdate,
174                   'label'       => emt('Signup date'),
175                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
176               }
177     &>
178 % }
179
180 % # permission to edit ticket subjects
181 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
182   <TR>
183     <TD ALIGN="right">
184       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
185         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
186     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
187   </TR>
188 % } else {
189   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
190 % }
191
192 % # permission to edit
193 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
194   <TR>
195     <TD ALIGN="right">
196       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
197         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
198     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
199   </TR>
200 % } else {
201   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
202 % }
203
204 </TABLE>
205
206 <%init>
207
208 my( $cust_main, %opt ) = @_;
209
210 my $custnum = $opt{'custnum'};
211
212 if ( $cgi->param('error') ) {
213   $cust_main->set('residential_commercial',
214     ($cgi->param('residential_commercial') eq 'Commercial')
215       ? 'Commercial'
216       : 'Residential'
217   );
218 } elsif ( $custnum ) { #editing
219   $cust_main->set('residential_commercial',
220     length($cust_main->company)
221       ? 'Commercial'
222       : 'Residential'
223   );
224 } else { #new customer
225   #config to default to commercial and/or disable residential when someone needs
226   $cust_main->set('residential_commercial', 'Residential');
227 }
228
229 my $conf = new FS::Conf;
230
231 my $curuser = $FS::CurrentUser::CurrentUser;
232
233 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
234
235 # which agents lock the service address, if any
236 my %ship_locked_agents;
237 foreach (qsearch('agent',{})) {
238   my $agentnum = $_->agentnum;
239   next unless $conf->exists('agent-ship_address', $_->agentnum);
240   my $cust_main = $_->agent_cust_main or next;
241   my $agent_ship_location = $cust_main->ship_location;
242   $ship_locked_agents{$agentnum} = +{
243     map { $_ => $agent_ship_location->$_ }
244     qw(address1 city state zip country latitude longitude district)
245   };
246 }
247
248 </%init>