1 <& /elements/header.html, $title, &>
3 <& /elements/error.html &>
5 <FORM NAME = "CustomerForm"
7 ACTION = "<% popurl(1) %>process/cust_main.cgi"
10 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
11 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
14 <% mt('Customer #') |h %><B><% $cust_main->display_custnum %></B> -
15 <B><FONT COLOR="#<% $cust_main->statuscolor %>">
16 <% $cust_main->status_label %>
21 %# agent, agent_custid, refnum (advertising source), referral_custnum
22 %# better section title for this?
23 <FONT CLASS="fsinnerbox-title"><% mt('Basics') |h %></FONT>
24 <& cust_main/basics.html, $cust_main, 'custnum' => $custnum &>
27 % if ( $conf->config('national_id-country')
28 % || $conf->exists('cust_main-enable_birthdate')
29 % || $conf->exists('cust_main-enable_anniversary_date')
33 <& cust_main/birthdate.html, $cust_main &>
35 % my $has_ship_address = '';
36 % if ( $cgi->param('error') ) {
37 % $has_ship_address = !$same;
38 % } elsif ( $cust_main->custnum ) {
39 % $has_ship_address = $cust_main->has_ship_address;
43 <TD STYLE="width:650px">
44 %#; padding-right:2px; vertical-align:top">
45 <FONT CLASS="fsinnerbox-title"><% mt('Billing address') |h %></FONT>
46 <TABLE CLASS="fsinnerbox" WIDTH="100%">
47 <& cust_main/before_bill_location.html, $cust_main &>
48 <& /elements/location.html,
49 object => $cust_main->bill_location,
51 enable_censustract => 1,
55 <& cust_main/after_bill_location.html, $cust_main &>
59 <TR><TD STYLE="height:14px"></TD></TR>
61 <TD STYLE="width:650px">
62 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
63 <INPUT TYPE="checkbox"
66 onclick="samechanged(this)"
67 onkeyup="samechanged(this)"
69 <% $has_ship_address ? '' : 'CHECKED' %>
70 ><% mt('same as billing address') |h %>
71 <DIV CLASS="fsinnerbox">
72 <TABLE ID="table_ship_location" WIDTH="100%">
73 <& cust_main/before_ship_location.html, $cust_main &>
74 <& /elements/location.html,
75 object => $cust_main->ship_location,
77 enable_censustract => 1,
81 % unless ($conf->exists('invoice-ship_address')) { #it's always on, so hide per-cust config
85 <% include('/elements/checkbox.html',
86 'field' => 'invoice_ship_address',
88 'curr_value' => $cust_main->invoice_ship_address,
89 'postfix' => emt('included on invoices'),
100 function samechanged(what) {
101 %# not display = 'none', because we still want it to take up space
102 %# document.getElementById('table_ship_location').style.visibility =
103 %# what.checked ? 'hidden' : 'visible';
104 var t1 = document.getElementById('table_ship_location');
105 if ( what.checked ) {
106 t1.style.visibility = 'hidden';
109 t1.style.visibility = 'visible'
112 //samechanged(document.getElementById('same'));
117 <& cust_main/contacts_new.html, 'cust_main'=>$cust_main, &>
120 <& cust_main/billing.html, $cust_main,
121 'payinfo' => $payinfo,
122 'invoicing_list' => \@invoicing_list,
125 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
126 % if (!$ro_comments || $cust_main->comments) {
129 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
130 <TABLE CLASS="fsinnerbox">
133 <TEXTAREA NAME = "comments"
138 ><% $cust_main->comments %></TEXTAREA>
145 % unless ( $custnum ) {
147 <& cust_main/first_pkg.html, $cust_main,
148 'pkgpart_svcpart' => $pkgpart_svcpart,
150 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
151 'username' => $username,
152 'password' => $password,
154 'saved_domsvc' => $saved_domsvc,
161 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
163 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
165 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
168 <INPUT TYPE = "button"
169 NAME = "submitButton"
171 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
172 onClick = "this.disabled=true; bottomfixup(this.form);"
177 <& /elements/footer.html &>
181 my $curuser = $FS::CurrentUser::CurrentUser;
183 #probably redundant given the checks below...
185 unless $curuser->access_right('New customer')
186 || $curuser->access_right('Edit customer');
188 my $conf = new FS::Conf;
192 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
193 my $pkgpart_svcpart = ''; #first_pkg
194 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
197 my $prospectnum = '';
198 my $locationnum = '';
201 $m->comp('/elements/handle_uri_query', 'secure'=>1);
203 if ( $cgi->param('error') ) {
205 $same = ($cgi->param('same') || '') eq 'Y';
206 # false laziness w/ edit/process/cust_main.cgi
208 for my $pre (qw(bill ship)) {
210 foreach ( FS::cust_main->location_fields ) {
211 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
213 $hash{'custnum'} = $cgi->param('custnum');
214 $locations{$pre} = qsearchs('cust_location', \%hash)
215 || FS::cust_location->new( \%hash );
218 $locations{ship} = $locations{bill};
221 $cust_main = new FS::cust_main ( {
222 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
223 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
226 for my $pre (qw(bill ship)) {
227 $cust_main->set($pre.'_location', $locations{$pre});
228 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
231 $custnum = $cust_main->custnum;
234 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
236 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
237 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
238 $ss = $cust_main->ss; # don't mask an entered value on errors
239 $stateid = $cust_main->stateid; # don't mask an entered value on errors
240 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
242 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
244 $prospectnum = $cgi->param('prospectnum') || '';
246 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
248 $locationnum = $cgi->param('locationnum') || '';
251 $username = $cgi->param('username');
252 $password = $cgi->param('_password');
253 $popnum = $cgi->param('popnum');
254 $saved_domsvc = $cgi->param('domsvc') || '';
255 if ( $saved_domsvc =~ /^(\d+)$/ ) {
262 $svc_phone{$_} = $cgi->param($_)
263 foreach qw( countrycode phonenum sip_password pin phone_name );
265 #svc_dsl (phonenum came in with svc_phone)
266 $svc_phone{$_} = $cgi->param($_)
267 foreach qw( password isp_chg isp_prev vendor_qual_id );
269 } elsif ( $cgi->keywords ) { #editing
272 unless $curuser->access_right('Edit customer');
274 my( $query ) = $cgi->keywords;
277 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
278 or die "custnum $custnum not found";
279 if ( $cust_main->dbdef_table->column('paycvv')
280 && length($cust_main->paycvv) ) {
281 my $paycvv = $cust_main->paycvv;
283 $cust_main->paycvv($paycvv);
285 @invoicing_list = $cust_main->invoicing_list;
286 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
287 $stateid = $cust_main->masked('stateid');
288 $payinfo = $cust_main->paymask;
290 } else { #new customer
293 unless $curuser->access_right('New customer');
296 $cust_main = new FS::cust_main ( {} );
297 $cust_main->agentnum( $conf->config('default_agentnum') )
298 if $conf->exists('default_agentnum');
299 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
300 @invoicing_list = ();
301 push @invoicing_list, 'POST'
302 unless $conf->exists('disablepostalinvoicedefault');
307 $cgi->param('tagnum', FS::part_tag->default_tags);
309 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
311 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
312 or die "unknown qualnum $qualnum";
314 my $prospect_main = $qual->cust_or_prospect;
315 $prospectnum = $prospect_main->prospectnum
316 or die "qualification not on a prospect";
318 $cust_main->agentnum( $prospect_main->agentnum );
319 $cust_main->company( $prospect_main->company );
321 #first contact? -> name
322 my @prospect_contacts = $prospect_main->prospect_contact;
323 my $contact = $prospect_contacts[0]->contact;
324 $cust_main->first( $contact->first );
325 $cust_main->set( 'last', $contact->get('last') );
326 #contact phone numbers?
328 #location -> address (all prospect quals have location, right?)
329 my $cust_location = $qual->cust_location;
330 $cust_location->dealternize;
331 $cust_main->$_( $cust_location->$_ )
332 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
334 #locationnum -> package order
335 $locationnum = $qual->locationnum;
337 #pkgpart handled by lock_pkgpart below
339 #service telephone & vendor_qual_id -> svc_dsl
340 $svc_dsl{$_} = $qual->$_
341 foreach qw( phonenum vendor_qual_id );
344 my $countrydefault = $conf->config('countrydefault') || 'US';
345 my $statedefault = $conf->config('statedefault') || 'CA';
346 $cust_main->set('bill_location',
347 FS::cust_location->new( {
348 country => $countrydefault,
349 state => $statedefault,
353 $cust_main->set('ship_location',
354 FS::cust_location->new( {
355 country => $countrydefault,
356 state => $statedefault,
362 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
364 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
365 or die "unknown pkgpart $pkgpart";
366 my $svcpart = $part_pkg->svcpart;
367 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
372 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
374 $title .= ": ". $cust_main->name if $custnum;
376 my $r = qq!<font color="#ff0000">*</font> !;