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 <& cust_main/before_ship_location.html, $cust_main &>
77 <& /elements/location.html,
78 object => $cust_main->ship_location,
80 enable_censustract => 1,
90 function samechanged(what) {
91 %# not display = 'none', because we still want it to take up space
92 %# document.getElementById('table_ship_location').style.visibility =
93 %# what.checked ? 'hidden' : 'visible';
94 var t1 = document.getElementById('table_ship_location');
96 t1.style.visibility = 'hidden';
99 t1.style.visibility = 'visible'
102 //samechanged(document.getElementById('same'));
107 <& cust_main/contacts_new.html,
108 'cust_main' => $cust_main,
112 <& cust_main/billing.html, $cust_main,
113 'payinfo' => $payinfo,
114 'invoicing_list' => \@invoicing_list,
118 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
119 % if (!$ro_comments || $cust_main->comments) {
122 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
123 <TABLE CLASS="fsinnerbox">
126 <TEXTAREA NAME = "comments"
131 ><% $cust_main->comments %></TEXTAREA>
138 % unless ( $custnum ) {
140 <& cust_main/first_pkg.html, $cust_main,
141 'pkgpart_svcpart' => $pkgpart_svcpart,
143 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
144 'username' => $username,
145 'password' => $password,
147 'saved_domsvc' => $saved_domsvc,
154 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
156 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
158 %# cust_main/bottomfixup.js
159 % foreach my $hidden (
160 % 'payauto', 'billday',
161 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
162 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
163 % 'paystart_month', 'paystart_year', 'payissue',
167 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
170 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
173 <INPUT TYPE = "button"
174 NAME = "submitButton"
176 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
177 onClick = "this.disabled=true; bottomfixup(this.form);"
182 <& /elements/footer.html &>
186 my $curuser = $FS::CurrentUser::CurrentUser;
188 #probably redundant given the checks below...
190 unless $curuser->access_right('New customer')
191 || $curuser->access_right('Edit customer');
193 my $conf = new FS::Conf;
197 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
198 my $pkgpart_svcpart = ''; #first_pkg
199 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
202 my $prospectnum = '';
203 my $locationnum = '';
206 $m->comp('/elements/handle_uri_query', 'secure'=>1);
208 if ( $cgi->param('error') ) {
210 $same = ($cgi->param('same') || '') eq 'Y';
211 # false laziness w/ edit/process/cust_main.cgi
213 for my $pre (qw(bill ship)) {
215 foreach ( FS::cust_main->location_fields ) {
216 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
218 $hash{'custnum'} = $cgi->param('custnum');
219 $locations{$pre} = qsearchs('cust_location', \%hash)
220 || FS::cust_location->new( \%hash );
223 $locations{ship} = $locations{bill};
226 $cust_main = new FS::cust_main ( {
227 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
228 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
231 for my $pre (qw(bill ship)) {
232 $cust_main->set($pre.'_location', $locations{$pre});
233 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
236 $custnum = $cust_main->custnum;
239 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
241 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
242 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
243 $ss = $cust_main->ss; # don't mask an entered value on errors
244 $stateid = $cust_main->stateid; # don't mask an entered value on errors
245 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
247 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
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 or die "custnum $custnum not found";
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->referral_custnum( $cgi->param('referral_custnum') );
305 @invoicing_list = ();
306 push @invoicing_list, 'POST'
307 unless $conf->exists('disablepostalinvoicedefault');
312 $cgi->param('tagnum', FS::part_tag->default_tags);
314 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
316 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
317 or die "unknown qualnum $qualnum";
319 my $prospect_main = $qual->cust_or_prospect;
320 $prospectnum = $prospect_main->prospectnum
321 or die "qualification not on a prospect";
323 $cust_main->agentnum( $prospect_main->agentnum );
324 $cust_main->company( $prospect_main->company );
326 #first contact? -> name
327 my @contacts = $prospect_main->contact;
328 my $contact = $contacts[0];
329 $cust_main->first( $contact->first );
330 $cust_main->set( 'last', $contact->get('last') );
331 #contact phone numbers?
333 #location -> address (all prospect quals have location, right?)
334 my $cust_location = $qual->cust_location;
335 $cust_location->dealternize;
336 $cust_main->$_( $cust_location->$_ )
337 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
339 #locationnum -> package order
340 $locationnum = $qual->locationnum;
342 #pkgpart handled by lock_pkgpart below
344 #service telephone & vendor_qual_id -> svc_dsl
345 $svc_dsl{$_} = $qual->$_
346 foreach qw( phonenum vendor_qual_id );
349 my $countrydefault = $conf->config('countrydefault') || 'US';
350 my $statedefault = $conf->config('statedefault') || 'CA';
351 $cust_main->set('bill_location',
352 FS::cust_location->new( {
353 country => $countrydefault,
354 state => $statedefault,
358 $cust_main->set('ship_location',
359 FS::cust_location->new( {
360 country => $countrydefault,
361 state => $statedefault,
367 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
369 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
370 or die "unknown pkgpart $pkgpart";
371 my $svcpart = $part_pkg->svcpart;
372 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
377 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
378 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
380 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
382 $title .= ": ". $cust_main->name if $custnum;
384 my $r = qq!<font color="#ff0000">*</font> !;