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 ID="div_ship_location">
72 <TABLE WIDTH="100%" CLASS="fsinnerbox">
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'),
98 <SCRIPT TYPE="text/javascript">
100 function samechanged(what) {
101 if ( what.checked ) {
102 $('#div_ship_location').slideUp();
104 $('#div_ship_location').slideDown();
108 % if ( ! $has_ship_address ) {
109 $('#div_ship_location').hide();
114 <& cust_main/contacts_new.html, 'cust_main'=>$cust_main, &>
117 <& cust_main/billing.html, $cust_main,
118 'invoicing_list' => \@invoicing_list,
121 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
122 % if (!$ro_comments || $cust_main->comments) {
125 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
126 <TABLE CLASS="fsinnerbox">
129 <TEXTAREA NAME = "comments"
134 ><% $cust_main->comments %></TEXTAREA>
141 % unless ( $custnum ) {
143 <& cust_main/first_pkg.html, $cust_main,
144 'pkgpart_svcpart' => $pkgpart_svcpart,
146 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
147 'username' => $username,
148 'password' => $password,
150 'saved_domsvc' => $saved_domsvc,
157 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
159 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
161 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
164 <INPUT TYPE = "button"
165 NAME = "submitButton"
167 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
168 onClick = "this.disabled=true; bottomfixup(this.form);"
173 <& /elements/footer.html &>
177 my $curuser = $FS::CurrentUser::CurrentUser;
179 #probably redundant given the checks below...
181 unless $curuser->access_right('New customer')
182 || $curuser->access_right('Edit customer');
184 my $conf = new FS::Conf;
188 my($custnum, $cust_main, $ss, $stateid, @invoicing_list);
189 my $pkgpart_svcpart = ''; #first_pkg
190 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
193 my $prospectnum = '';
194 my $locationnum = '';
197 $m->comp('/elements/handle_uri_query', 'secure'=>1);
199 if ( $cgi->param('error') ) {
201 $same = ($cgi->param('same') || '') eq 'Y';
202 # false laziness w/ edit/process/cust_main.cgi
204 for my $pre (qw(bill ship)) {
206 foreach my $locfield ( FS::cust_main->location_fields ) {
207 # don't search on lat/long, string values can cause qsearchs to die
208 next if grep {$_ eq $locfield} qw(latitude longitude);
209 $hash{$locfield} = scalar($cgi->param($pre.'_'.$locfield));
211 $hash{'custnum'} = $cgi->param('custnum');
212 $locations{$pre} = qsearchs('cust_location', \%hash)
213 || FS::cust_location->new( \%hash );
214 # now set lat/long, for redisplay of entered values
215 foreach my $locfield ( qw(latitude longitude) ) {
216 my $locvalue = scalar($cgi->param($pre.'_'.$locfield));
217 $locations{$pre}->set($locfield,$locvalue);
221 $locations{ship} = $locations{bill};
224 $cust_main = new FS::cust_main ( {
225 map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')),
226 map { ( "ship_$_", '' ) } (FS::cust_main->location_fields)
229 for my $pre (qw(bill ship)) {
230 $cust_main->set($pre.'_location', $locations{$pre});
231 $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum);
234 $custnum = $cust_main->custnum;
237 unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
239 @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
240 $cust_main->setfield( 'paid' => scalar($cgi->param('paid')) )
241 if $cgi->param('paid');
242 $ss = $cust_main->ss; # don't mask an entered value on errors
243 $stateid = $cust_main->stateid; # don't mask an entered value on errors
245 $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
247 $prospectnum = $cgi->param('prospectnum') || '';
249 $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
251 $locationnum = $cgi->param('locationnum') || '';
254 $username = $cgi->param('username');
255 $password = $cgi->param('_password');
256 $popnum = $cgi->param('popnum');
257 $saved_domsvc = $cgi->param('domsvc') || '';
258 if ( $saved_domsvc =~ /^(\d+)$/ ) {
265 $svc_phone{$_} = $cgi->param($_)
266 foreach qw( countrycode phonenum sip_password pin phone_name );
268 #svc_dsl (phonenum came in with svc_phone)
269 $svc_phone{$_} = $cgi->param($_)
270 foreach qw( password isp_chg isp_prev vendor_qual_id );
272 } elsif ( $cgi->keywords ) { #editing
275 unless $curuser->access_right('Edit customer');
277 my( $query ) = $cgi->keywords;
280 $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
281 or die "custnum $custnum not found";
282 if ( $cust_main->dbdef_table->column('paycvv')
283 && length($cust_main->paycvv) ) {
284 my $paycvv = $cust_main->paycvv;
286 $cust_main->paycvv($paycvv);
288 @invoicing_list = $cust_main->invoicing_list;
289 $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
290 $stateid = $cust_main->masked('stateid');
292 } else { #new customer
295 unless $curuser->access_right('New customer');
298 $cust_main = new FS::cust_main ( {} );
299 $cust_main->agentnum( $conf->config('default_agentnum') )
300 if $conf->exists('default_agentnum');
301 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
302 $cust_main->set('postal_invoice', 'Y')
303 unless $conf->exists('disablepostalinvoicedefault');
307 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
309 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
310 or die "unknown qualnum $qualnum";
312 my $prospect_main = $qual->cust_or_prospect;
313 $prospectnum = $prospect_main->prospectnum
314 or die "qualification not on a prospect";
316 $cust_main->agentnum( $prospect_main->agentnum );
317 $cust_main->company( $prospect_main->company );
319 #first contact? -> name
320 my @prospect_contacts = $prospect_main->prospect_contact;
321 my $contact = $prospect_contacts[0]->contact;
322 $cust_main->first( $contact->first );
323 $cust_main->set( 'last', $contact->get('last') );
324 #contact phone numbers?
326 #location -> address (all prospect quals have location, right?)
327 my $cust_location = $qual->cust_location;
328 $cust_location->dealternize;
329 $cust_main->$_( $cust_location->$_ )
330 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
332 #locationnum -> package order
333 $locationnum = $qual->locationnum;
335 #pkgpart handled by lock_pkgpart below
337 #service telephone & vendor_qual_id -> svc_dsl
338 $svc_dsl{$_} = $qual->$_
339 foreach qw( phonenum vendor_qual_id );
342 my $countrydefault = $conf->config('countrydefault') || 'US';
343 my $statedefault = $conf->config('statedefault') || 'CA';
344 $cust_main->set('bill_location',
345 FS::cust_location->new( {
346 country => $countrydefault,
347 state => $statedefault,
351 $cust_main->set('ship_location',
352 FS::cust_location->new( {
353 country => $countrydefault,
354 state => $statedefault,
360 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
362 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
363 or die "unknown pkgpart $pkgpart";
364 my $svcpart = $part_pkg->svcpart;
365 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
370 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
372 $title .= ": ". $cust_main->name if $custnum;
374 my $r = qq!<font color="#ff0000">*</font> !;