UI spring cleaning: customer edit
[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       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   rescom_changed(document.getElementById('residential_commercial_Residential'));
87   agent_changed(document.getElementById('agentnum'));
88   samechanged(document.getElementById('same'));
89   </&>
90  
91 </SCRIPT>
92
93 % foreach my $field ($cust_main->virtual_fields) {
94     <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
95 % }
96
97 %# tags
98 <& /elements/tr-select-cust_tag.html,
99              'custnum' => $custnum,
100              'cgi'     => $cgi,
101 &>
102
103 %# agent
104 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
105 %
106 %   my $agentnum = $1;
107 %   $cust_main->agentnum($agentnum);
108
109     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
110     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
111       VALUE="<% $agentnum %>">
112     <TR>
113       <TH ALIGN="right"><% mt('Agent') |h %></TD>
114       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
115     </TR>
116
117 % } else {
118
119   <& /elements/tr-select-agent.html, 
120                 'curr_value'    => $cust_main->agentnum,
121                 'label'         => $r. emt('Agent'),
122                 'empty_label'   => emt('Select agent'),
123                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
124                 'viewall_right' => emt('None'), 
125                 'onchange'      => 'agent_changed(this)',
126   &>
127
128 % }
129
130 %# agent_custid
131 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
132
133     <TR>
134       <TH ALIGN="right"><% mt('Customer identifier') |h %></TD>
135       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
136     </TR>
137
138 % } else {
139
140     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
141
142 % }
143
144 %# class
145 <& /elements/tr-select-cust_class.html,
146              'curr_value'  => $cust_main->classnum,
147              'label'       => emt("Class"),
148 &>
149
150 %# tax status
151 <& /elements/tr-select-tax_status.html,
152              'curr_value'     => $cust_main->taxstatusnum,
153              'disable_empty'  => 0,
154              'empty_label'    => ' ',
155 &>
156
157 %#sales person
158 <& /elements/tr-select-sales.html,
159      'curr_value' => $cust_main->salesnum,
160      'th' => 1,
161 &>
162
163 %# referral (advertising source)
164 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
165 %if ( $custnum && ! $conf->exists('editreferrals') ) {
166
167   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
168
169 % } else { 
170
171   <& /elements/tr-select-part_referral.html,
172                 'curr_value' => $refnum,
173                 'label'      => $r. emt('Advertising source'),
174   &>
175 % } 
176
177
178 %# referring customer
179 %my $referring_cust_main = '';
180 %if ( $cust_main->referral_custnum
181 %     and $referring_cust_main =
182 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
183 %     and ! $curuser->access_right('Edit referring customer')
184 %) {
185
186   <TR>
187     <TH ALIGN="right"><% mt('Referring customer') |h %></TD>
188     <TD>
189       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
190     </TD>
191   </TR>
192   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
193
194 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
195
196   <TR>
197     <TH ALIGN="right"><% mt('Referring customer') |h %></TD>
198     <TD>
199       <& /elements/search-cust_main.html,
200                     'field_name' => 'referral_custnum',
201                     'curr_value' => $cust_main->referral_custnum,
202       &>
203     </TD>
204   </TR>
205
206 % } else { 
207   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
208 % } 
209
210 %# signup date
211 % if ( $conf->exists('cust_main-edit_signupdate') ) {
212     <& /elements/tr-input-date-field.html, {
213                   'name'        => 'signupdate',
214                   'value'       => $cust_main->signupdate,
215                   'label'       => emt('Signup date'),
216                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
217               }
218     &>
219 % }
220
221 % # permission to edit ticket subjects
222 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
223   <TR>
224     <TD ALIGN="right">
225       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
226         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
227     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
228   </TR>
229 % } else {
230   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
231 % }
232
233 % # permission to edit
234 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
235   <TR>
236     <TD ALIGN="right">
237       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
238         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
239     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
240   </TR>
241 % } else {
242   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
243 % }
244
245 </TABLE>
246
247 <%init>
248
249 my( $cust_main, %opt ) = @_;
250
251 my $custnum = $opt{'custnum'};
252
253 my $conf = new FS::Conf;
254
255 if ( $cgi->param('error') ) {
256   $cust_main->set('residential_commercial',
257     ($cgi->param('residential_commercial') eq 'Commercial')
258       ? 'Commercial'
259       : 'Residential'
260   );
261 } elsif ( $custnum ) { #editing
262   $cust_main->set('residential_commercial',
263     length($cust_main->company)
264       ? 'Commercial'
265       : 'Residential'
266   );
267 } else { #new customer
268   $cust_main->set('residential_commercial',
269     $conf->exists('cust_main-default_commercial')
270       ? 'Commercial'
271       : 'Residential'
272   );
273 }
274
275 my $curuser = $FS::CurrentUser::CurrentUser;
276
277 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
278
279 # which agents lock the service address, if any
280 my %ship_locked_agents;
281 foreach (qsearch('agent',{})) {
282   my $agentnum = $_->agentnum;
283   next unless $conf->exists('agent-ship_address', $_->agentnum);
284   my $cust_main = $_->agent_cust_main or next;
285   my $agent_ship_location = $cust_main->ship_location;
286   $ship_locked_agents{$agentnum} = +{
287     map { $_ => $agent_ship_location->$_ }
288     qw(locationname address1 city state zip country latitude longitude district)
289   };
290 }
291
292 </%init>