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 <FIELDSET ID="bill_location" CLASS="location">
47 <TABLE CLASS="fsinnerbox" WIDTH="100%">
48 <& cust_main/before_bill_location.html, $cust_main &>
49 <& /elements/location.html,
50 object => $cust_main->bill_location,
52 enable_censustract => 1,
56 <& cust_main/after_bill_location.html, $cust_main &>
61 <TR><TD STYLE="height:14px"></TD></TR>
64 <FONT CLASS="fsinnerbox-title"><% mt('Service address') |h %></FONT>
65 <INPUT TYPE="checkbox"
68 onclick="samechanged(this)"
69 onkeyup="samechanged(this)"
71 <% $has_ship_address ? '' : 'CHECKED' %>
72 ><% mt('same as billing address') |h %>
73 <FIELDSET ID="ship_location" CLASS="location">
74 <TABLE WIDTH="100%" CLASS="fsinnerbox">
75 <& cust_main/before_ship_location.html, $cust_main &>
76 <& /elements/location.html,
77 object => $cust_main->ship_location,
79 enable_censustract => 1,
83 % unless ($conf->exists('invoice-ship_address')) { #it's always on, so hide per-cust config
86 <% include('/elements/checkbox.html',
87 'field' => 'invoice_ship_address',
89 'curr_value' => $cust_main->invoice_ship_address,
90 'postfix' => emt('Include service address on invoices'),
100 <SCRIPT TYPE="text/javascript">
102 function samechanged(what) {
103 if ( what.checked ) {
104 $('#ship_location').slideUp();
106 $('#ship_location').slideDown();
110 % if ( ! $has_ship_address ) {
111 $('#ship_location').hide();
114 $().ready( function() {
115 window.bill_location = new Location($('fieldset#bill_location'));
120 <& cust_main/contacts_new.html, 'cust_main'=>$cust_main, &>
123 <& cust_main/billing.html, $cust_main,
124 'payinfo' => $payinfo,
125 'invoicing_list' => \@invoicing_list,
128 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
129 % if (!$ro_comments || $cust_main->comments) {
132 <FONT CLASS="fsinnerbox-title"><% mt('Comments') |h %></FONT>
133 <TABLE CLASS="fsinnerbox">
136 <TEXTAREA NAME = "comments"
141 ><% $cust_main->comments %></TEXTAREA>
148 % unless ( $custnum ) {
150 <& cust_main/first_pkg.html, $cust_main,
151 'pkgpart_svcpart' => $pkgpart_svcpart,
153 scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
154 'username' => $username,
155 'password' => $password,
157 'saved_domsvc' => $saved_domsvc,
164 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
166 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
168 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
171 <INPUT TYPE = "button"
172 NAME = "submitButton"
174 VALUE = "<% $custnum ? emt("Apply changes") : emt("Add Customer") %>"
175 onClick = "this.disabled=true; bottomfixup(this.form);"
180 <& /elements/footer.html &>
184 my $curuser = $FS::CurrentUser::CurrentUser;
186 #probably redundant given the checks below...
188 unless $curuser->access_right('New customer')
189 || $curuser->access_right('Edit customer');
191 my $conf = new FS::Conf;
195 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
196 my $pkgpart_svcpart = ''; #first_pkg
197 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
200 my $prospectnum = '';
201 my $locationnum = '';
204 $m->comp('/elements/handle_uri_query', 'secure'=>1);
206 if ( $cgi->param('error') ) {
208 $same = ($cgi->param('same') || '') eq 'Y';
209 # false laziness w/ edit/process/cust_main.cgi
211 for my $pre (qw(bill ship)) {
213 foreach ( FS::cust_main->location_fields ) {
214 $hash{$_} = scalar($cgi->param($pre.'_'.$_));
216 $hash{'custnum'} = $cgi->param('custnum');
217 $locations{$pre} = qsearchs('cust_location', \%hash)
218 || FS::cust_location->new( \%hash );
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' => $cgi->param('paid')) if $cgi->param('paid');
241 $ss = $cust_main->ss; # don't mask an entered value on errors
242 $stateid = $cust_main->stateid; # don't mask an entered value on errors
243 $payinfo = $cust_main->payinfo; # 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');
291 $payinfo = $cust_main->paymask;
293 } else { #new customer
296 unless $curuser->access_right('New customer');
299 $cust_main = new FS::cust_main ( {} );
300 $cust_main->agentnum( $conf->config('default_agentnum') )
301 if $conf->exists('default_agentnum');
302 $cust_main->referral_custnum( $cgi->param('referral_custnum') );
303 @invoicing_list = ();
304 push @invoicing_list, 'POST'
305 unless $conf->exists('disablepostalinvoicedefault');
310 $cgi->param('tagnum', FS::part_tag->default_tags);
312 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
314 my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
315 or die "unknown qualnum $qualnum";
317 my $prospect_main = $qual->cust_or_prospect;
318 $prospectnum = $prospect_main->prospectnum
319 or die "qualification not on a prospect";
321 $cust_main->agentnum( $prospect_main->agentnum );
322 $cust_main->company( $prospect_main->company );
324 #first contact? -> name
325 my @prospect_contacts = $prospect_main->prospect_contact;
326 my $contact = $prospect_contacts[0]->contact;
327 $cust_main->first( $contact->first );
328 $cust_main->set( 'last', $contact->get('last') );
329 #contact phone numbers?
331 #location -> address (all prospect quals have location, right?)
332 my $cust_location = $qual->cust_location;
333 $cust_location->dealternize;
334 $cust_main->$_( $cust_location->$_ )
335 foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
337 #locationnum -> package order
338 $locationnum = $qual->locationnum;
340 #pkgpart handled by lock_pkgpart below
342 #service telephone & vendor_qual_id -> svc_dsl
343 $svc_dsl{$_} = $qual->$_
344 foreach qw( phonenum vendor_qual_id );
347 my $countrydefault = $conf->config('countrydefault') || 'US';
348 my $statedefault = $conf->config('statedefault') || 'CA';
349 $cust_main->set('bill_location',
350 FS::cust_location->new( {
351 country => $countrydefault,
352 state => $statedefault,
356 $cust_main->set('ship_location',
357 FS::cust_location->new( {
358 country => $countrydefault,
359 state => $statedefault,
365 if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
367 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
368 or die "unknown pkgpart $pkgpart";
369 my $svcpart = $part_pkg->svcpart;
370 $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
375 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
377 $title .= ": ". $cust_main->name if $custnum;
379 my $r = qq!<font color="#ff0000">*</font> !;