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 <% $cust_main->status_label %>
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/basics.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,
91 function samechanged(what) {
92 %# not display = 'none', because we still want it to take up space
93 %# document.getElementById('table_ship_location').style.visibility =
94 %# what.checked ? 'hidden' : 'visible';
95 var t1 = document.getElementById('table_ship_location');
97 t1.style.visibility = 'hidden';
100 t1.style.visibility = 'visible'
103 //samechanged(document.getElementById('same'));
108 <& cust_main/contacts_new.html,
109 'cust_main' => $cust_main,
113 <& cust_main/billing.html, $cust_main,
114 'payinfo' => $payinfo,
115 'invoicing_list' => \@invoicing_list,
119 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
120 % if (!$ro_comments || $cust_main->comments) {
123 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
124 <TABLE CLASS="fsinnerbox">
127 <TEXTAREA NAME = "comments"
132 ><% $cust_main->comments %></TEXTAREA>
139 % unless ( $custnum ) {
141 <& cust_main/first_pkg.html, $cust_main,
142 'pkgpart_svcpart' => $pkgpart_svcpart,
144 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
145 'username' => $username,
146 'password' => $password,
148 'saved_domsvc' => $saved_domsvc,
155 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
157 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
159 %# cust_main/bottomfixup.js
160 % foreach my $hidden (
161 % 'payauto', 'billday',
162 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
163 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
164 % 'paystart_month', 'paystart_year', 'payissue',
168 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
171 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
174 <INPUT TYPE = "button"
175 NAME = "submitButton"
177 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
178 onClick = "this.disabled=true; bottomfixup(this.form);"
183 <& /elements/footer.html &>
187 my $curuser = $FS::CurrentUser::CurrentUser;
189 #probably redundant given the checks below...
191 unless $curuser->access_right('New customer')
192 || $curuser->access_right('Edit customer');
194 my $conf = new FS::Conf;
198 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
199 my $pkgpart_svcpart = ''; #first_pkg
200 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
203 my $prospectnum = '';
204 my $locationnum = '';
207 $m->comp('/elements/handle_uri_query', 'secure'=>1);
209 if ( $cgi->param('error') ) {
211 $same = ($cgi->param('same') || '') eq 'Y';
212 # false laziness w/ edit/process/cust_main.cgi
214 for my $pre (qw(bill ship)) {
216 foreach ( FS::cust_main->location_fields ) {
217 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
219 $hash{'custnum'} = $cgi->param('custnum');
220 $locations{$pre} = qsearchs('cust_location', \%hash)
221 || FS::cust_location->new( \%hash );
224 $locations{ship} = $locations{bill};
227 $cust_main = new FS::cust_main ( {
228 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
229 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
232 for my $pre (qw(bill ship)) {
233 $cust_main->set($pre.'_location', $locations{$pre});
234 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
237 $custnum = $cust_main->custnum;
240 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
242 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
243 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
244 $ss = $cust_main->ss; # don't mask an entered value on errors
245 $stateid = $cust_main->stateid; # don't mask an entered value on errors
246 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
248 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
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 or die "custnum $custnum not found";
285 if ( $cust_main->dbdef_table->column('paycvv')
286 && length($cust_main->paycvv) ) {
287 my $paycvv = $cust_main->paycvv;
289 $cust_main->paycvv($paycvv);
291 @invoicing_list = $cust_main->invoicing_list;
292 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
293 $stateid = $cust_main->masked('stateid');
294 $payinfo = $cust_main->paymask;
296 } else { #new customer
299 unless $curuser->access_right('New customer');
302 $cust_main = new FS::cust_main ( {} );
303 $cust_main->agentnum( $conf->config('default_agentnum') )
304 if $conf->exists('default_agentnum');
305 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
306 @invoicing_list = ();
307 push @invoicing_list, 'POST'
308 unless $conf->exists('disablepostalinvoicedefault');
313 $cgi->param('tagnum', FS::part_tag->default_tags);
315 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
317 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
318 or die "unknown qualnum $qualnum";
320 my $prospect_main = $qual->cust_or_prospect;
321 $prospectnum = $prospect_main->prospectnum
322 or die "qualification not on a prospect";
324 $cust_main->agentnum( $prospect_main->agentnum );
325 $cust_main->company( $prospect_main->company );
327 #first contact? -> name
328 my @contacts = $prospect_main->contact;
329 my $contact = $contacts[0];
330 $cust_main->first( $contact->first );
331 $cust_main->set( 'last', $contact->get('last') );
332 #contact phone numbers?
334 #location -> address (all prospect quals have location, right?)
335 my $cust_location = $qual->cust_location;
336 $cust_location->dealternize;
337 $cust_main->$_( $cust_location->$_ )
338 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
340 #locationnum -> package order
341 $locationnum = $qual->locationnum;
343 #pkgpart handled by lock_pkgpart below
345 #service telephone & vendor_qual_id -> svc_dsl
346 $svc_dsl{$_} = $qual->$_
347 foreach qw( phonenum vendor_qual_id );
350 my $countrydefault = $conf->config('countrydefault') || 'US';
351 my $statedefault = $conf->config('statedefault') || 'CA';
352 $cust_main->set('bill_location',
353 FS::cust_location->new( {
354 country => $countrydefault,
355 state => $statedefault,
359 $cust_main->set('ship_location',
360 FS::cust_location->new( {
361 country => $countrydefault,
362 state => $statedefault,
368 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
370 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
371 or die "unknown pkgpart $pkgpart";
372 my $svcpart = $part_pkg->svcpart;
373 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
378 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
379 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
381 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
383 $title .= ": ". $cust_main->name if $custnum;
385 my $r = qq!<font color="#ff0000">*</font> !;