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_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" WIDTH="100%">
51 <& cust_main/before_bill_location.html, $cust_main &>
52 <& /elements/location.html,
53 object => $cust_main->bill_location,
55 enable_censustract => 1,
59 <& cust_main/after_bill_location.html, $cust_main &>
63 <TR><TD STYLE="height:40px"></TD></TR>
65 <TD STYLE="width:650px">
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 <DIV CLASS="fsinnerbox">
76 <TABLE ID="table_ship_location" WIDTH="100%">
77 <& cust_main/before_ship_location.html, $cust_main &>
78 <& /elements/location.html,
79 object => $cust_main->ship_location,
81 enable_censustract => 1,
85 % unless ($conf->exists('invoice-ship_address')) { #it's always on, so hide per-cust config
88 <% include('/elements/checkbox.html',
89 'field' => 'invoice_ship_address',
91 'curr_value' => $cust_main->invoice_ship_address,
92 'postfix' => emt('Include service address on invoices'),
103 function samechanged(what) {
104 %# not display = 'none', because we still want it to take up space
105 %# document.getElementById('table_ship_location').style.visibility =
106 %# what.checked ? 'hidden' : 'visible';
107 var t1 = document.getElementById('table_ship_location');
108 if ( what.checked ) {
109 t1.style.visibility = 'hidden';
112 t1.style.visibility = 'visible'
115 samechanged(document.getElementById('same'));
120 <& cust_main/contacts_new.html,
121 'cust_main' => $cust_main,
125 <& cust_main/billing.html, $cust_main,
126 'payinfo' => $payinfo,
127 'invoicing_list' => \@invoicing_list,
131 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
132 % if (!$ro_comments || $cust_main->comments) {
135 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
136 <TABLE CLASS="fsinnerbox">
139 <TEXTAREA NAME = "comments"
144 ><% $cust_main->comments %></TEXTAREA>
151 % unless ( $custnum ) {
153 <& cust_main/first_pkg.html, $cust_main,
154 'pkgpart_svcpart' => $pkgpart_svcpart,
156 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
157 'username' => $username,
158 'password' => $password,
160 'saved_domsvc' => $saved_domsvc,
167 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
169 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
171 %# cust_main/bottomfixup.js
172 % foreach my $hidden (
173 % 'payauto', 'billday',
174 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
175 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
176 % 'paystart_month', 'paystart_year', 'payissue',
180 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
183 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
186 <INPUT TYPE = "button"
187 NAME = "submitButton"
189 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
190 onClick = "this.disabled=true; bottomfixup(this.form);"
195 <& /elements/footer.html &>
199 my $curuser = $FS::CurrentUser::CurrentUser;
201 #probably redundant given the checks below...
203 unless $curuser->access_right('New customer')
204 || $curuser->access_right('Edit customer');
206 my $conf = new FS::Conf;
210 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
211 my $pkgpart_svcpart = ''; #first_pkg
212 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
215 my $prospectnum = '';
216 my $locationnum = '';
219 $m->comp('/elements/handle_uri_query', 'secure'=>1);
221 if ( $cgi->param('error') ) {
223 $same = ($cgi->param('same') || '') eq 'Y';
224 # false laziness w/ edit/process/cust_main.cgi
226 for my $pre (qw(bill ship)) {
228 foreach my $locfield ( FS::cust_main->location_fields ) {
229 # don't search on lat/long, string values can cause qsearchs to die
230 next if grep {$_ eq $locfield} qw(latitude longitude);
231 $hash{$locfield} = scalar($cgi->param($pre.'_'.$locfield));
233 $hash{'custnum'} = $cgi->param('custnum');
234 $locations{$pre} = qsearchs('cust_location', \%hash)
235 || FS::cust_location->new( \%hash );
236 # now set lat/long, for redisplay of entered values
237 foreach my $locfield ( qw(latitude longitude) ) {
238 my $locvalue = scalar($cgi->param($pre.'_'.$locfield));
239 $locations{$pre}->set($locfield,$locvalue);
243 $locations{ship} = $locations{bill};
246 $cust_main = new FS::cust_main ( {
247 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
248 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
251 for my $pre (qw(bill ship)) {
252 $cust_main->set($pre.'_location', $locations{$pre});
253 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
256 $custnum = $cust_main->custnum;
259 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
261 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
262 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
263 $ss = $cust_main->ss; # don't mask an entered value on errors
264 $stateid = $cust_main->stateid; # don't mask an entered value on errors
265 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
267 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
269 $prospectnum = $cgi->param('prospectnum') || '';
271 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
273 $locationnum = $cgi->param('locationnum') || '';
276 $username = $cgi->param('username');
277 $password = $cgi->param('_password');
278 $popnum = $cgi->param('popnum');
279 $saved_domsvc = $cgi->param('domsvc') || '';
280 if ( $saved_domsvc =~ /^(\d+)$/ ) {
287 $svc_phone{$_} = $cgi->param($_)
288 foreach qw( countrycode phonenum sip_password pin phone_name );
290 #svc_dsl (phonenum came in with svc_phone)
291 $svc_phone{$_} = $cgi->param($_)
292 foreach qw( password isp_chg isp_prev vendor_qual_id );
294 } elsif ( $cgi->keywords ) { #editing
297 unless $curuser->access_right('Edit customer');
299 my( $query ) = $cgi->keywords;
302 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
303 or die "custnum $custnum not found";
304 if ( $cust_main->dbdef_table->column('paycvv')
305 && length($cust_main->paycvv) ) {
306 my $paycvv = $cust_main->paycvv;
308 $cust_main->paycvv($paycvv);
310 @invoicing_list = $cust_main->invoicing_list;
311 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
312 $stateid = $cust_main->masked('stateid');
313 $payinfo = $cust_main->paymask;
315 } else { #new customer
318 unless $curuser->access_right('New customer');
321 $cust_main = new FS::cust_main ( {} );
322 $cust_main->agentnum( $conf->config('default_agentnum') )
323 if $conf->exists('default_agentnum');
324 $cust_main->otaker( &getotaker );
325 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
326 @invoicing_list = ();
327 push @invoicing_list, 'POST'
328 unless $conf->exists('disablepostalinvoicedefault');
333 $cgi->param('tagnum', FS::part_tag->default_tags);
335 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
337 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
338 or die "unknown qualnum $qualnum";
340 my $prospect_main = $qual->cust_or_prospect;
341 $prospectnum = $prospect_main->prospectnum
342 or die "qualification not on a prospect";
344 $cust_main->agentnum( $prospect_main->agentnum );
345 $cust_main->company( $prospect_main->company );
347 #first contact? -> name
348 my @contacts = $prospect_main->contact;
349 my $contact = $contacts[0];
350 $cust_main->first( $contact->first );
351 $cust_main->set( 'last', $contact->get('last') );
352 #contact phone numbers?
354 #location -> address (all prospect quals have location, right?)
355 my $cust_location = $qual->cust_location;
356 $cust_location->dealternize;
357 $cust_main->$_( $cust_location->$_ )
358 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
360 #locationnum -> package order
361 $locationnum = $qual->locationnum;
363 #pkgpart handled by lock_pkgpart below
365 #service telephone & vendor_qual_id -> svc_dsl
366 $svc_dsl{$_} = $qual->$_
367 foreach qw( phonenum vendor_qual_id );
370 my $countrydefault = $conf->config('countrydefault') || 'US';
371 my $statedefault = $conf->config('statedefault') || 'CA';
372 $cust_main->set('bill_location',
373 FS::cust_location->new( {
374 country => $countrydefault,
375 state => $statedefault,
379 $cust_main->set('ship_location',
380 FS::cust_location->new( {
381 country => $countrydefault,
382 state => $statedefault,
388 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
390 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
391 or die "unknown pkgpart $pkgpart";
392 my $svcpart = $part_pkg->svcpart;
393 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
398 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
399 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
401 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
403 $title .= ": ". $cust_main->name if $custnum;
405 my $r = qq!<font color="#ff0000">*</font> !;