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->exists('cust_main-enable_birthdate')
32 % || $conf->exists('cust_main-enable_spouse_birthdate')
36 <& cust_main/birthdate.html, $cust_main &>
38 % my $has_ship_address = '';
39 % if ( $cgi->param('error') ) {
40 % $has_ship_address = !$same;
41 % } elsif ( $cust_main->custnum ) {
42 % $has_ship_address = $cust_main->has_ship_address;
46 <TD STYLE="width:650px">
47 %#; padding-right:2px; vertical-align:top">
48 <FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
49 <TABLE CLASS="fsinnerbox">
50 <& cust_main/before_bill_location.html, $cust_main &>
51 <& /elements/location.html,
52 object => $cust_main->bill_location,
55 <& cust_main/after_bill_location.html, $cust_main &>
59 <TR><TD STYLE="height:40px"></TD></TR>
61 <TD STYLE="width:650px">
62 %#; padding-left:2px; vertical-align:top">
63 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
64 <INPUT TYPE="checkbox"
67 onclick="samechanged(this)"
68 onkeyup="samechanged(this)"
70 <% $has_ship_address ? '' : 'CHECKED' %>
71 ><% mt('same as billing address') |h %>
72 <TABLE CLASS="fsinnerbox" ID="table_ship_location">
73 <& /elements/location.html,
74 object => $cust_main->ship_location,
76 enable_censustract => 1,
80 <TABLE CLASS="fsinnerbox" ID="table_ship_location_blank"
88 function samechanged(what) {
89 %# not display = 'none', because we still want it to take up space
90 %# document.getElementById('table_ship_location').style.visibility =
91 %# what.checked ? 'hidden' : 'visible';
92 var t1 = document.getElementById('table_ship_location');
93 var t2 = document.getElementById('table_ship_location_blank');
95 t2.style.width = t1.clientWidth + 'px';
96 t2.style.height = t1.clientHeight + 'px';
97 t1.style.display = 'none';
98 t2.style.display = '';
101 t2.style.display = 'none';
102 t1.style.display = '';
105 samechanged(document.getElementById('same'));
110 <& cust_main/contacts_new.html,
111 'cust_main' => $cust_main,
115 <& cust_main/billing.html, $cust_main,
116 'payinfo' => $payinfo,
117 'invoicing_list' => \@invoicing_list,
121 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
122 % if (!$ro_comments || $cust_main->comments) {
125 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
126 <TABLE CLASS="fsinnerbox">
129 <TEXTAREA NAME = "comments"
134 ><% $cust_main->comments %></TEXTAREA>
141 % unless ( $custnum ) {
143 <& cust_main/first_pkg.html, $cust_main,
144 'pkgpart_svcpart' => $pkgpart_svcpart,
146 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
147 'username' => $username,
148 'password' => $password,
150 'saved_domsvc' => $saved_domsvc,
157 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
159 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
161 %# cust_main/bottomfixup.js
162 % foreach my $hidden (
163 % 'payauto', 'billday',
164 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
165 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
166 % 'paystart_month', 'paystart_year', 'payissue',
170 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
173 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
176 <INPUT TYPE = "button"
177 NAME = "submitButton"
179 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
180 onClick = "this.disabled=true; bottomfixup(this.form);"
185 <& /elements/footer.html &>
189 my $curuser = $FS::CurrentUser::CurrentUser;
191 #probably redundant given the checks below...
193 unless $curuser->access_right('New customer')
194 || $curuser->access_right('Edit customer');
196 my $conf = new FS::Conf;
200 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
201 my $pkgpart_svcpart = ''; #first_pkg
202 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
205 my $prospectnum = '';
206 my $locationnum = '';
210 if ( $cgi->param('error') ) {
212 $same = ($cgi->param('same') || '') eq 'Y';
213 # false laziness w/ edit/process/cust_main.cgi
215 for my $pre (qw(bill ship)) {
217 foreach ( FS::cust_main->location_fields ) {
218 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
220 $hash{'custnum'} = $cgi->param('custnum');
221 $locations{$pre} = qsearchs('cust_location', \%hash)
222 || FS::cust_location->new( \%hash );
225 $locations{ship} = $locations{bill};
228 $cust_main = new FS::cust_main ( {
229 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
230 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
233 for my $pre (qw(bill ship)) {
234 $cust_main->set($pre.'_location', $locations{$pre});
235 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
238 $custnum = $cust_main->custnum;
241 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
243 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
244 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
245 $ss = $cust_main->ss; # don't mask an entered value on errors
246 $stateid = $cust_main->stateid; # don't mask an entered value on errors
247 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
249 $prospectnum = $cgi->param('prospectnum') || '';
251 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
253 $locationnum = $cgi->param('locationnum') || '';
256 $username = $cgi->param('username');
257 $password = $cgi->param('_password');
258 $popnum = $cgi->param('popnum');
259 $saved_domsvc = $cgi->param('domsvc') || '';
260 if ( $saved_domsvc =~ /^(\d+)$/ ) {
267 $svc_phone{$_} = $cgi->param($_)
268 foreach qw( countrycode phonenum sip_password pin phone_name );
270 #svc_dsl (phonenum came in with svc_phone)
271 $svc_phone{$_} = $cgi->param($_)
272 foreach qw( password isp_chg isp_prev vendor_qual_id );
274 } elsif ( $cgi->keywords ) { #editing
277 unless $curuser->access_right('Edit customer');
279 my( $query ) = $cgi->keywords;
282 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
283 if ( $cust_main->dbdef_table->column('paycvv')
284 && length($cust_main->paycvv) ) {
285 my $paycvv = $cust_main->paycvv;
287 $cust_main->paycvv($paycvv);
289 @invoicing_list = $cust_main->invoicing_list;
290 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
291 $stateid = $cust_main->masked('stateid');
292 $payinfo = $cust_main->paymask;
294 } else { #new customer
297 unless $curuser->access_right('New customer');
300 $cust_main = new FS::cust_main ( {} );
301 $cust_main->agentnum( $conf->config('default_agentnum') )
302 if $conf->exists('default_agentnum');
303 $cust_main->otaker( &getotaker );
304 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
305 @invoicing_list = ();
306 push @invoicing_list, 'POST'
307 unless $conf->exists('disablepostalinvoicedefault');
312 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
314 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
315 or die "unknown qualnum $qualnum";
317 my $prospect_main = $qual->cust_or_prospect;
318 $prospectnum = $prospect_main->prospectnum
319 or die "qualification not on a prospect";
321 $cust_main->agentnum( $prospect_main->agentnum );
322 $cust_main->company( $prospect_main->company );
324 #first contact? -> name
325 my @contacts = $prospect_main->contact;
326 my $contact = $contacts[0];
327 $cust_main->first( $contact->first );
328 $cust_main->set( 'last', $contact->get('last') );
329 #contact phone numbers?
331 #location -> address (all prospect quals have location, right?)
332 my $cust_location = $qual->cust_location;
333 $cust_location->dealternize;
334 $cust_main->$_( $cust_location->$_ )
335 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
337 #locationnum -> package order
338 $locationnum = $qual->locationnum;
340 #pkgpart handled by lock_pkgpart below
342 #service telephone & vendor_qual_id -> svc_dsl
343 $svc_dsl{$_} = $qual->$_
344 foreach qw( phonenum vendor_qual_id );
347 my $countrydefault = $conf->config('countrydefault') || 'US';
348 my $statedefault = $conf->config('statedefault') || 'CA';
349 $cust_main->set('bill_location',
350 FS::cust_location->new(
351 { country => $countrydefault, state => $statedefault }
354 $cust_main->set('ship_location',
355 FS::cust_location->new(
356 { country => $countrydefault, state => $statedefault }
361 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
363 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
364 or die "unknown pkgpart $pkgpart";
365 my $svcpart = $part_pkg->svcpart;
366 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
371 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
372 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
374 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
376 $title .= ": ". $cust_main->name if $custnum;
378 my $r = qq!<font color="#ff0000">*</font> !;