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 &>
36 % my $same_checked = '';
37 % my $ship_disabled = '';
38 % my @ship_style = ();
39 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
40 % $same_checked = 'CHECKED';
41 % $ship_disabled = 'DISABLED';
42 % push @ship_style, 'background-color:#dddddd';
44 % qw( last first company address1 address2 city county state zip country
45 % latitude longitude coord_auto
46 % daytime night fax mobile )
48 % $cust_main->set("ship_$_", $cust_main->get($_) );
53 <FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
55 <& cust_main/contact.html,
56 'cust_main' => $cust_main,
58 'onchange' => 'bill_changed(this)',
61 'stateid' => $stateid,
62 'same_checked' => $same_checked, #for address2 "Unit #" labeling
66 function bill_changed(what) {
67 if ( what.form.same.checked ) {
68 % for (qw( last first company address1 address2 city zip latitude longitude coord_auto daytime night fax mobile )) {
69 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
72 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
74 function fix_ship_city() {
75 what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
76 what.form.ship_city.style.display = what.form.city.style.display;
77 what.form.ship_city_select.style.display = what.form.city_select.style.display;
80 function fix_ship_county() {
81 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
82 ship_county_changed(what.form.ship_county, fix_ship_city );
85 function fix_ship_state() {
86 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
87 ship_state_changed(what.form.ship_state, fix_ship_county );
90 ship_country_changed(what.form.ship_country, fix_ship_state );
94 function samechanged(what) {
98 % my @fields = qw( last first company address1 address2 city city_select county state zip country latitude longitude daytime night fax mobile );
100 what.form.ship_<%$_%>.disabled = true;
101 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
104 % if ( $conf->exists('cust_main-require_address2') ) {
105 document.getElementById('address2_required').style.visibility = '';
106 document.getElementById('address2_label').style.visibility = '';
107 document.getElementById('ship_address2_required').style.visibility = 'hidden';
108 document.getElementById('ship_address2_label').style.visibility = 'hidden';
114 what.form.ship_<%$_%>.disabled = false;
115 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
118 % if ( $conf->exists('cust_main-require_address2') ) {
119 document.getElementById('address2_required').style.visibility = 'hidden';
120 document.getElementById('address2_label').style.visibility = 'hidden';
121 document.getElementById('ship_address2_required').style.visibility = '';
122 document.getElementById('ship_address2_label').style.visibility = '';
130 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
132 <INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>
133 <& cust_main/contact.html,
134 'cust_main' => $cust_main,
137 'disabled' => $ship_disabled,
138 'style' => \@ship_style
141 <& cust_main/contacts_new.html,
142 'cust_main' => $cust_main,
146 <& cust_main/billing.html, $cust_main,
147 'payinfo' => $payinfo,
148 'invoicing_list' => \@invoicing_list,
152 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
153 % if (!$ro_comments || $cust_main->comments) {
156 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
157 <TABLE CLASS="fsinnerbox">
160 <TEXTAREA NAME = "comments"
165 ><% $cust_main->comments %></TEXTAREA>
172 % unless ( $custnum ) {
174 <& cust_main/first_pkg.html, $cust_main,
175 'pkgpart_svcpart' => $pkgpart_svcpart,
177 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
178 'username' => $username,
179 'password' => $password,
181 'saved_domsvc' => $saved_domsvc,
188 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
190 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
192 %# cust_main/bottomfixup.js
193 % foreach my $hidden (
194 % 'payauto', 'billday',
195 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
196 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
197 % 'paystart_month', 'paystart_year', 'payissue',
201 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
204 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
207 <INPUT TYPE = "button"
208 NAME = "submitButton"
210 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
211 onClick = "this.disabled=true; bottomfixup(this.form);"
216 <& /elements/footer.html &>
220 my $curuser = $FS::CurrentUser::CurrentUser;
222 #probably redundant given the checks below...
224 unless $curuser->access_right('New customer')
225 || $curuser->access_right('Edit customer');
227 my $conf = new FS::Conf;
231 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
233 my $pkgpart_svcpart = ''; #first_pkg
234 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
237 my $prospectnum = '';
238 my $locationnum = '';
240 if ( $cgi->param('error') ) {
242 $cust_main = new FS::cust_main ( {
243 map { $_, scalar($cgi->param($_)) } fields('cust_main')
246 $custnum = $cust_main->custnum;
249 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
251 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
252 $same = $cgi->param('same');
253 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
254 $ss = $cust_main->ss; # don't mask an entered value on errors
255 $stateid = $cust_main->stateid; # don't mask an entered value on errors
256 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
258 $prospectnum = $cgi->param('prospectnum') || '';
260 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
262 $locationnum = $cgi->param('locationnum') || '';
265 $username = $cgi->param('username');
266 $password = $cgi->param('_password');
267 $popnum = $cgi->param('popnum');
268 $saved_domsvc = $cgi->param('domsvc') || '';
269 if ( $saved_domsvc =~ /^(\d+)$/ ) {
276 $svc_phone{$_} = $cgi->param($_)
277 foreach qw( countrycode phonenum sip_password pin phone_name );
279 #svc_dsl (phonenum came in with svc_phone)
280 $svc_phone{$_} = $cgi->param($_)
281 foreach qw( password isp_chg isp_prev vendor_qual_id );
283 } elsif ( $cgi->keywords ) { #editing
286 unless $curuser->access_right('Edit customer');
288 my( $query ) = $cgi->keywords;
291 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
292 if ( $cust_main->dbdef_table->column('paycvv')
293 && length($cust_main->paycvv) ) {
294 my $paycvv = $cust_main->paycvv;
296 $cust_main->paycvv($paycvv);
298 @invoicing_list = $cust_main->invoicing_list;
299 $ss = $cust_main->masked('ss');
300 $stateid = $cust_main->masked('stateid');
301 $payinfo = $cust_main->paymask;
303 } else { #new customer
306 unless $curuser->access_right('New customer');
309 $cust_main = new FS::cust_main ( {} );
310 $cust_main->agentnum( $conf->config('default_agentnum') )
311 if $conf->exists('default_agentnum');
312 $cust_main->otaker( &getotaker );
313 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
314 @invoicing_list = ();
315 push @invoicing_list, 'POST'
316 unless $conf->exists('disablepostalinvoicedefault');
321 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
323 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
324 or die "unknown qualnum $qualnum";
326 my $prospect_main = $qual->cust_or_prospect;
327 $prospectnum = $prospect_main->prospectnum
328 or die "qualification not on a prospect";
330 $cust_main->agentnum( $prospect_main->agentnum );
331 $cust_main->company( $prospect_main->company );
333 #first contact? -> name
334 my @contacts = $prospect_main->contact;
335 my $contact = $contacts[0];
336 $cust_main->first( $contact->first );
337 $cust_main->set( 'last', $contact->get('last') );
338 #contact phone numbers?
340 #location -> address (all prospect quals have location, right?)
341 my $cust_location = $qual->cust_location;
342 $cust_location->dealternize;
343 $cust_main->$_( $cust_location->$_ )
344 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
346 #locationnum -> package order
347 $locationnum = $qual->locationnum;
349 #pkgpart handled by lock_pkgpart below
351 #service telephone & vendor_qual_id -> svc_dsl
352 $svc_dsl{$_} = $qual->$_
353 foreach qw( phonenum vendor_qual_id );
356 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
358 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
359 or die "unknown pkgpart $pkgpart";
360 my $svcpart = $part_pkg->svcpart;
361 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
366 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
367 $cgi->delete( grep !$keep{$_}, $cgi->param );
369 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
371 $title .= ": ". $cust_main->name if $custnum;
373 my $r = qq!<font color="#ff0000">*</font> !;