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 <& cust_main/top_misc.html, $cust_main, 'custnum' => $custnum &>
29 % if ( $conf->config('national_id-country')
30 % || $conf->exists('cust_main-enable_birthdate')
31 % || $conf->exists('cust_main-enable_spouse_birthdate')
32 % || $conf->exists('cust_main-enable_anniversary_date')
36 <& cust_main/birthdate.html, $cust_main &>
41 % my $same_checked = '';
42 % my $ship_disabled = '';
43 % my @ship_style = ();
44 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
45 % $same_checked = 'CHECKED';
46 % $ship_disabled = 'DISABLED';
47 % push @ship_style, 'background-color:#dddddd';
49 % qw( last first company address1 address2 city county state zip country
50 % latitude longitude coord_auto
51 % daytime night fax mobile )
53 % $cust_main->set("ship_$_", $cust_main->get($_) );
58 <FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
60 <& cust_main/contact.html,
61 'cust_main' => $cust_main,
63 'onchange' => 'bill_changed(this)',
66 'stateid' => $stateid,
67 'same_checked' => $same_checked, #for address2 "Unit #" labeling
71 function bill_changed(what) {
72 if ( what.form.same.checked ) {
73 % for (qw( last first company address1 address2 city zip latitude longitude coord_auto daytime night fax mobile )) {
74 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
77 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
79 function fix_ship_city() {
80 what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
81 what.form.ship_city.style.display = what.form.city.style.display;
82 if ( what.form.ship_city_select ) {
83 what.form.ship_city_select.style.display = what.form.city_select.style.display;
87 function fix_ship_county() {
88 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
89 ship_county_changed(what.form.ship_county, fix_ship_city );
92 function fix_ship_state() {
93 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
94 ship_state_changed(what.form.ship_state, fix_ship_county );
97 ship_country_changed(what.form.ship_country, fix_ship_state );
101 function samechanged(what) {
102 if ( what.checked ) {
105 % my @fields = qw( last first company address1 address2 city county state zip country latitude longitude daytime night fax mobile );
107 what.form.ship_<%$_%>.disabled = true;
108 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
110 if ( what.form.ship_city_select ) {
111 what.form.ship_city_select.disabled = true;
112 what.form.ship_city_select.style.backgroundColor = '#dddddd';
115 % if ( $conf->exists('cust_main-require_address2') ) {
116 document.getElementById('address2_required').style.visibility = '';
117 document.getElementById('address2_label').style.visibility = '';
118 document.getElementById('ship_address2_required').style.visibility = 'hidden';
119 document.getElementById('ship_address2_label').style.visibility = 'hidden';
125 what.form.ship_<%$_%>.disabled = false;
126 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
129 % if ( $conf->exists('cust_main-require_address2') ) {
130 document.getElementById('address2_required').style.visibility = 'hidden';
131 document.getElementById('address2_label').style.visibility = 'hidden';
132 document.getElementById('ship_address2_required').style.visibility = '';
133 document.getElementById('ship_address2_label').style.visibility = '';
141 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
143 (<INPUT TYPE="checkbox" ID="same" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
144 <& cust_main/contact.html,
145 'cust_main' => $cust_main,
148 'disabled' => $ship_disabled,
149 'style' => \@ship_style
153 <& cust_main/billing.html, $cust_main,
154 'payinfo' => $payinfo,
155 'invoicing_list' => \@invoicing_list,
158 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
159 % if (!$ro_comments || $cust_main->comments) {
161 <BR><% mt('Comments') |h %>
162 <% &ntable("#cccccc") %>
165 <TEXTAREA NAME = "comments"
170 ><% $cust_main->comments %></TEXTAREA>
177 % unless ( $custnum ) {
179 <& cust_main/first_pkg.html, $cust_main,
180 'pkgpart_svcpart' => $pkgpart_svcpart,
182 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
183 'username' => $username,
184 'password' => $password,
186 'saved_domsvc' => $saved_domsvc,
193 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
195 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
197 %# cust_main/bottomfixup.js
198 % foreach my $hidden (
199 % 'payauto', 'billday',
200 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
201 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
202 % 'paystart_month', 'paystart_year', 'payissue',
206 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
209 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
212 <INPUT TYPE = "button"
213 NAME = "submitButton"
215 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
216 onClick = "this.disabled=true; bottomfixup(this.form);"
220 <& /elements/footer.html &>
224 my $curuser = $FS::CurrentUser::CurrentUser;
226 #probably redundant given the checks below...
228 unless $curuser->access_right('New customer')
229 || $curuser->access_right('Edit customer');
231 my $conf = new FS::Conf;
235 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
237 my $pkgpart_svcpart = ''; #first_pkg
238 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
241 my $prospectnum = '';
242 my $locationnum = '';
244 if ( $cgi->param('error') ) {
246 $cust_main = new FS::cust_main ( {
247 map { $_, scalar($cgi->param($_)) } fields('cust_main')
250 $custnum = $cust_main->custnum;
253 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
255 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
256 $same = $cgi->param('same');
257 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
258 $ss = $cust_main->ss; # don't mask an entered value on errors
259 $stateid = $cust_main->stateid; # don't mask an entered value on errors
260 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
262 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
264 $prospectnum = $cgi->param('prospectnum') || '';
266 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
268 $locationnum = $cgi->param('locationnum') || '';
271 $username = $cgi->param('username');
272 $password = $cgi->param('_password');
273 $popnum = $cgi->param('popnum');
274 $saved_domsvc = $cgi->param('domsvc') || '';
275 if ( $saved_domsvc =~ /^(\d+)$/ ) {
282 $svc_phone{$_} = $cgi->param($_)
283 foreach qw( countrycode phonenum sip_password pin phone_name );
285 #svc_dsl (phonenum came in with svc_phone)
286 $svc_phone{$_} = $cgi->param($_)
287 foreach qw( password isp_chg isp_prev vendor_qual_id );
289 } elsif ( $cgi->keywords ) { #editing
292 unless $curuser->access_right('Edit customer');
294 my( $query ) = $cgi->keywords;
297 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
298 or die "custnum $custnum not found";
299 if ( $cust_main->dbdef_table->column('paycvv')
300 && length($cust_main->paycvv) ) {
301 my $paycvv = $cust_main->paycvv;
303 $cust_main->paycvv($paycvv);
305 @invoicing_list = $cust_main->invoicing_list;
306 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
307 $stateid = $cust_main->masked('stateid');
308 $payinfo = $cust_main->paymask;
310 } else { #new customer
313 unless $curuser->access_right('New customer');
316 $cust_main = new FS::cust_main ( {} );
317 $cust_main->agentnum( $conf->config('default_agentnum') )
318 if $conf->exists('default_agentnum');
319 $cust_main->otaker( &getotaker );
320 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
321 @invoicing_list = ();
322 push @invoicing_list, 'POST'
323 unless $conf->exists('disablepostalinvoicedefault');
328 $cgi->param('tagnum', FS::part_tag->default_tags);
330 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
332 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
333 or die "unknown qualnum $qualnum";
335 my $prospect_main = $qual->cust_or_prospect;
336 $prospectnum = $prospect_main->prospectnum
337 or die "qualification not on a prospect";
339 $cust_main->agentnum( $prospect_main->agentnum );
340 $cust_main->company( $prospect_main->company );
342 #first contact? -> name
343 my @contacts = $prospect_main->contact;
344 my $contact = $contacts[0];
345 $cust_main->first( $contact->first );
346 $cust_main->set( 'last', $contact->get('last') );
347 #contact phone numbers?
349 #location -> address (all prospect quals have location, right?)
350 my $cust_location = $qual->cust_location;
351 $cust_location->dealternize;
352 $cust_main->$_( $cust_location->$_ )
353 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
355 #locationnum -> package order
356 $locationnum = $qual->locationnum;
358 #pkgpart handled by lock_pkgpart below
360 #service telephone & vendor_qual_id -> svc_dsl
361 $svc_dsl{$_} = $qual->$_
362 foreach qw( phonenum vendor_qual_id );
365 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
367 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
368 or die "unknown pkgpart $pkgpart";
369 my $svcpart = $part_pkg->svcpart;
370 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
375 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
376 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
378 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
380 $title .= ": ". $cust_main->name if $custnum;
382 my $r = qq!<font color="#ff0000">*</font> !;