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 SIZE="+1"><B><% mt('Billing address') |h %></B></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 SIZE="+1"><B><% mt('Service address') |h %></B></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
142 <& cust_main/billing.html, $cust_main,
143 'payinfo' => $payinfo,
144 'invoicing_list' => \@invoicing_list,
147 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
148 % if (!$ro_comments || $cust_main->comments) {
150 <BR><% mt('Comments') |h %>
151 <% &ntable("#cccccc") %>
154 <TEXTAREA NAME = "comments"
159 ><% $cust_main->comments %></TEXTAREA>
166 % unless ( $custnum ) {
168 <& cust_main/first_pkg.html, $cust_main,
169 'pkgpart_svcpart' => $pkgpart_svcpart,
171 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
172 'username' => $username,
173 'password' => $password,
175 'saved_domsvc' => $saved_domsvc,
182 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
184 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
186 %# cust_main/bottomfixup.js
187 % foreach my $hidden (
188 % 'payauto', 'billday',
189 % 'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
190 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
191 % 'paystart_month', 'paystart_year', 'payissue',
195 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
198 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
201 <INPUT TYPE = "button"
202 NAME = "submitButton"
204 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
205 onClick = "this.disabled=true; bottomfixup(this.form);"
209 <& /elements/footer.html &>
213 my $curuser = $FS::CurrentUser::CurrentUser;
215 #probably redundant given the checks below...
217 unless $curuser->access_right('New customer')
218 || $curuser->access_right('Edit customer');
220 my $conf = new FS::Conf;
224 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
226 my $pkgpart_svcpart = ''; #first_pkg
227 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
230 my $prospectnum = '';
231 my $locationnum = '';
233 if ( $cgi->param('error') ) {
235 $cust_main = new FS::cust_main ( {
236 map { $_, scalar($cgi->param($_)) } fields('cust_main')
239 $custnum = $cust_main->custnum;
242 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
244 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
245 $same = $cgi->param('same');
246 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
247 $ss = $cust_main->ss; # don't mask an entered value on errors
248 $stateid = $cust_main->stateid; # don't mask an entered value on errors
249 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
251 $prospectnum = $cgi->param('prospectnum') || '';
253 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
255 $locationnum = $cgi->param('locationnum') || '';
258 $username = $cgi->param('username');
259 $password = $cgi->param('_password');
260 $popnum = $cgi->param('popnum');
261 $saved_domsvc = $cgi->param('domsvc') || '';
262 if ( $saved_domsvc =~ /^(\d+)$/ ) {
269 $svc_phone{$_} = $cgi->param($_)
270 foreach qw( countrycode phonenum sip_password pin phone_name );
272 #svc_dsl (phonenum came in with svc_phone)
273 $svc_phone{$_} = $cgi->param($_)
274 foreach qw( password isp_chg isp_prev vendor_qual_id );
276 } elsif ( $cgi->keywords ) { #editing
279 unless $curuser->access_right('Edit customer');
281 my( $query ) = $cgi->keywords;
284 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
285 if ( $cust_main->dbdef_table->column('paycvv')
286 && length($cust_main->paycvv) ) {
287 my $paycvv = $cust_main->paycvv;
289 $cust_main->paycvv($paycvv);
291 @invoicing_list = $cust_main->invoicing_list;
292 $ss = $cust_main->masked('ss');
293 $stateid = $cust_main->masked('stateid');
294 $payinfo = $cust_main->paymask;
296 } else { #new customer
299 unless $curuser->access_right('New customer');
302 $cust_main = new FS::cust_main ( {} );
303 $cust_main->agentnum( $conf->config('default_agentnum') )
304 if $conf->exists('default_agentnum');
305 $cust_main->otaker( &getotaker );
306 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
307 @invoicing_list = ();
308 push @invoicing_list, 'POST'
309 unless $conf->exists('disablepostalinvoicedefault');
314 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
316 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
317 or die "unknown qualnum $qualnum";
319 my $prospect_main = $qual->cust_or_prospect;
320 $prospectnum = $prospect_main->prospectnum
321 or die "qualification not on a prospect";
323 $cust_main->agentnum( $prospect_main->agentnum );
324 $cust_main->company( $prospect_main->company );
326 #first contact? -> name
327 my @contacts = $prospect_main->contact;
328 my $contact = $contacts[0];
329 $cust_main->first( $contact->first );
330 $cust_main->set( 'last', $contact->get('last') );
331 #contact phone numbers?
333 #location -> address (all prospect quals have location, right?)
334 my $cust_location = $qual->cust_location;
335 $cust_location->dealternize;
336 $cust_main->$_( $cust_location->$_ )
337 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
339 #locationnum -> package order
340 $locationnum = $qual->locationnum;
342 #pkgpart handled by lock_pkgpart below
344 #service telephone & vendor_qual_id -> svc_dsl
345 $svc_dsl{$_} = $qual->$_
346 foreach qw( phonenum vendor_qual_id );
349 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
351 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
352 or die "unknown pkgpart $pkgpart";
353 my $svcpart = $part_pkg->svcpart;
354 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
359 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
360 $cgi->delete( grep !$keep{$_}, $cgi->param );
362 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
364 $title .= ": ". $cust_main->name if $custnum;
366 my $r = qq!<font color="#ff0000">*</font> !;