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