1 <& /elements/header.html,
4 ' onUnload="myclose()"' #hmm, in billing.html
7 <& /elements/error.html &>
9 <FORM NAME = "CustomerForm"
11 ACTION = "<% popurl(1) %>process/cust_main.cgi"
14 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
15 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
18 <% mt('Customer #') |h %><B><% $cust_main->display_custnum %></B> -
19 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
20 <% ucfirst($cust_main->status) %>
25 %# agent, agent_custid, refnum (advertising source), referral_custnum
26 %# better section title for this?
27 <FONT CLASS="fsinnerbox-title"><% mt('Basics') |h %></FONT>
28 <& cust_main/top_misc.html, $cust_main, 'custnum' => $custnum &>
31 % if ( $conf->config('national_id-country')
32 % || $conf->exists('cust_main-enable_birthdate')
33 % || $conf->exists('cust_main-enable_spouse_birthdate')
34 % || $conf->exists('cust_main-enable_anniversary_date')
38 <& cust_main/birthdate.html, $cust_main &>
40 % my $has_ship_address = '';
41 % if ( $cgi->param('error') ) {
42 % $has_ship_address = !$same;
43 % } elsif ( $cust_main->custnum ) {
44 % $has_ship_address = $cust_main->has_ship_address;
48 <TD STYLE="width:650px">
49 %#; padding-right:2px; vertical-align:top">
50 <FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
51 <TABLE CLASS="fsinnerbox">
52 <& cust_main/before_bill_location.html, $cust_main &>
53 <& /elements/location.html,
54 object => $cust_main->bill_location,
58 <& cust_main/after_bill_location.html, $cust_main &>
62 <TR><TD STYLE="height:40px"></TD></TR>
64 <TD STYLE="width:650px">
65 %#; padding-left:2px; vertical-align:top">
66 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
67 <INPUT TYPE="checkbox"
70 onclick="samechanged(this)"
71 onkeyup="samechanged(this)"
73 <% $has_ship_address ? '' : 'CHECKED' %>
74 ><% mt('same as billing address') |h %>
75 <TABLE CLASS="fsinnerbox" ID="table_ship_location">
76 <& /elements/location.html,
77 object => $cust_main->ship_location,
79 enable_censustract => 1,
84 <TABLE CLASS="fsinnerbox" ID="table_ship_location_blank"
92 function samechanged(what) {
93 %# not display = 'none', because we still want it to take up space
94 %# document.getElementById('table_ship_location').style.visibility =
95 %# what.checked ? 'hidden' : 'visible';
96 var t1 = document.getElementById('table_ship_location');
97 var t2 = document.getElementById('table_ship_location_blank');
99 t2.style.width = t1.clientWidth + 'px';
100 t2.style.height = t1.clientHeight + 'px';
101 t1.style.display = 'none';
102 t2.style.display = '';
105 t2.style.display = 'none';
106 t1.style.display = '';
109 samechanged(document.getElementById('same'));
114 <& cust_main/contacts_new.html,
115 'cust_main' => $cust_main,
119 <& cust_main/billing.html, $cust_main,
120 'payinfo' => $payinfo,
121 'invoicing_list' => \@invoicing_list,
125 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
126 % if (!$ro_comments || $cust_main->comments) {
129 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
130 <TABLE CLASS="fsinnerbox">
133 <TEXTAREA NAME = "comments"
138 ><% $cust_main->comments %></TEXTAREA>
145 % unless ( $custnum ) {
147 <& cust_main/first_pkg.html, $cust_main,
148 'pkgpart_svcpart' => $pkgpart_svcpart,
150 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
151 'username' => $username,
152 'password' => $password,
154 'saved_domsvc' => $saved_domsvc,
161 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
163 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
165 %# cust_main/bottomfixup.js
166 % foreach my $hidden (
167 % 'payauto', 'billday',
168 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
169 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
170 % 'paystart_month', 'paystart_year', 'payissue',
174 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
177 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
180 <INPUT TYPE = "button"
181 NAME = "submitButton"
183 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
184 onClick = "this.disabled=true; bottomfixup(this.form);"
189 <& /elements/footer.html &>
193 my $curuser = $FS::CurrentUser::CurrentUser;
195 #probably redundant given the checks below...
197 unless $curuser->access_right('New customer')
198 || $curuser->access_right('Edit customer');
200 my $conf = new FS::Conf;
204 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
205 my $pkgpart_svcpart = ''; #first_pkg
206 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
209 my $prospectnum = '';
210 my $locationnum = '';
214 if ( $cgi->param('error') ) {
216 $same = ($cgi->param('same') || '') eq 'Y';
217 # false laziness w/ edit/process/cust_main.cgi
219 for my $pre (qw(bill ship)) {
221 foreach ( FS::cust_main->location_fields ) {
222 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
224 $hash{'custnum'} = $cgi->param('custnum');
225 $locations{$pre} = qsearchs('cust_location', \%hash)
226 || FS::cust_location->new( \%hash );
229 $locations{ship} = $locations{bill};
232 $cust_main = new FS::cust_main ( {
233 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
234 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
237 for my $pre (qw(bill ship)) {
238 $cust_main->set($pre.'_location', $locations{$pre});
239 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
242 $custnum = $cust_main->custnum;
245 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
247 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
248 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
249 $ss = $cust_main->ss; # don't mask an entered value on errors
250 $stateid = $cust_main->stateid; # don't mask an entered value on errors
251 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
253 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
255 $prospectnum = $cgi->param('prospectnum') || '';
257 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
259 $locationnum = $cgi->param('locationnum') || '';
262 $username = $cgi->param('username');
263 $password = $cgi->param('_password');
264 $popnum = $cgi->param('popnum');
265 $saved_domsvc = $cgi->param('domsvc') || '';
266 if ( $saved_domsvc =~ /^(\d+)$/ ) {
273 $svc_phone{$_} = $cgi->param($_)
274 foreach qw( countrycode phonenum sip_password pin phone_name );
276 #svc_dsl (phonenum came in with svc_phone)
277 $svc_phone{$_} = $cgi->param($_)
278 foreach qw( password isp_chg isp_prev vendor_qual_id );
280 } elsif ( $cgi->keywords ) { #editing
283 unless $curuser->access_right('Edit customer');
285 my( $query ) = $cgi->keywords;
288 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
289 if ( $cust_main->dbdef_table->column('paycvv')
290 && length($cust_main->paycvv) ) {
291 my $paycvv = $cust_main->paycvv;
293 $cust_main->paycvv($paycvv);
295 @invoicing_list = $cust_main->invoicing_list;
296 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
297 $stateid = $cust_main->masked('stateid');
298 $payinfo = $cust_main->paymask;
300 } else { #new customer
303 unless $curuser->access_right('New customer');
306 $cust_main = new FS::cust_main ( {} );
307 $cust_main->agentnum( $conf->config('default_agentnum') )
308 if $conf->exists('default_agentnum');
309 $cust_main->otaker( &getotaker );
310 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
311 @invoicing_list = ();
312 push @invoicing_list, 'POST'
313 unless $conf->exists('disablepostalinvoicedefault');
318 $cgi->param('tagnum', FS::part_tag->default_tags);
319 $cust_main->coord_auto('Y');
320 $cust_main->ship_coord_auto('Y');
322 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
324 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
325 or die "unknown qualnum $qualnum";
327 my $prospect_main = $qual->cust_or_prospect;
328 $prospectnum = $prospect_main->prospectnum
329 or die "qualification not on a prospect";
331 $cust_main->agentnum( $prospect_main->agentnum );
332 $cust_main->company( $prospect_main->company );
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?
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 latitude longitude coord_auto geocode );
347 #locationnum -> package order
348 $locationnum = $qual->locationnum;
350 #pkgpart handled by lock_pkgpart below
352 #service telephone & vendor_qual_id -> svc_dsl
353 $svc_dsl{$_} = $qual->$_
354 foreach qw( phonenum vendor_qual_id );
357 my $countrydefault = $conf->config('countrydefault') || 'US';
358 my $statedefault = $conf->config('statedefault') || 'CA';
359 $cust_main->set('bill_location',
360 FS::cust_location->new(
361 { country => $countrydefault, state => $statedefault }
364 $cust_main->set('ship_location',
365 FS::cust_location->new(
366 { country => $countrydefault, state => $statedefault }
371 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
373 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
374 or die "unknown pkgpart $pkgpart";
375 my $svcpart = $part_pkg->svcpart;
376 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
381 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
382 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
384 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
386 $title .= ": ". $cust_main->name if $custnum;
388 my $r = qq!<font color="#ff0000">*</font> !;