1 <% include('/elements/header.html',
4 ' onUnload="myclose()"' #hmm, in billing.html
7 <% include('/elements/error.html') %>
9 <FORM NAME = "CustomerForm"
11 ACTION = "<% popurl(1) %>process/cust_main.cgi"
12 %# STYLE = "margin-bottom: 0"
13 %# STYLE="margin-top: 0; margin-bottom: 0">
16 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
19 Customer #<B><% $cust_main->display_custnum %></B> -
20 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
21 <% ucfirst($cust_main->status) %>
26 %# agent, agent_custid, refnum (advertising source), referral_custnum
27 <% include('cust_main/top_misc.html', $cust_main, 'custnum' => $custnum ) %>
30 % if ( $conf->exists('cust_main-enable_birthdate') ) {
32 <% include('cust_main/birthdate.html', $cust_main) %>
35 %# latitude and longitude
36 % if ( $conf->exists('cust_main-require_censustract') ) {
37 % my ($latitude, $longitude) = $cust_main->service_coordinates;
38 % $latitude ||= $conf->config('company_latitude') || '';
39 % $longitude ||= $conf->config('company_longitude') || '';
40 <INPUT NAME="latitude" TYPE="hidden" VALUE="<% $latitude |h %>">
41 <INPUT NAME="longitude" TYPE="hidden" VALUE="<% $longitude |h %>">
46 % my $same_checked = '';
47 % my $ship_disabled = '';
48 % unless ( $cust_main->ship_last && $same ne 'Y' ) {
49 % $same_checked = 'CHECKED';
50 % $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
52 % qw( last first company address1 address2 city county state zip country
55 % $cust_main->set("ship_$_", $cust_main->get($_) );
60 <FONT SIZE="+1"><B>Billing address</B></FONT>
62 <% include('cust_main/contact.html',
63 'cust_main' => $cust_main,
65 'onchange' => 'bill_changed(this)',
68 'stateid' => $stateid,
69 '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 )) {
78 what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
81 what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
83 function fix_ship_county() {
84 what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
87 function fix_ship_state() {
88 what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
89 ship_state_changed(what.form.ship_state, fix_ship_county );
92 ship_country_changed(what.form.ship_country, fix_ship_state );
96 function samechanged(what) {
100 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
101 what.form.ship_<%$_%>.disabled = true;
102 what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
105 % if ( $conf->exists('cust_main-require_address2') ) {
106 document.getElementById('address2_required').style.visibility = '';
107 document.getElementById('address2_label').style.visibility = '';
108 document.getElementById('ship_address2_required').style.visibility = 'hidden';
109 document.getElementById('ship_address2_label').style.visibility = 'hidden';
114 % for (qw( last first company address1 address2 city county state zip country daytime night fax )) {
115 what.form.ship_<%$_%>.disabled = false;
116 what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
119 % if ( $conf->exists('cust_main-require_address2') ) {
120 document.getElementById('address2_required').style.visibility = 'hidden';
121 document.getElementById('address2_label').style.visibility = 'hidden';
122 document.getElementById('ship_address2_required').style.visibility = '';
123 document.getElementById('ship_address2_label').style.visibility = '';
131 <FONT SIZE="+1"><B>Service address</B></FONT>
133 (<INPUT TYPE="checkbox" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>>same as billing address)
134 <% include('cust_main/contact.html',
135 'cust_main' => $cust_main,
138 'disabled' => $ship_disabled,
143 <% include( 'cust_main/billing.html', $cust_main,
144 'payinfo' => $payinfo,
145 'invoicing_list' => \@invoicing_list,
149 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
150 % if (!$ro_comments || $cust_main->comments) {
153 <% &ntable("#cccccc") %>
156 <TEXTAREA NAME = "comments"
161 ><% $cust_main->comments %></TEXTAREA>
168 % unless ( $custnum ) {
170 <% include('cust_main/first_pkg.html', $cust_main,
171 'pkgpart_svcpart' => $pkgpart_svcpart,
173 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
175 'username' => $username,
176 'password' => $password,
178 'saved_domsvc' => $saved_domsvc,
185 <INPUT TYPE="hidden" NAME="otaker" VALUE="<% $cust_main->otaker %>">
187 %# cust_main/bottomfixup.js
188 % foreach my $hidden (
190 % 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
191 % 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
192 % 'paystart_month', 'paystart_year', 'payissue',
196 <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
199 <% include('cust_main/bottomfixup.html') %>
202 <INPUT TYPE = "button"
203 NAME = "submitButton"
205 VALUE = "<% $custnum ? "Apply Changes" : "Add Customer" %>"
206 onClick = "this.disabled=true; bottomfixup(this.form);"
210 <% include('/elements/footer.html') %>
214 my $curuser = $FS::CurrentUser::CurrentUser;
216 #probably redundant given the checks below...
218 unless $curuser->access_right('New customer')
219 || $curuser->access_right('Edit customer');
221 my $conf = new FS::Conf;
225 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
227 my $pkgpart_svcpart = ''; #first_pkg
228 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
231 if ( $cgi->param('error') ) {
233 $cust_main = new FS::cust_main ( {
234 map { $_, scalar($cgi->param($_)) } fields('cust_main')
237 $custnum = $cust_main->custnum;
240 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
242 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
243 $same = $cgi->param('same');
244 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
245 $ss = $cust_main->ss; # don't mask an entered value on errors
246 $stateid = $cust_main->stateid; # don't mask an entered value on errors
247 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
249 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
252 $username = $cgi->param('username');
253 $password = $cgi->param('_password');
254 $popnum = $cgi->param('popnum');
255 $saved_domsvc = $cgi->param('domsvc') || '';
256 if ( $saved_domsvc =~ /^(\d+)$/ ) {
263 $svc_phone{$_} = $cgi->param($_)
264 foreach qw( countrycode phonenum sip_password pin phone_name );
266 } elsif ( $cgi->keywords ) { #editing
269 unless $curuser->access_right('Edit customer');
271 my( $query ) = $cgi->keywords;
274 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
275 if ( $cust_main->dbdef_table->column('paycvv')
276 && length($cust_main->paycvv) ) {
277 my $paycvv = $cust_main->paycvv;
279 $cust_main->paycvv($paycvv);
281 @invoicing_list = $cust_main->invoicing_list;
282 $ss = $cust_main->masked('ss');
283 $stateid = $cust_main->masked('stateid');
284 $payinfo = $cust_main->paymask;
286 } else { #new customer
289 unless $curuser->access_right('New customer');
292 $cust_main = new FS::cust_main ( {} );
293 $cust_main->otaker( &getotaker );
294 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
295 @invoicing_list = ();
296 push @invoicing_list, 'POST'
297 unless $conf->exists('disablepostalinvoicedefault');
302 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
304 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
305 or die "unknown pkgpart $pkgpart";
306 my $svcpart = $part_pkg->svcpart;
307 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
312 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
313 $cgi->delete( grep !$keep{$_}, $cgi->param );
315 my $action = $custnum ? 'Edit' : 'Add';
316 $action .= ": ". $cust_main->name if $custnum;
318 my $r = qq!<font color="#ff0000">*</font> !;