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,
57 <& cust_main/after_bill_location.html, $cust_main &>
61 <TR><TD STYLE="height:40px"></TD></TR>
63 <TD STYLE="width:650px">
64 %#; padding-left:2px; vertical-align:top">
65 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
66 <INPUT TYPE="checkbox"
69 onclick="samechanged(this)"
70 onkeyup="samechanged(this)"
72 <% $has_ship_address ? '' : 'CHECKED' %>
73 ><% mt('same as billing address') |h %>
74 <TABLE CLASS="fsinnerbox" ID="table_ship_location">
75 <& /elements/location.html,
76 object => $cust_main->ship_location,
78 enable_censustract => 1,
82 <TABLE CLASS="fsinnerbox" ID="table_ship_location_blank"
90 function samechanged(what) {
91 %# not display = 'none', because we still want it to take up space
92 %# document.getElementById('table_ship_location').style.visibility =
93 %# what.checked ? 'hidden' : 'visible';
94 var t1 = document.getElementById('table_ship_location');
95 var t2 = document.getElementById('table_ship_location_blank');
97 t2.style.width = t1.clientWidth + 'px';
98 t2.style.height = t1.clientHeight + 'px';
99 t1.style.display = 'none';
100 t2.style.display = '';
103 t2.style.display = 'none';
104 t1.style.display = '';
107 samechanged(document.getElementById('same'));
112 <& cust_main/contacts_new.html,
113 'cust_main' => $cust_main,
117 <& cust_main/billing.html, $cust_main,
118 'payinfo' => $payinfo,
119 'invoicing_list' => \@invoicing_list,
123 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
124 % if (!$ro_comments || $cust_main->comments) {
127 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
128 <TABLE CLASS="fsinnerbox">
131 <TEXTAREA NAME = "comments"
136 ><% $cust_main->comments %></TEXTAREA>
143 % unless ( $custnum ) {
145 <& cust_main/first_pkg.html, $cust_main,
146 'pkgpart_svcpart' => $pkgpart_svcpart,
148 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
149 'username' => $username,
150 'password' => $password,
152 'saved_domsvc' => $saved_domsvc,
159 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
161 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
163 %# cust_main/bottomfixup.js
164 % foreach my $hidden (
165 % 'payauto', 'billday',
166 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
167 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
168 % 'paystart_month', 'paystart_year', 'payissue',
172 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
175 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
178 <INPUT TYPE = "button"
179 NAME = "submitButton"
181 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
182 onClick = "this.disabled=true; bottomfixup(this.form);"
187 <& /elements/footer.html &>
191 my $curuser = $FS::CurrentUser::CurrentUser;
193 #probably redundant given the checks below...
195 unless $curuser->access_right('New customer')
196 || $curuser->access_right('Edit customer');
198 my $conf = new FS::Conf;
202 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
203 my $pkgpart_svcpart = ''; #first_pkg
204 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
207 my $prospectnum = '';
208 my $locationnum = '';
212 if ( $cgi->param('error') ) {
214 $same = ($cgi->param('same') || '') eq 'Y';
215 # false laziness w/ edit/process/cust_main.cgi
217 for my $pre (qw(bill ship)) {
219 foreach ( FS::cust_main->location_fields ) {
220 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
222 $hash{'custnum'} = $cgi->param('custnum');
223 $locations{$pre} = qsearchs('cust_location', \%hash)
224 || FS::cust_location->new( \%hash );
227 $locations{ship} = $locations{bill};
230 $cust_main = new FS::cust_main ( {
231 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
232 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
235 for my $pre (qw(bill ship)) {
236 $cust_main->set($pre.'_location', $locations{$pre});
237 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
240 $custnum = $cust_main->custnum;
243 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
245 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
246 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
247 $ss = $cust_main->ss; # don't mask an entered value on errors
248 $stateid = $cust_main->stateid; # don't mask an entered value on errors
249 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
251 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
253 $prospectnum = $cgi->param('prospectnum') || '';
255 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
257 $locationnum = $cgi->param('locationnum') || '';
260 $username = $cgi->param('username');
261 $password = $cgi->param('_password');
262 $popnum = $cgi->param('popnum');
263 $saved_domsvc = $cgi->param('domsvc') || '';
264 if ( $saved_domsvc =~ /^(\d+)$/ ) {
271 $svc_phone{$_} = $cgi->param($_)
272 foreach qw( countrycode phonenum sip_password pin phone_name );
274 #svc_dsl (phonenum came in with svc_phone)
275 $svc_phone{$_} = $cgi->param($_)
276 foreach qw( password isp_chg isp_prev vendor_qual_id );
278 } elsif ( $cgi->keywords ) { #editing
281 unless $curuser->access_right('Edit customer');
283 my( $query ) = $cgi->keywords;
286 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
287 if ( $cust_main->dbdef_table->column('paycvv')
288 && length($cust_main->paycvv) ) {
289 my $paycvv = $cust_main->paycvv;
291 $cust_main->paycvv($paycvv);
293 @invoicing_list = $cust_main->invoicing_list;
294 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
295 $stateid = $cust_main->masked('stateid');
296 $payinfo = $cust_main->paymask;
298 } else { #new customer
301 unless $curuser->access_right('New customer');
304 $cust_main = new FS::cust_main ( {} );
305 $cust_main->agentnum( $conf->config('default_agentnum') )
306 if $conf->exists('default_agentnum');
307 $cust_main->otaker( &getotaker );
308 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
309 @invoicing_list = ();
310 push @invoicing_list, 'POST'
311 unless $conf->exists('disablepostalinvoicedefault');
316 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
318 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
319 or die "unknown qualnum $qualnum";
321 my $prospect_main = $qual->cust_or_prospect;
322 $prospectnum = $prospect_main->prospectnum
323 or die "qualification not on a prospect";
325 $cust_main->agentnum( $prospect_main->agentnum );
326 $cust_main->company( $prospect_main->company );
328 #first contact? -> name
329 my @contacts = $prospect_main->contact;
330 my $contact = $contacts[0];
331 $cust_main->first( $contact->first );
332 $cust_main->set( 'last', $contact->get('last') );
333 #contact phone numbers?
335 #location -> address (all prospect quals have location, right?)
336 my $cust_location = $qual->cust_location;
337 $cust_location->dealternize;
338 $cust_main->$_( $cust_location->$_ )
339 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
341 #locationnum -> package order
342 $locationnum = $qual->locationnum;
344 #pkgpart handled by lock_pkgpart below
346 #service telephone & vendor_qual_id -> svc_dsl
347 $svc_dsl{$_} = $qual->$_
348 foreach qw( phonenum vendor_qual_id );
351 my $countrydefault = $conf->config('countrydefault') || 'US';
352 my $statedefault = $conf->config('statedefault') || 'CA';
353 $cust_main->set('bill_location',
354 FS::cust_location->new(
355 { country => $countrydefault, state => $statedefault }
358 $cust_main->set('ship_location',
359 FS::cust_location->new(
360 { country => $countrydefault, state => $statedefault }
365 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
367 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
368 or die "unknown pkgpart $pkgpart";
369 my $svcpart = $part_pkg->svcpart;
370 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
375 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
376 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
378 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
380 $title .= ": ". $cust_main->name if $custnum;
382 my $r = qq!<font color="#ff0000">*</font> !;