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