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;
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>
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
84 <% include('/elements/checkbox.html',
85 'field' => 'invoice_ship_address',
87 'curr_value' => $cust_main->invoice_ship_address,
88 'postfix' => emt('Include service address on invoices'),
99 function samechanged(what) {
100 var t1 = document.getElementById('table_ship_location');
101 if ( what.checked ) {
102 t1.style.display = 'none';
104 t1.style.display = ''
107 samechanged(document.getElementById('same'));
110 <& cust_main/contacts_new.html, 'cust_main'=>$cust_main, &>
113 <& cust_main/billing.html, $cust_main,
114 'payinfo' => $payinfo,
115 'invoicing_list' => \@invoicing_list,
118 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
119 % if (!$ro_comments || $cust_main->comments) {
122 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
123 <TABLE CLASS="fsinnerbox">
126 <TEXTAREA NAME = "comments"
131 ><% $cust_main->comments %></TEXTAREA>
138 % unless ( $custnum ) {
140 <& cust_main/first_pkg.html, $cust_main,
141 'pkgpart_svcpart' => $pkgpart_svcpart,
143 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
144 'username' => $username,
145 'password' => $password,
147 'saved_domsvc' => $saved_domsvc,
154 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
156 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
158 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
161 <INPUT TYPE = "button"
162 NAME = "submitButton"
164 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
165 onClick = "this.disabled=true; bottomfixup(this.form);"
170 <& /elements/footer.html &>
174 my $curuser = $FS::CurrentUser::CurrentUser;
176 #probably redundant given the checks below...
178 unless $curuser->access_right('New customer')
179 || $curuser->access_right('Edit customer');
181 my $conf = new FS::Conf;
185 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
186 my $pkgpart_svcpart = ''; #first_pkg
187 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
190 my $prospectnum = '';
191 my $locationnum = '';
194 $m->comp('/elements/handle_uri_query', 'secure'=>1);
196 if ( $cgi->param('error') ) {
198 $same = ($cgi->param('same') || '') eq 'Y';
199 # false laziness w/ edit/process/cust_main.cgi
201 for my $pre (qw(bill ship)) {
203 foreach ( FS::cust_main->location_fields ) {
204 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
206 $hash{'custnum'} = $cgi->param('custnum');
207 $locations{$pre} = qsearchs('cust_location', \%hash)
208 || FS::cust_location->new( \%hash );
211 $locations{ship} = $locations{bill};
214 $cust_main = new FS::cust_main ( {
215 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
216 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
219 for my $pre (qw(bill ship)) {
220 $cust_main->set($pre.'_location', $locations{$pre});
221 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
224 $custnum = $cust_main->custnum;
227 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
229 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
230 $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
231 $ss = $cust_main->ss; # don't mask an entered value on errors
232 $stateid = $cust_main->stateid; # don't mask an entered value on errors
233 $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
235 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
237 $prospectnum = $cgi->param('prospectnum') || '';
239 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
241 $locationnum = $cgi->param('locationnum') || '';
244 $username = $cgi->param('username');
245 $password = $cgi->param('_password');
246 $popnum = $cgi->param('popnum');
247 $saved_domsvc = $cgi->param('domsvc') || '';
248 if ( $saved_domsvc =~ /^(\d+)$/ ) {
255 $svc_phone{$_} = $cgi->param($_)
256 foreach qw( countrycode phonenum sip_password pin phone_name );
258 #svc_dsl (phonenum came in with svc_phone)
259 $svc_phone{$_} = $cgi->param($_)
260 foreach qw( password isp_chg isp_prev vendor_qual_id );
262 } elsif ( $cgi->keywords ) { #editing
265 unless $curuser->access_right('Edit customer');
267 my( $query ) = $cgi->keywords;
270 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
271 or die "custnum $custnum not found";
272 if ( $cust_main->dbdef_table->column('paycvv')
273 && length($cust_main->paycvv) ) {
274 my $paycvv = $cust_main->paycvv;
276 $cust_main->paycvv($paycvv);
278 @invoicing_list = $cust_main->invoicing_list;
279 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
280 $stateid = $cust_main->masked('stateid');
281 $payinfo = $cust_main->paymask;
283 } else { #new customer
286 unless $curuser->access_right('New customer');
289 $cust_main = new FS::cust_main ( {} );
290 $cust_main->agentnum( $conf->config('default_agentnum') )
291 if $conf->exists('default_agentnum');
292 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
293 @invoicing_list = ();
294 push @invoicing_list, 'POST'
295 unless $conf->exists('disablepostalinvoicedefault');
300 $cgi->param('tagnum', FS::part_tag->default_tags);
302 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
304 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
305 or die "unknown qualnum $qualnum";
307 my $prospect_main = $qual->cust_or_prospect;
308 $prospectnum = $prospect_main->prospectnum
309 or die "qualification not on a prospect";
311 $cust_main->agentnum( $prospect_main->agentnum );
312 $cust_main->company( $prospect_main->company );
314 #first contact? -> name
315 my @prospect_contacts = $prospect_main->prospect_contact;
316 my $contact = $prospect_contacts[0]->contact;
317 $cust_main->first( $contact->first );
318 $cust_main->set( 'last', $contact->get('last') );
319 #contact phone numbers?
321 #location -> address (all prospect quals have location, right?)
322 my $cust_location = $qual->cust_location;
323 $cust_location->dealternize;
324 $cust_main->$_( $cust_location->$_ )
325 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
327 #locationnum -> package order
328 $locationnum = $qual->locationnum;
330 #pkgpart handled by lock_pkgpart below
332 #service telephone & vendor_qual_id -> svc_dsl
333 $svc_dsl{$_} = $qual->$_
334 foreach qw( phonenum vendor_qual_id );
337 my $countrydefault = $conf->config('countrydefault') || 'US';
338 my $statedefault = $conf->config('statedefault') || 'CA';
339 $cust_main->set('bill_location',
340 FS::cust_location->new( {
341 country => $countrydefault,
342 state => $statedefault,
346 $cust_main->set('ship_location',
347 FS::cust_location->new( {
348 country => $countrydefault,
349 state => $statedefault,
355 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
357 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
358 or die "unknown pkgpart $pkgpart";
359 my $svcpart = $part_pkg->svcpart;
360 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
365 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
367 $title .= ": ". $cust_main->name if $custnum;
369 my $r = qq!<font color="#ff0000">*</font> !;