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')
33 % || $conf->exists('cust_main-enable_anniversary_date')
37 <& cust_main/birthdate.html, $cust_main &>
39 % my $has_ship_address = '';
40 % if ( $cgi->param('error') ) {
41 % $has_ship_address = !$same;
42 % } elsif ( $cust_main->custnum ) {
43 % $has_ship_address = $cust_main->has_ship_address;
47 <TD STYLE="width:650px">
48 %#; padding-right:2px; vertical-align:top">
49 <FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
50 <TABLE CLASS="fsinnerbox">
51 <& cust_main/before_bill_location.html, $cust_main &>
52 <& /elements/location.html,
53 object => $cust_main->bill_location,
56 <& cust_main/after_bill_location.html, $cust_main &>
60 <TR><TD STYLE="height:40px"></TD></TR>
62 <TD STYLE="width:650px">
63 %#; padding-left:2px; vertical-align:top">
64 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
65 <INPUT TYPE="checkbox"
68 onclick="samechanged(this)"
69 onkeyup="samechanged(this)"
71 <% $has_ship_address ? '' : 'CHECKED' %>
72 ><% mt('same as billing address') |h %>
73 <TABLE CLASS="fsinnerbox" ID="table_ship_location">
74 <& /elements/location.html,
75 object => $cust_main->ship_location,
77 enable_censustract => 1,
81 <TABLE CLASS="fsinnerbox" ID="table_ship_location_blank"
89 function samechanged(what) {
90 %# not display = 'none', because we still want it to take up space
91 %# document.getElementById('table_ship_location').style.visibility =
92 %# what.checked ? 'hidden' : 'visible';
93 var t1 = document.getElementById('table_ship_location');
94 var t2 = document.getElementById('table_ship_location_blank');
96 t2.style.width = t1.clientWidth + 'px';
97 t2.style.height = t1.clientHeight + 'px';
98 t1.style.display = 'none';
99 t2.style.display = '';
102 t2.style.display = 'none';
103 t1.style.display = '';
106 samechanged(document.getElementById('same'));
111 <& cust_main/contacts_new.html,
112 'cust_main' => $cust_main,
116 <& cust_main/billing.html, $cust_main,
117 'payinfo' => $payinfo,
118 'invoicing_list' => \@invoicing_list,
122 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
123 % if (!$ro_comments || $cust_main->comments) {
126 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
127 <TABLE CLASS="fsinnerbox">
130 <TEXTAREA NAME = "comments"
135 ><% $cust_main->comments %></TEXTAREA>
142 % unless ( $custnum ) {
144 <& cust_main/first_pkg.html, $cust_main,
145 'pkgpart_svcpart' => $pkgpart_svcpart,
147 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
148 'username' => $username,
149 'password' => $password,
151 'saved_domsvc' => $saved_domsvc,
158 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
160 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
162 %# cust_main/bottomfixup.js
163 % foreach my $hidden (
164 % 'payauto', 'billday',
165 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
166 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
167 % 'paystart_month', 'paystart_year', 'payissue',
171 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
174 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
177 <INPUT TYPE = "button"
178 NAME = "submitButton"
180 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
181 onClick = "this.disabled=true; bottomfixup(this.form);"
186 <& /elements/footer.html &>
190 my $curuser = $FS::CurrentUser::CurrentUser;
192 #probably redundant given the checks below...
194 unless $curuser->access_right('New customer')
195 || $curuser->access_right('Edit customer');
197 my $conf = new FS::Conf;
201 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
202 my $pkgpart_svcpart = ''; #first_pkg
203 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
206 my $prospectnum = '';
207 my $locationnum = '';
211 if ( $cgi->param('error') ) {
213 $same = ($cgi->param('same') || '') eq 'Y';
214 # false laziness w/ edit/process/cust_main.cgi
216 for my $pre (qw(bill ship)) {
218 foreach ( FS::cust_main->location_fields ) {
219 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
221 $hash{'custnum'} = $cgi->param('custnum');
222 $locations{$pre} = qsearchs('cust_location', \%hash)
223 || FS::cust_location->new( \%hash );
226 $locations{ship} = $locations{bill};
229 $cust_main = new FS::cust_main ( {
230 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
231 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
234 for my $pre (qw(bill ship)) {
235 $cust_main->set($pre.'_location', $locations{$pre});
236 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
239 $custnum = $cust_main->custnum;
242 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
244 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
245 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
246 $ss = $cust_main->ss; # don't mask an entered value on errors
247 $stateid = $cust_main->stateid; # don't mask an entered value on errors
248 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
250 $prospectnum = $cgi->param('prospectnum') || '';
252 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
254 $locationnum = $cgi->param('locationnum') || '';
257 $username = $cgi->param('username');
258 $password = $cgi->param('_password');
259 $popnum = $cgi->param('popnum');
260 $saved_domsvc = $cgi->param('domsvc') || '';
261 if ( $saved_domsvc =~ /^(\d+)$/ ) {
268 $svc_phone{$_} = $cgi->param($_)
269 foreach qw( countrycode phonenum sip_password pin phone_name );
271 #svc_dsl (phonenum came in with svc_phone)
272 $svc_phone{$_} = $cgi->param($_)
273 foreach qw( password isp_chg isp_prev vendor_qual_id );
275 } elsif ( $cgi->keywords ) { #editing
278 unless $curuser->access_right('Edit customer');
280 my( $query ) = $cgi->keywords;
283 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
284 if ( $cust_main->dbdef_table->column('paycvv')
285 && length($cust_main->paycvv) ) {
286 my $paycvv = $cust_main->paycvv;
288 $cust_main->paycvv($paycvv);
290 @invoicing_list = $cust_main->invoicing_list;
291 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
292 $stateid = $cust_main->masked('stateid');
293 $payinfo = $cust_main->paymask;
295 } else { #new customer
298 unless $curuser->access_right('New customer');
301 $cust_main = new FS::cust_main ( {} );
302 $cust_main->agentnum( $conf->config('default_agentnum') )
303 if $conf->exists('default_agentnum');
304 $cust_main->otaker( &getotaker );
305 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
306 @invoicing_list = ();
307 push @invoicing_list, 'POST'
308 unless $conf->exists('disablepostalinvoicedefault');
313 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
315 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
316 or die "unknown qualnum $qualnum";
318 my $prospect_main = $qual->cust_or_prospect;
319 $prospectnum = $prospect_main->prospectnum
320 or die "qualification not on a prospect";
322 $cust_main->agentnum( $prospect_main->agentnum );
323 $cust_main->company( $prospect_main->company );
325 #first contact? -> name
326 my @contacts = $prospect_main->contact;
327 my $contact = $contacts[0];
328 $cust_main->first( $contact->first );
329 $cust_main->set( 'last', $contact->get('last') );
330 #contact phone numbers?
332 #location -> address (all prospect quals have location, right?)
333 my $cust_location = $qual->cust_location;
334 $cust_location->dealternize;
335 $cust_main->$_( $cust_location->$_ )
336 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
338 #locationnum -> package order
339 $locationnum = $qual->locationnum;
341 #pkgpart handled by lock_pkgpart below
343 #service telephone & vendor_qual_id -> svc_dsl
344 $svc_dsl{$_} = $qual->$_
345 foreach qw( phonenum vendor_qual_id );
348 my $countrydefault = $conf->config('countrydefault') || 'US';
349 my $statedefault = $conf->config('statedefault') || 'CA';
350 $cust_main->set('bill_location',
351 FS::cust_location->new(
352 { country => $countrydefault, state => $statedefault }
355 $cust_main->set('ship_location',
356 FS::cust_location->new(
357 { country => $countrydefault, state => $statedefault }
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{$_} && $_ !~ /^tax_/ } $cgi->param );
375 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
377 $title .= ": ". $cust_main->name if $custnum;
379 my $r = qq!<font color="#ff0000">*</font> !;