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 $m->comp('/elements/handle_uri_query', 'secure'=>1);
246 if ( $cgi->param('error') ) {
248 $cust_main = new FS::cust_main ( {
249 map { $_, scalar($cgi->param($_)) } fields('cust_main')
252 $custnum = $cust_main->custnum;
255 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
257 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
258 $same = $cgi->param('same');
259 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
260 $ss = $cust_main->ss; # don't mask an entered value on errors
261 $stateid = $cust_main->stateid; # don't mask an entered value on errors
262 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
264 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
266 $prospectnum = $cgi->param('prospectnum') || '';
268 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
270 $locationnum = $cgi->param('locationnum') || '';
273 $username = $cgi->param('username');
274 $password = $cgi->param('_password');
275 $popnum = $cgi->param('popnum');
276 $saved_domsvc = $cgi->param('domsvc') || '';
277 if ( $saved_domsvc =~ /^(\d+)$/ ) {
284 $svc_phone{$_} = $cgi->param($_)
285 foreach qw( countrycode phonenum sip_password pin phone_name );
287 #svc_dsl (phonenum came in with svc_phone)
288 $svc_phone{$_} = $cgi->param($_)
289 foreach qw( password isp_chg isp_prev vendor_qual_id );
291 } elsif ( $cgi->keywords ) { #editing
294 unless $curuser->access_right('Edit customer');
296 my( $query ) = $cgi->keywords;
299 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
300 or die "custnum $custnum not found";
301 if ( $cust_main->dbdef_table->column('paycvv')
302 && length($cust_main->paycvv) ) {
303 my $paycvv = $cust_main->paycvv;
305 $cust_main->paycvv($paycvv);
307 @invoicing_list = $cust_main->invoicing_list;
308 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
309 $stateid = $cust_main->masked('stateid');
310 $payinfo = $cust_main->paymask;
312 } else { #new customer
315 unless $curuser->access_right('New customer');
318 $cust_main = new FS::cust_main ( {} );
319 $cust_main->agentnum( $conf->config('default_agentnum') )
320 if $conf->exists('default_agentnum');
321 $cust_main->otaker( &getotaker );
322 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
323 @invoicing_list = ();
324 push @invoicing_list, 'POST'
325 unless $conf->exists('disablepostalinvoicedefault');
330 $cgi->param('tagnum', FS::part_tag->default_tags);
332 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
334 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
335 or die "unknown qualnum $qualnum";
337 my $prospect_main = $qual->cust_or_prospect;
338 $prospectnum = $prospect_main->prospectnum
339 or die "qualification not on a prospect";
341 $cust_main->agentnum( $prospect_main->agentnum );
342 $cust_main->company( $prospect_main->company );
344 #first contact? -> name
345 my @contacts = $prospect_main->contact;
346 my $contact = $contacts[0];
347 $cust_main->first( $contact->first );
348 $cust_main->set( 'last', $contact->get('last') );
349 #contact phone numbers?
351 #location -> address (all prospect quals have location, right?)
352 my $cust_location = $qual->cust_location;
353 $cust_location->dealternize;
354 $cust_main->$_( $cust_location->$_ )
355 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
357 #locationnum -> package order
358 $locationnum = $qual->locationnum;
360 #pkgpart handled by lock_pkgpart below
362 #service telephone & vendor_qual_id -> svc_dsl
363 $svc_dsl{$_} = $qual->$_
364 foreach qw( phonenum vendor_qual_id );
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> !;