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" WIDTH="100%">
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 <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 <DIV CLASS="fsinnerbox">
75 <TABLE ID="table_ship_location" WIDTH="100%">
76 <& /elements/location.html,
77 object => $cust_main->ship_location,
79 enable_censustract => 1,
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');
95 t1.style.visibility = 'hidden';
98 t1.style.visibility = 'visible'
101 //samechanged(document.getElementById('same'));
106 <& cust_main/contacts_new.html,
107 'cust_main' => $cust_main,
111 <& cust_main/billing.html, $cust_main,
112 'payinfo' => $payinfo,
113 'invoicing_list' => \@invoicing_list,
117 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
118 % if (!$ro_comments || $cust_main->comments) {
121 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
122 <TABLE CLASS="fsinnerbox">
125 <TEXTAREA NAME = "comments"
130 ><% $cust_main->comments %></TEXTAREA>
137 % unless ( $custnum ) {
139 <& cust_main/first_pkg.html, $cust_main,
140 'pkgpart_svcpart' => $pkgpart_svcpart,
142 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
143 'username' => $username,
144 'password' => $password,
146 'saved_domsvc' => $saved_domsvc,
153 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
155 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
157 %# cust_main/bottomfixup.js
158 % foreach my $hidden (
159 % 'payauto', 'billday',
160 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
161 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
162 % 'paystart_month', 'paystart_year', 'payissue',
166 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
169 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
172 <INPUT TYPE = "button"
173 NAME = "submitButton"
175 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
176 onClick = "this.disabled=true; bottomfixup(this.form);"
181 <& /elements/footer.html &>
185 my $curuser = $FS::CurrentUser::CurrentUser;
187 #probably redundant given the checks below...
189 unless $curuser->access_right('New customer')
190 || $curuser->access_right('Edit customer');
192 my $conf = new FS::Conf;
196 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
197 my $pkgpart_svcpart = ''; #first_pkg
198 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
201 my $prospectnum = '';
202 my $locationnum = '';
206 if ( $cgi->param('error') ) {
208 $same = ($cgi->param('same') || '') eq 'Y';
209 # false laziness w/ edit/process/cust_main.cgi
211 for my $pre (qw(bill ship)) {
213 foreach ( FS::cust_main->location_fields ) {
214 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
216 $hash{'custnum'} = $cgi->param('custnum');
217 $locations{$pre} = qsearchs('cust_location', \%hash)
218 || FS::cust_location->new( \%hash );
221 $locations{ship} = $locations{bill};
224 $cust_main = new FS::cust_main ( {
225 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
226 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
229 for my $pre (qw(bill ship)) {
230 $cust_main->set($pre.'_location', $locations{$pre});
231 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
234 $custnum = $cust_main->custnum;
237 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
239 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
240 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
241 $ss = $cust_main->ss; # don't mask an entered value on errors
242 $stateid = $cust_main->stateid; # don't mask an entered value on errors
243 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
245 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
247 $prospectnum = $cgi->param('prospectnum') || '';
249 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
251 $locationnum = $cgi->param('locationnum') || '';
254 $username = $cgi->param('username');
255 $password = $cgi->param('_password');
256 $popnum = $cgi->param('popnum');
257 $saved_domsvc = $cgi->param('domsvc') || '';
258 if ( $saved_domsvc =~ /^(\d+)$/ ) {
265 $svc_phone{$_} = $cgi->param($_)
266 foreach qw( countrycode phonenum sip_password pin phone_name );
268 #svc_dsl (phonenum came in with svc_phone)
269 $svc_phone{$_} = $cgi->param($_)
270 foreach qw( password isp_chg isp_prev vendor_qual_id );
272 } elsif ( $cgi->keywords ) { #editing
275 unless $curuser->access_right('Edit customer');
277 my( $query ) = $cgi->keywords;
280 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
281 or die "custnum $custnum not found";
282 if ( $cust_main->dbdef_table->column('paycvv')
283 && length($cust_main->paycvv) ) {
284 my $paycvv = $cust_main->paycvv;
286 $cust_main->paycvv($paycvv);
288 @invoicing_list = $cust_main->invoicing_list;
289 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
290 $stateid = $cust_main->masked('stateid');
291 $payinfo = $cust_main->paymask;
293 } else { #new customer
296 unless $curuser->access_right('New customer');
299 $cust_main = new FS::cust_main ( {} );
300 $cust_main->agentnum( $conf->config('default_agentnum') )
301 if $conf->exists('default_agentnum');
302 $cust_main->otaker( &getotaker );
303 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
304 @invoicing_list = ();
305 push @invoicing_list, 'POST'
306 unless $conf->exists('disablepostalinvoicedefault');
311 $cgi->param('tagnum', FS::part_tag->default_tags);
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,
353 state => $statedefault,
357 $cust_main->set('ship_location',
358 FS::cust_location->new( {
359 country => $countrydefault,
360 state => $statedefault,
366 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
368 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
369 or die "unknown pkgpart $pkgpart";
370 my $svcpart = $part_pkg->svcpart;
371 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
376 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
377 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
379 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
381 $title .= ": ". $cust_main->name if $custnum;
383 my $r = qq!<font color="#ff0000">*</font> !;