add cust_main.mobile and ship_mobile to support uniserve portal, RT#13656
[freeside.git] / httemplate / edit / cust_main.cgi
1 <& /elements/header.html,
2       $title,
3       '',
4       ' onUnload="myclose()"' #hmm, in billing.html
5 &>
6
7 <& /elements/error.html &>
8
9 <FORM NAME   = "CustomerForm"
10       METHOD = "POST"
11       ACTION = "<% popurl(1) %>process/cust_main.cgi"
12 >
13
14 <INPUT TYPE="hidden" NAME="custnum"     VALUE="<% $custnum %>">
15 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
16
17 % if ( $custnum ) { 
18   <% mt('Customer #') |h %><B><% $cust_main->display_custnum %></B> - 
19   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
20     <% ucfirst($cust_main->status) %>
21   </FONT></B>
22   <BR><BR>
23 % } 
24
25 %# agent, agent_custid, refnum (advertising source), referral_custnum
26 <& cust_main/top_misc.html, $cust_main, 'custnum' => $custnum  &>
27
28 %# birthdate
29 % if ( $conf->exists('cust_main-enable_birthdate') ) {
30   <BR>
31   <& cust_main/birthdate.html, $cust_main &>
32 % }
33
34 %# latitude and longitude
35 % if ( $conf->exists('cust_main-require_censustract') ) {
36 %   my ($latitude, $longitude) = $cust_main->service_coordinates;
37 %   $latitude ||= $conf->config('company_latitude') || '';
38 %   $longitude ||= $conf->config('company_longitude') || '';
39   <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
40   <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
41 % }
42
43 %# contact info
44
45 %  my $same_checked = '';
46 %  my $ship_disabled = '';
47 %  my @ship_style = ();
48 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
49 %    $same_checked = 'CHECKED';
50 %    $ship_disabled = 'DISABLED';
51 %    push @ship_style, 'background-color:#dddddd';
52 %    foreach (
53 %      qw( last first company address1 address2 city county state zip country
54 %          daytime night fax mobile )
55 %    ) {
56 %      $cust_main->set("ship_$_", $cust_main->get($_) );
57 %    }
58 %  }
59
60 <BR>
61 <FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
62
63 <& cust_main/contact.html,
64              'cust_main'    => $cust_main,
65              'pre'          => '',
66              'onchange'     => 'bill_changed(this)',
67              'disabled'     => '',
68              'ss'           => $ss,
69              'stateid'      => $stateid,
70              'same_checked' => $same_checked, #for address2 "Unit #" labeling
71 &>
72
73 <SCRIPT>
74 function bill_changed(what) {
75   if ( what.form.same.checked ) {
76 % for (qw( last first company address1 address2 city zip daytime night fax mobile )) { 
77     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
78 % } 
79
80     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
81
82     function fix_ship_city() {
83       what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
84       what.form.ship_city.style.display = what.form.city.style.display;
85       what.form.ship_city_select.style.display = what.form.city_select.style.display;
86     }
87
88     function fix_ship_county() {
89       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
90       ship_county_changed(what.form.ship_county, fix_ship_city );
91     }
92
93     function fix_ship_state() {
94       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
95       ship_state_changed(what.form.ship_state, fix_ship_county );
96     }
97
98     ship_country_changed(what.form.ship_country, fix_ship_state );
99
100   }
101 }
102 function samechanged(what) {
103   if ( what.checked ) {
104     bill_changed(what);
105
106 %   my @fields = qw( last first company address1 address2 city city_select county state zip country daytime night fax mobile );
107 %   for (@fields) { 
108       what.form.ship_<%$_%>.disabled = true;
109       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
110 %   } 
111
112 %   if ( $conf->exists('cust_main-require_address2') ) {
113       document.getElementById('address2_required').style.visibility = '';
114       document.getElementById('address2_label').style.visibility = '';
115       document.getElementById('ship_address2_required').style.visibility = 'hidden';
116       document.getElementById('ship_address2_label').style.visibility = 'hidden';
117 %   }
118
119   } else {
120
121 %   for (@fields) { 
122       what.form.ship_<%$_%>.disabled = false;
123       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
124 %   } 
125
126 %   if ( $conf->exists('cust_main-require_address2') ) {
127       document.getElementById('address2_required').style.visibility = 'hidden';
128       document.getElementById('address2_label').style.visibility = 'hidden';
129       document.getElementById('ship_address2_required').style.visibility = '';
130       document.getElementById('ship_address2_label').style.visibility = '';
131 %   }
132
133   }
134 }
135 </SCRIPT>
136
137 <BR>
138 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
139
140 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
141 <& cust_main/contact.html,
142              'cust_main' => $cust_main,
143              'pre'       => 'ship_',
144              'onchange'  => '',
145              'disabled'  => $ship_disabled,
146              'style'     => \@ship_style
147 &>
148
149 %# billing info
150 <& cust_main/billing.html, $cust_main,
151                'payinfo'        => $payinfo,
152                'invoicing_list' => \@invoicing_list,
153 &>
154
155 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
156 % if (!$ro_comments || $cust_main->comments) {
157
158     <BR><% mt('Comments') |h %> 
159     <% &ntable("#cccccc") %>
160       <TR>
161         <TD>
162           <TEXTAREA NAME = "comments"
163                     COLS = 80
164                     ROWS = 5
165                     WRAP = "HARD"
166                     <% $ro_comments %>
167           ><% $cust_main->comments %></TEXTAREA>
168         </TD>
169       </TR>
170     </TABLE>
171
172 % }
173
174 % unless ( $custnum ) {
175
176     <& cust_main/first_pkg.html, $cust_main,
177                  'pkgpart_svcpart' => $pkgpart_svcpart,
178                  'disable_empty'   =>
179                    scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
180                  'username'        => $username,
181                  'password'        => $password,
182                  'popnum'          => $popnum,
183                  'saved_domsvc'    => $saved_domsvc,
184                  %svc_phone,
185                  %svc_dsl,
186     &>
187
188 % }
189
190 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
191
192 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
193
194 %# cust_main/bottomfixup.js
195 % foreach my $hidden (
196 %    'payauto',
197 %    'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
198 %    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
199 %    'paystart_month', 'paystart_year', 'payissue',
200 %    'payip',
201 %    'paid',
202 % ) {
203     <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
204 % } 
205
206 <& cust_main/bottomfixup.html &>
207
208 <BR>
209 <INPUT TYPE    = "button"
210        NAME    = "submitButton"
211        ID      = "submitButton"
212        VALUE   = "<% $custnum ?  emt("Apply changes") : emt("Add Customer") %>"
213        onClick = "this.disabled=true; bottomfixup(this.form);"
214 >
215 </FORM>
216
217 <& /elements/footer.html &>
218
219 <%init>
220
221 my $curuser = $FS::CurrentUser::CurrentUser;
222
223 #probably redundant given the checks below...
224 die "access denied"
225   unless $curuser->access_right('New customer')
226      ||  $curuser->access_right('Edit customer');
227
228 my $conf = new FS::Conf;
229
230 #get record
231
232 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
233 my $same = '';
234 my $pkgpart_svcpart = ''; #first_pkg
235 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
236 my %svc_phone = ();
237 my %svc_dsl = ();
238 my $prospectnum = '';
239 my $locationnum = '';
240
241 if ( $cgi->param('error') ) {
242
243   $cust_main = new FS::cust_main ( {
244     map { $_, scalar($cgi->param($_)) } fields('cust_main')
245   } );
246
247   $custnum = $cust_main->custnum;
248
249   die "access denied"
250     unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
251
252   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
253   $same = $cgi->param('same');
254   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
255   $ss = $cust_main->ss;           # don't mask an entered value on errors
256   $stateid = $cust_main->stateid; # don't mask an entered value on errors
257   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
258
259   $prospectnum = $cgi->param('prospectnum') || '';
260
261   $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
262
263   $locationnum = $cgi->param('locationnum') || '';
264
265   #svc_acct
266   $username = $cgi->param('username');
267   $password = $cgi->param('_password');
268   $popnum = $cgi->param('popnum');
269   $saved_domsvc = $cgi->param('domsvc') || '';
270   if ( $saved_domsvc =~ /^(\d+)$/ ) {
271     $saved_domsvc = $1;
272   } else {
273     $saved_domsvc = '';
274   }
275
276   #svc_phone
277   $svc_phone{$_} = $cgi->param($_)
278     foreach qw( countrycode phonenum sip_password pin phone_name );
279
280   #svc_dsl (phonenum came in with svc_phone)
281   $svc_phone{$_} = $cgi->param($_)
282     foreach qw( password isp_chg isp_prev vendor_qual_id );
283
284 } elsif ( $cgi->keywords ) { #editing
285
286   die "access denied"
287     unless $curuser->access_right('Edit customer');
288
289   my( $query ) = $cgi->keywords;
290   $query =~ /^(\d+)$/;
291   $custnum=$1;
292   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
293   if ( $cust_main->dbdef_table->column('paycvv')
294        && length($cust_main->paycvv)             ) {
295     my $paycvv = $cust_main->paycvv;
296     $paycvv =~ s/./*/g;
297     $cust_main->paycvv($paycvv);
298   }
299   @invoicing_list = $cust_main->invoicing_list;
300   $ss = $cust_main->masked('ss');
301   $stateid = $cust_main->masked('stateid');
302   $payinfo = $cust_main->paymask;
303
304 } else { #new customer
305
306   die "access denied"
307     unless $curuser->access_right('New customer');
308
309   $custnum='';
310   $cust_main = new FS::cust_main ( {} );
311   $cust_main->agentnum( $conf->config('default_agentnum') )
312     if $conf->exists('default_agentnum');
313   $cust_main->otaker( &getotaker );
314   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
315   @invoicing_list = ();
316   push @invoicing_list, 'POST'
317     unless $conf->exists('disablepostalinvoicedefault');
318   $ss = '';
319   $stateid = '';
320   $payinfo = '';
321
322   if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
323     my $qualnum = $1;
324     my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
325       or die "unknown qualnum $qualnum";
326
327     my $prospect_main = $qual->cust_or_prospect;
328     $prospectnum = $prospect_main->prospectnum
329       or die "qualification not on a prospect";
330
331     $cust_main->agentnum( $prospect_main->agentnum );
332     $cust_main->company(  $prospect_main->company  );
333
334     #first contact? -> name
335     my @contacts = $prospect_main->contact;
336     my $contact = $contacts[0];
337     $cust_main->first( $contact->first );
338     $cust_main->set( 'last', $contact->get('last') );
339     #contact phone numbers?
340
341     #location -> address  (all prospect quals have location, right?)
342     my $cust_location = $qual->cust_location;
343     $cust_location->dealternize;
344     $cust_main->$_( $cust_location->$_ )
345       foreach qw( address1 address2 city county state zip country geocode );
346
347     #locationnum -> package order
348     $locationnum = $qual->locationnum;
349
350     #pkgpart handled by lock_pkgpart below
351
352     #service telephone & vendor_qual_id -> svc_dsl
353     $svc_dsl{$_} = $qual->$_
354       foreach qw( phonenum vendor_qual_id );
355   }
356
357   if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
358     my $pkgpart = $1;
359     my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
360       or die "unknown pkgpart $pkgpart";
361     my $svcpart = $part_pkg->svcpart;
362     $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
363   }
364
365 }
366
367 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
368 $cgi->delete( grep !$keep{$_}, $cgi->param );
369
370 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
371 $title = mt($title);
372 $title .= ": ". $cust_main->name if $custnum;
373
374 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
375
376 </%init>