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->exists('cust_main-enable_birthdate') ) {
31 <& cust_main/birthdate.html, $cust_main &>
34 %# latitude and longitude
35 % if ( $conf->exists('cust_main-require_censustract') ) {
36 % my ($latitude, $longitude) = $cust_main->service_coordinates;
37 % $latitude ||= $conf->config('company_latitude') || '';
38 % $longitude ||= $conf->config('company_longitude') || '';
39 <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
40 <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
45 % my $same_checked = '';
46 % my $ship_disabled = '';
47 % my @ship_style = ();
48 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
49 % $same_checked = 'CHECKED';
50 % $ship_disabled = 'DISABLED';
51 % push @ship_style, 'background-color:#dddddd';
53 % qw( last first company address1 address2 city county state zip country
54 % daytime night fax mobile )
56 % $cust_main->set("ship_$_", $cust_main->get($_) );
61 <FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
63 <& cust_main/contact.html,
64 'cust_main' => $cust_main,
66 'onchange' => 'bill_changed(this)',
69 'stateid' => $stateid,
70 'same_checked' => $same_checked, #for address2 "Unit #" labeling
74 function bill_changed(what) {
75 if ( what.form.same.checked ) {
76 % for (qw( last first company address1 address2 city zip daytime night fax mobile )) {
77 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
80 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
82 function fix_ship_city() {
83 what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
84 what.form.ship_city.style.display = what.form.city.style.display;
85 what.form.ship_city_select.style.display = what.form.city_select.style.display;
88 function fix_ship_county() {
89 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
90 ship_county_changed(what.form.ship_county, fix_ship_city );
93 function fix_ship_state() {
94 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
95 ship_state_changed(what.form.ship_state, fix_ship_county );
98 ship_country_changed(what.form.ship_country, fix_ship_state );
102 function samechanged(what) {
103 if ( what.checked ) {
106 % my @fields = qw( last first company address1 address2 city city_select county state zip country daytime night fax mobile );
108 what.form.ship_<%$_%>.disabled = true;
109 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
112 % if ( $conf->exists('cust_main-require_address2') ) {
113 document.getElementById('address2_required').style.visibility = '';
114 document.getElementById('address2_label').style.visibility = '';
115 document.getElementById('ship_address2_required').style.visibility = 'hidden';
116 document.getElementById('ship_address2_label').style.visibility = 'hidden';
122 what.form.ship_<%$_%>.disabled = false;
123 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
126 % if ( $conf->exists('cust_main-require_address2') ) {
127 document.getElementById('address2_required').style.visibility = 'hidden';
128 document.getElementById('address2_label').style.visibility = 'hidden';
129 document.getElementById('ship_address2_required').style.visibility = '';
130 document.getElementById('ship_address2_label').style.visibility = '';
138 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
140 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
141 <& cust_main/contact.html,
142 'cust_main' => $cust_main,
145 'disabled' => $ship_disabled,
146 'style' => \@ship_style
150 <& cust_main/billing.html, $cust_main,
151 'payinfo' => $payinfo,
152 'invoicing_list' => \@invoicing_list,
155 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
156 % if (!$ro_comments || $cust_main->comments) {
158 <BR><% mt('Comments') |h %>
159 <% &ntable("#cccccc") %>
162 <TEXTAREA NAME = "comments"
167 ><% $cust_main->comments %></TEXTAREA>
174 % unless ( $custnum ) {
176 <& cust_main/first_pkg.html, $cust_main,
177 'pkgpart_svcpart' => $pkgpart_svcpart,
179 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
180 'username' => $username,
181 'password' => $password,
183 'saved_domsvc' => $saved_domsvc,
190 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
192 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
194 %# cust_main/bottomfixup.js
195 % foreach my $hidden (
197 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
198 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
199 % 'paystart_month', 'paystart_year', 'payissue',
203 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
206 <& cust_main/bottomfixup.html &>
209 <INPUT TYPE = "button"
210 NAME = "submitButton"
212 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
213 onClick = "this.disabled=true; bottomfixup(this.form);"
217 <& /elements/footer.html &>
221 my $curuser = $FS::CurrentUser::CurrentUser;
223 #probably redundant given the checks below...
225 unless $curuser->access_right('New customer')
226 || $curuser->access_right('Edit customer');
228 my $conf = new FS::Conf;
232 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
234 my $pkgpart_svcpart = ''; #first_pkg
235 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
238 my $prospectnum = '';
239 my $locationnum = '';
241 if ( $cgi->param('error') ) {
243 $cust_main = new FS::cust_main ( {
244 map { $_, scalar($cgi->param($_)) } fields('cust_main')
247 $custnum = $cust_main->custnum;
250 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
252 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
253 $same = $cgi->param('same');
254 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
255 $ss = $cust_main->ss; # don't mask an entered value on errors
256 $stateid = $cust_main->stateid; # don't mask an entered value on errors
257 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
259 $prospectnum = $cgi->param('prospectnum') || '';
261 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
263 $locationnum = $cgi->param('locationnum') || '';
266 $username = $cgi->param('username');
267 $password = $cgi->param('_password');
268 $popnum = $cgi->param('popnum');
269 $saved_domsvc = $cgi->param('domsvc') || '';
270 if ( $saved_domsvc =~ /^(\d+)$/ ) {
277 $svc_phone{$_} = $cgi->param($_)
278 foreach qw( countrycode phonenum sip_password pin phone_name );
280 #svc_dsl (phonenum came in with svc_phone)
281 $svc_phone{$_} = $cgi->param($_)
282 foreach qw( password isp_chg isp_prev vendor_qual_id );
284 } elsif ( $cgi->keywords ) { #editing
287 unless $curuser->access_right('Edit customer');
289 my( $query ) = $cgi->keywords;
292 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
293 if ( $cust_main->dbdef_table->column('paycvv')
294 && length($cust_main->paycvv) ) {
295 my $paycvv = $cust_main->paycvv;
297 $cust_main->paycvv($paycvv);
299 @invoicing_list = $cust_main->invoicing_list;
300 $ss = $cust_main->masked('ss');
301 $stateid = $cust_main->masked('stateid');
302 $payinfo = $cust_main->paymask;
304 } else { #new customer
307 unless $curuser->access_right('New customer');
310 $cust_main = new FS::cust_main ( {} );
311 $cust_main->agentnum( $conf->config('default_agentnum') )
312 if $conf->exists('default_agentnum');
313 $cust_main->otaker( &getotaker );
314 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
315 @invoicing_list = ();
316 push @invoicing_list, 'POST'
317 unless $conf->exists('disablepostalinvoicedefault');
322 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
324 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
325 or die "unknown qualnum $qualnum";
327 my $prospect_main = $qual->cust_or_prospect;
328 $prospectnum = $prospect_main->prospectnum
329 or die "qualification not on a prospect";
331 $cust_main->agentnum( $prospect_main->agentnum );
332 $cust_main->company( $prospect_main->company );
334 #first contact? -> name
335 my @contacts = $prospect_main->contact;
336 my $contact = $contacts[0];
337 $cust_main->first( $contact->first );
338 $cust_main->set( 'last', $contact->get('last') );
339 #contact phone numbers?
341 #location -> address (all prospect quals have location, right?)
342 my $cust_location = $qual->cust_location;
343 $cust_location->dealternize;
344 $cust_main->$_( $cust_location->$_ )
345 foreach qw( address1 address2 city county state zip country geocode );
347 #locationnum -> package order
348 $locationnum = $qual->locationnum;
350 #pkgpart handled by lock_pkgpart below
352 #service telephone & vendor_qual_id -> svc_dsl
353 $svc_dsl{$_} = $qual->$_
354 foreach qw( phonenum vendor_qual_id );
357 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
359 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
360 or die "unknown pkgpart $pkgpart";
361 my $svcpart = $part_pkg->svcpart;
362 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
367 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
368 $cgi->delete( grep !$keep{$_}, $cgi->param );
370 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
372 $title .= ": ". $cust_main->name if $custnum;
374 my $r = qq!<font color="#ff0000">*</font> !;