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