1 <% include('/elements/header.html',
4 ' onUnload="myclose()"' #hmm, in billing.html
7 <% include('/elements/error.html') %>
9 <FORM NAME = "CustomerForm"
11 ACTION = "<% popurl(1) %>process/cust_main.cgi"
12 %# STYLE = "margin-bottom: 0"
13 %# STYLE="margin-top: 0; margin-bottom: 0">
16 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
17 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
20 Customer #<B><% $cust_main->display_custnum %></B> -
21 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
22 <% ucfirst($cust_main->status) %>
27 %# agent, agent_custid, refnum (advertising source), referral_custnum
28 <% include('cust_main/top_misc.html', $cust_main, 'custnum' => $custnum ) %>
31 % if ( $conf->exists('cust_main-enable_birthdate') ) {
33 <% include('cust_main/birthdate.html', $cust_main) %>
36 %# latitude and longitude
37 % if ( $conf->exists('cust_main-require_censustract') ) {
38 % my ($latitude, $longitude) = $cust_main->service_coordinates;
39 % $latitude ||= $conf->config('company_latitude') || '';
40 % $longitude ||= $conf->config('company_longitude') || '';
41 <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
42 <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
47 % my $same_checked = '';
48 % my $ship_disabled = '';
49 % my @ship_style = ();
50 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
51 % $same_checked = 'CHECKED';
52 % $ship_disabled = 'DISABLED';
53 % push @ship_style, 'background-color:#dddddd';
55 % qw( last first company address1 address2 city county state zip country
58 % $cust_main->set("ship_$_", $cust_main->get($_) );
63 <FONT SIZE="+1"><B>Billing address</B></FONT>
65 <% include('cust_main/contact.html',
66 'cust_main' => $cust_main,
68 'onchange' => 'bill_changed(this)',
71 'stateid' => $stateid,
72 'same_checked' => $same_checked, #for address2 "Unit #" labeling
77 function bill_changed(what) {
78 if ( what.form.same.checked ) {
79 % for (qw( last first company address1 address2 city zip daytime night fax )) {
80 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
83 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
85 function fix_ship_city() {
86 what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
87 what.form.ship_city.style.display = what.form.city.style.display;
88 what.form.ship_city_select.style.display = what.form.city_select.style.display;
91 function fix_ship_county() {
92 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
93 ship_county_changed(what.form.ship_county, fix_ship_city );
96 function fix_ship_state() {
97 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
98 ship_state_changed(what.form.ship_state, fix_ship_county );
101 ship_country_changed(what.form.ship_country, fix_ship_state );
105 function samechanged(what) {
106 if ( what.checked ) {
109 % my @fields = qw( last first company address1 address2 city city_select county state zip country daytime night fax );
111 what.form.ship_<%$_%>.disabled = true;
112 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
115 % if ( $conf->exists('cust_main-require_address2') ) {
116 document.getElementById('address2_required').style.visibility = '';
117 document.getElementById('address2_label').style.visibility = '';
118 document.getElementById('ship_address2_required').style.visibility = 'hidden';
119 document.getElementById('ship_address2_label').style.visibility = 'hidden';
125 what.form.ship_<%$_%>.disabled = false;
126 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
129 % if ( $conf->exists('cust_main-require_address2') ) {
130 document.getElementById('address2_required').style.visibility = 'hidden';
131 document.getElementById('address2_label').style.visibility = 'hidden';
132 document.getElementById('ship_address2_required').style.visibility = '';
133 document.getElementById('ship_address2_label').style.visibility = '';
141 <FONT SIZE="+1"><B>Service address</B></FONT>
143 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
144 <% include('cust_main/contact.html',
145 'cust_main' => $cust_main,
148 'disabled' => $ship_disabled,
149 'style' => \@ship_style
154 <% include( 'cust_main/billing.html', $cust_main,
155 'payinfo' => $payinfo,
156 'invoicing_list' => \@invoicing_list,
160 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
161 % if (!$ro_comments || $cust_main->comments) {
164 <% &ntable("#cccccc") %>
167 <TEXTAREA NAME = "comments"
172 ><% $cust_main->comments %></TEXTAREA>
179 % unless ( $custnum ) {
181 <% include('cust_main/first_pkg.html', $cust_main,
182 'pkgpart_svcpart' => $pkgpart_svcpart,
184 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
186 'username' => $username,
187 'password' => $password,
189 'saved_domsvc' => $saved_domsvc,
197 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
199 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
201 %# cust_main/bottomfixup.js
202 % foreach my $hidden (
204 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
205 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
206 % 'paystart_month', 'paystart_year', 'payissue',
210 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
213 <% include('cust_main/bottomfixup.html') %>
216 <INPUT TYPE = "button"
217 NAME = "submitButton"
219 VALUE = "<% $custnum ? "Apply Changes" : "Add Customer" %>"
220 onClick = "this.disabled=true; bottomfixup(this.form);"
224 <% include('/elements/footer.html') %>
228 my $curuser = $FS::CurrentUser::CurrentUser;
230 #probably redundant given the checks below...
232 unless $curuser->access_right('New customer')
233 || $curuser->access_right('Edit customer');
235 my $conf = new FS::Conf;
239 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
241 my $pkgpart_svcpart = ''; #first_pkg
242 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
245 my $prospectnum = '';
246 my $locationnum = '';
248 if ( $cgi->param('error') ) {
250 $cust_main = new FS::cust_main ( {
251 map { $_, scalar($cgi->param($_)) } fields('cust_main')
254 $custnum = $cust_main->custnum;
257 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
259 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
260 $same = $cgi->param('same');
261 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
262 $ss = $cust_main->ss; # don't mask an entered value on errors
263 $stateid = $cust_main->stateid; # don't mask an entered value on errors
264 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
266 $prospectnum = $cgi->param('prospectnum') || '';
268 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
270 $locationnum = $cgi->param('locationnum') || '';
273 $username = $cgi->param('username');
274 $password = $cgi->param('_password');
275 $popnum = $cgi->param('popnum');
276 $saved_domsvc = $cgi->param('domsvc') || '';
277 if ( $saved_domsvc =~ /^(\d+)$/ ) {
284 $svc_phone{$_} = $cgi->param($_)
285 foreach qw( countrycode phonenum sip_password pin phone_name );
287 #svc_dsl (phonenum came in with svc_phone)
288 $svc_phone{$_} = $cgi->param($_)
289 foreach qw( password isp_chg isp_prev vendor_qual_id );
291 } elsif ( $cgi->keywords ) { #editing
294 unless $curuser->access_right('Edit customer');
296 my( $query ) = $cgi->keywords;
299 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
300 if ( $cust_main->dbdef_table->column('paycvv')
301 && length($cust_main->paycvv) ) {
302 my $paycvv = $cust_main->paycvv;
304 $cust_main->paycvv($paycvv);
306 @invoicing_list = $cust_main->invoicing_list;
307 $ss = $cust_main->masked('ss');
308 $stateid = $cust_main->masked('stateid');
309 $payinfo = $cust_main->paymask;
311 } else { #new customer
314 unless $curuser->access_right('New customer');
317 $cust_main = new FS::cust_main ( {} );
318 $cust_main->otaker( &getotaker );
319 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
320 @invoicing_list = ();
321 push @invoicing_list, 'POST'
322 unless $conf->exists('disablepostalinvoicedefault');
327 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
329 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
330 or die "unknown qualnum $qualnum";
332 my $prospect_main = $qual->cust_or_prospect;
333 $prospectnum = $prospect_main->prospectnum
334 or die "qualification not on a prospect";
336 $cust_main->agentnum( $prospect_main->agentnum );
337 $cust_main->company( $prospect_main->company );
339 #first contact? -> name
340 my @contacts = $prospect_main->contact;
341 my $contact = $contacts[0];
342 $cust_main->first( $contact->first );
343 $cust_main->set( 'last', $contact->get('last') );
344 #contact phone numbers?
346 #location -> address (all prospect quals have location, right?)
347 my $cust_location = $qual->cust_location;
348 $cust_location->dealternize;
349 $cust_main->$_( $cust_location->$_ )
350 foreach qw( address1 address2 city county state zip country geocode );
352 #locationnum -> package order
353 $locationnum = $qual->locationnum;
355 #pkgpart handled by lock_pkgpart below
357 #service telephone & vendor_qual_id -> svc_dsl
358 $svc_dsl{$_} = $qual->$_
359 foreach qw( phonenum vendor_qual_id );
362 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
364 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
365 or die "unknown pkgpart $pkgpart";
366 my $svcpart = $part_pkg->svcpart;
367 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
372 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
373 $cgi->delete( grep !$keep{$_}, $cgi->param );
375 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
376 $title .= ": ". $cust_main->name if $custnum;
378 my $r = qq!<font color="#ff0000">*</font> !;