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')
30 % || $conf->exists('cust_main-enable_spouse_birthdate')
34 <& cust_main/birthdate.html, $cust_main &>
39 % my $same_checked = '';
40 % my $ship_disabled = '';
41 % my @ship_style = ();
42 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
43 % $same_checked = 'CHECKED';
44 % $ship_disabled = 'DISABLED';
45 % push @ship_style, 'background-color:#dddddd';
47 % qw( last first company address1 address2 city county state zip country
48 % latitude longitude coord_auto
49 % daytime night fax mobile )
51 % $cust_main->set("ship_$_", $cust_main->get($_) );
56 <FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
58 <& cust_main/contact.html,
59 'cust_main' => $cust_main,
61 'onchange' => 'bill_changed(this)',
64 'stateid' => $stateid,
65 'same_checked' => $same_checked, #for address2 "Unit #" labeling
69 function bill_changed(what) {
70 if ( what.form.same.checked ) {
71 % for (qw( last first company address1 address2 city zip latitude longitude coord_auto daytime night fax mobile )) {
72 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
75 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
77 function fix_ship_city() {
78 what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
79 what.form.ship_city.style.display = what.form.city.style.display;
80 what.form.ship_city_select.style.display = what.form.city_select.style.display;
83 function fix_ship_county() {
84 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
85 ship_county_changed(what.form.ship_county, fix_ship_city );
88 function fix_ship_state() {
89 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
90 ship_state_changed(what.form.ship_state, fix_ship_county );
93 ship_country_changed(what.form.ship_country, fix_ship_state );
97 function samechanged(what) {
101 % my @fields = qw( last first company address1 address2 city city_select county state zip country latitude longitude daytime night fax mobile );
103 what.form.ship_<%$_%>.disabled = true;
104 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
107 % if ( $conf->exists('cust_main-require_address2') ) {
108 document.getElementById('address2_required').style.visibility = '';
109 document.getElementById('address2_label').style.visibility = '';
110 document.getElementById('ship_address2_required').style.visibility = 'hidden';
111 document.getElementById('ship_address2_label').style.visibility = 'hidden';
117 what.form.ship_<%$_%>.disabled = false;
118 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
121 % if ( $conf->exists('cust_main-require_address2') ) {
122 document.getElementById('address2_required').style.visibility = 'hidden';
123 document.getElementById('address2_label').style.visibility = 'hidden';
124 document.getElementById('ship_address2_required').style.visibility = '';
125 document.getElementById('ship_address2_label').style.visibility = '';
133 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
135 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
136 <& cust_main/contact.html,
137 'cust_main' => $cust_main,
140 'disabled' => $ship_disabled,
141 'style' => \@ship_style
145 <& cust_main/billing.html, $cust_main,
146 'payinfo' => $payinfo,
147 'invoicing_list' => \@invoicing_list,
150 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
151 % if (!$ro_comments || $cust_main->comments) {
153 <BR><% mt('Comments') |h %>
154 <% &ntable("#cccccc") %>
157 <TEXTAREA NAME = "comments"
162 ><% $cust_main->comments %></TEXTAREA>
169 % unless ( $custnum ) {
171 <& cust_main/first_pkg.html, $cust_main,
172 'pkgpart_svcpart' => $pkgpart_svcpart,
174 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
175 'username' => $username,
176 'password' => $password,
178 'saved_domsvc' => $saved_domsvc,
185 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
187 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
189 %# cust_main/bottomfixup.js
190 % foreach my $hidden (
191 % 'payauto', 'billday',
192 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
193 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
194 % 'paystart_month', 'paystart_year', 'payissue',
198 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
201 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
204 <INPUT TYPE = "button"
205 NAME = "submitButton"
207 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
208 onClick = "this.disabled=true; bottomfixup(this.form);"
212 <& /elements/footer.html &>
216 my $curuser = $FS::CurrentUser::CurrentUser;
218 #probably redundant given the checks below...
220 unless $curuser->access_right('New customer')
221 || $curuser->access_right('Edit customer');
223 my $conf = new FS::Conf;
227 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
229 my $pkgpart_svcpart = ''; #first_pkg
230 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
233 my $prospectnum = '';
234 my $locationnum = '';
236 if ( $cgi->param('error') ) {
238 $cust_main = new FS::cust_main ( {
239 map { $_, scalar($cgi->param($_)) } fields('cust_main')
242 $custnum = $cust_main->custnum;
245 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
247 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
248 $same = $cgi->param('same');
249 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
250 $ss = $cust_main->ss; # don't mask an entered value on errors
251 $stateid = $cust_main->stateid; # don't mask an entered value on errors
252 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
254 $prospectnum = $cgi->param('prospectnum') || '';
256 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
258 $locationnum = $cgi->param('locationnum') || '';
261 $username = $cgi->param('username');
262 $password = $cgi->param('_password');
263 $popnum = $cgi->param('popnum');
264 $saved_domsvc = $cgi->param('domsvc') || '';
265 if ( $saved_domsvc =~ /^(\d+)$/ ) {
272 $svc_phone{$_} = $cgi->param($_)
273 foreach qw( countrycode phonenum sip_password pin phone_name );
275 #svc_dsl (phonenum came in with svc_phone)
276 $svc_phone{$_} = $cgi->param($_)
277 foreach qw( password isp_chg isp_prev vendor_qual_id );
279 } elsif ( $cgi->keywords ) { #editing
282 unless $curuser->access_right('Edit customer');
284 my( $query ) = $cgi->keywords;
287 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
288 if ( $cust_main->dbdef_table->column('paycvv')
289 && length($cust_main->paycvv) ) {
290 my $paycvv = $cust_main->paycvv;
292 $cust_main->paycvv($paycvv);
294 @invoicing_list = $cust_main->invoicing_list;
295 $ss = $cust_main->masked('ss');
296 $stateid = $cust_main->masked('stateid');
297 $payinfo = $cust_main->paymask;
299 } else { #new customer
302 unless $curuser->access_right('New customer');
305 $cust_main = new FS::cust_main ( {} );
306 $cust_main->agentnum( $conf->config('default_agentnum') )
307 if $conf->exists('default_agentnum');
308 $cust_main->otaker( &getotaker );
309 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
310 @invoicing_list = ();
311 push @invoicing_list, 'POST'
312 unless $conf->exists('disablepostalinvoicedefault');
317 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
319 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
320 or die "unknown qualnum $qualnum";
322 my $prospect_main = $qual->cust_or_prospect;
323 $prospectnum = $prospect_main->prospectnum
324 or die "qualification not on a prospect";
326 $cust_main->agentnum( $prospect_main->agentnum );
327 $cust_main->company( $prospect_main->company );
329 #first contact? -> name
330 my @contacts = $prospect_main->contact;
331 my $contact = $contacts[0];
332 $cust_main->first( $contact->first );
333 $cust_main->set( 'last', $contact->get('last') );
334 #contact phone numbers?
336 #location -> address (all prospect quals have location, right?)
337 my $cust_location = $qual->cust_location;
338 $cust_location->dealternize;
339 $cust_main->$_( $cust_location->$_ )
340 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
342 #locationnum -> package order
343 $locationnum = $qual->locationnum;
345 #pkgpart handled by lock_pkgpart below
347 #service telephone & vendor_qual_id -> svc_dsl
348 $svc_dsl{$_} = $qual->$_
349 foreach qw( phonenum vendor_qual_id );
352 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
354 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
355 or die "unknown pkgpart $pkgpart";
356 my $svcpart = $part_pkg->svcpart;
357 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
362 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
363 $cgi->delete( grep !$keep{$_}, $cgi->param );
365 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
367 $title .= ": ". $cust_main->name if $custnum;
369 my $r = qq!<font color="#ff0000">*</font> !;