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