X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fcust_main.cgi;h=e58441d2465c141f2609d09f2513a1c9b8f9e155;hb=ac8410cdb67639afeb84c84e975fffadf3e6cce1;hp=9588dcb3aa53fe12da8a867b45ebfc6f5843b609;hpb=cf16b23820da69e3c8d0156ae27e21c635bf1ec5;p=freeside.git diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 9588dcb3a..e58441d24 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -1,464 +1,376 @@ -<% -# - -use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum - $last $first $ss $company $address1 $address2 $city $zip - $daytime $night $fax @invoicing_list $invoicing_list $payinfo - $payname %payby %paybychecked $refnum $otaker $r ); -use vars qw ( $conf $saved_pkgpart $username $password $popnum $ulen $ulen2 ); -use vars qw ( $error ); -#use CGI::Switch; -use CGI; -use CGI::Carp qw(fatalsToBrowser); -use FS::UID qw(cgisuidsetup getotaker); -#use FS::Record qw(qsearch qsearchs fields); -use FS::Record qw(qsearch qsearchs fields dbdef); -use FS::CGI qw(header popurl itable table); -use FS::cust_main; -use FS::agent; -use FS::part_referral; -use FS::cust_main_county; - - #for misplaced logic below - use FS::part_pkg; - - #for false laziness below (now more properly lazy) - use FS::svc_acct_pop; - - #for (other) false laziness below - use FS::agent; - use FS::type_pkgs; - -$conf = new FS::Conf; - -#get record - -$error = ''; -if ( $cgi->param('error') ) { - $error = $cgi->param('error'); - $cust_main = new FS::cust_main ( { - map { $_, scalar($cgi->param($_)) } fields('cust_main') - } ); - $custnum = $cust_main->custnum; - $saved_pkgpart = $cgi->param('pkgpart_svcpart') || ''; - if ( $saved_pkgpart =~ /^(\d+)_/ ) { - $saved_pkgpart = $1; +<& /elements/header.html, $title, &> + +<& /elements/error.html &> + +
+ + + + +% if ( $custnum ) { + <% mt('Customer #') |h %><% $cust_main->display_custnum %> - + + <% $cust_main->status_label %> + +

+% } + +%# agent, agent_custid, refnum (advertising source), referral_custnum +%# better section title for this? +<% mt('Basics') |h %> +<& cust_main/basics.html, $cust_main, 'custnum' => $custnum &> + +%# birthdate +% if ( $conf->config('national_id-country') +% || $conf->exists('cust_main-enable_birthdate') +% || $conf->exists('cust_main-enable_anniversary_date') +% ) +% { +
+ <& cust_main/birthdate.html, $cust_main &> +% } +% my $has_ship_address = ''; +% if ( $cgi->param('error') ) { +% $has_ship_address = !$same; +% } elsif ( $cust_main->custnum ) { +% $has_ship_address = $cust_main->has_ship_address; +% } +
+ + + + + + +
+%#; padding-right:2px; vertical-align:top"> + <% mt('Billing address') |h %> + + <& cust_main/before_bill_location.html, $cust_main &> + <& /elements/location.html, + object => $cust_main->bill_location, + prefix => 'bill_', + enable_censustract => 1, + enable_district => 1, + enable_coords => 1, + &> + <& cust_main/after_bill_location.html, $cust_main &> +
+
+ <% mt('Service address') |h %> + + ><% mt('same as billing address') |h %> +
+ + <& cust_main/before_ship_location.html, $cust_main &> + <& /elements/location.html, + object => $cust_main->ship_location, + prefix => 'ship_', + enable_censustract => 1, + enable_district => 1, + enable_coords => 1, + &> +% unless ($conf->exists('invoice-ship_address')) { #it's always on, so hide per-cust config + + + +% } +
+ <% include('/elements/checkbox.html', + 'field' => 'invoice_ship_address', + 'value' => 'Y', + 'curr_value' => $cust_main->invoice_ship_address, + 'postfix' => emt('Include service address on invoices'), + ) %> +
+
+
+ + -#referring customer - -#print qq!

Referring Customer: !; -if ( $cust_main->referral_custnum ) { - my $referring_cust_main = - qsearchs('cust_main', { custnum => $cust_main->referral_custnum } ); - print '

Referring Customer: '. - $cust_main->referral_custnum. ': '. - ( $referring_cust_main->company - || $referring_cust_main->last. ', '. $referring_cust_main->first ). - ''; -} elsif ( ! $conf->exists('disable_customer_referrals') ) { - print '

Referring customer number: '; -} else { - print ''; -} +<& cust_main/contacts_new.html, 'cust_main'=>$cust_main, &> -# contact info - -($last,$first,$ss,$company,$address1,$address2,$city,$zip)=( - $cust_main->last, - $cust_main->first, - $cust_main->ss, - $cust_main->company, - $cust_main->address1, - $cust_main->address2, - $cust_main->city, - $cust_main->zip, -); - -print "

Billing address", &itable("#cccccc"), <${r}Contact name
(last, first) -END - -print < , - -END - -print <SS# -Company -${r}Address -${r}City${r}State/Country${r}Zip!; +%# billing info +<& cust_main/billing.html, $cust_main, + 'invoicing_list' => \@invoicing_list, +&> -($daytime,$night,$fax)=( - $cust_main->daytime, - $cust_main->night, - $cust_main->fax, -); +% my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly'; +% if (!$ro_comments || $cust_main->comments) { -print <Day Phone -Night Phone -Fax -END +
+ <% mt('Comments') |h %> + + + + +
+ +
-print "$r required fields
"; +% } -# service address +% unless ( $custnum ) { -if ( defined $cust_main->dbdef_table->column('ship_last') ) { + <& cust_main/first_pkg.html, $cust_main, + 'pkgpart_svcpart' => $pkgpart_svcpart, + 'disable_empty' => + scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ), + 'username' => $username, + 'password' => $password, + 'popnum' => $popnum, + 'saved_domsvc' => $saved_domsvc, + %svc_phone, + %svc_dsl, + &> - print "\n", < - function changed(what) { - what.form.same.checked = false; - } - function samechanged(what) { - if ( what.checked ) { -END -print " what.form.ship_$_.value = what.form.$_.value;\n" - for (qw( last first company address1 address2 city zip daytime night fax )); -print < + + + +<& cust_main/bottomfixup.html, 'custnum' => $custnum &> + +
+" + onClick = "this.disabled=true; bottomfixup(this.form);" +> +

+ + +<& /elements/footer.html &> + +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +#probably redundant given the checks below... +die "access denied" + unless $curuser->access_right('New customer') + || $curuser->access_right('Edit customer'); + +my $conf = new FS::Conf; + +#get record + +my($custnum, $cust_main, $ss, $stateid, @invoicing_list); +my $pkgpart_svcpart = ''; #first_pkg +my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct +my %svc_phone = (); +my %svc_dsl = (); +my $prospectnum = ''; +my $locationnum = ''; +my $same = ''; + +$m->comp('/elements/handle_uri_query', 'secure'=>1); + +if ( $cgi->param('error') ) { + + $same = ($cgi->param('same') || '') eq 'Y'; + # false laziness w/ edit/process/cust_main.cgi + my %locations; + for my $pre (qw(bill ship)) { + my %hash; + foreach my $locfield ( FS::cust_main->location_fields ) { + # don't search on lat/long, string values can cause qsearchs to die + next if grep {$_ eq $locfield} qw(latitude longitude); + $hash{$locfield} = scalar($cgi->param($pre.'_'.$locfield)); } - } - -END - - print '
Service address ', - '(ship_last ) { - print ' CHECKED'; - foreach ( - qw( last first company address1 address2 city state zip daytime night fax) - ) { - $cust_main->set("ship_$_", $cust_main->get($_) ); + $hash{'custnum'} = $cgi->param('custnum'); + $locations{$pre} = qsearchs('cust_location', \%hash) + || FS::cust_location->new( \%hash ); + # now set lat/long, for redisplay of entered values + foreach my $locfield ( qw(latitude longitude) ) { + my $locvalue = scalar($cgi->param($pre.'_'.$locfield)); + $locations{$pre}->set($locfield,$locvalue); } } - print '>same as billing address)
'; - - my($ship_last,$ship_first,$ship_company,$ship_address1,$ship_address2,$ship_city,$ship_zip)=( - $cust_main->ship_last, - $cust_main->ship_first, - $cust_main->ship_company, - $cust_main->ship_address1, - $cust_main->ship_address2, - $cust_main->ship_city, - $cust_main->ship_zip, - ); - - print &itable("#cccccc"), <${r}Contact name
(last, first) -END - - print < , - -END - - print < - Company - ${r}Address -   - ${r}City${r}State/Country${r}Zip!; - my($ship_daytime,$ship_night,$ship_fax)=( - $cust_main->ship_daytime, - $cust_main->ship_night, - $cust_main->ship_fax, - ); + $cust_main = new FS::cust_main ( { + map { ( $_, scalar($cgi->param($_)) ) } (fields('cust_main')), + map { ( "ship_$_", '' ) } (FS::cust_main->location_fields) + } ); - print <Day Phone - Night Phone - Fax -END + for my $pre (qw(bill ship)) { + $cust_main->set($pre.'_location', $locations{$pre}); + $cust_main->set($pre.'_locationnum', $locations{$pre}->locationnum); + } - print "$r required fields
"; + $custnum = $cust_main->custnum; -} + die "access denied" + unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer'); -# billing info - -sub expselect { - my $prefix = shift; - my( $m, $y ) = (0, 0); - if ( scalar(@_) ) { - my $date = shift || '01-2000'; - if ( $date =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format - ( $m, $y ) = ( $2, $1 ); - } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) { - ( $m, $y ) = ( $1, $3 ); - } else { - die "unrecognized expiration date format: $date"; - } - } + @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') ); + $cust_main->setfield( 'paid' => scalar($cgi->param('paid')) ) + if $cgi->param('paid'); + $ss = $cust_main->ss; # don't mask an entered value on errors + $stateid = $cust_main->stateid; # don't mask an entered value on errors - my $return = qq!!; - for ( 2001 .. 2037 ) { - $return .= "national_id( $cgi->param('national_id1') || $cgi->param('national_id2') ); - $return; -} + $prospectnum = $cgi->param('prospectnum') || ''; -print "
Billing information", &itable("#cccccc"), - qq!tax eq "Y"; -print qq!>Tax Exempt!; -print qq!invoicing_list; -print qq! CHECKED! - if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') ) - || grep { $_ eq 'POST' } @invoicing_list; -print qq!>Postal mail invoice!; -$invoicing_list = join(', ', grep { $_ ne 'POST' } @invoicing_list ); -print qq!Email invoice !; - -print "Billing type", - "", - &table("#cccccc"), ""; - -($payinfo, $payname)=( - $cust_main->payinfo, - $cust_main->payname, -); - -%payby = ( - 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD"). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", "12-2037"). qq!
${r}Attention
!, - 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP"), -); -%paybychecked = ( - 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD", $cust_main->paydate). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", $cust_main->paydate). qq!
${r}Attention
!, - 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP", $cust_main->paydate), -); -for (qw(CARD BILL COMP)) { - print qq!payby eq "$_") { - print qq! CHECKED> $paybychecked{$_}!; + $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || ''; + + $locationnum = $cgi->param('locationnum') || ''; + + #svc_acct + $username = $cgi->param('username'); + $password = $cgi->param('_password'); + $popnum = $cgi->param('popnum'); + $saved_domsvc = $cgi->param('domsvc') || ''; + if ( $saved_domsvc =~ /^(\d+)$/ ) { + $saved_domsvc = $1; } else { - print qq!> $payby{$_}!; + $saved_domsvc = ''; } -} -print "$r required fields for each billing type"; + #svc_phone + $svc_phone{$_} = $cgi->param($_) + foreach qw( countrycode phonenum sip_password pin phone_name ); -if ( defined $cust_main->dbdef_table->column('comments') ) { - print "

Comments", &itable("#cccccc"), - qq!", - ""; -} + #svc_dsl (phonenum came in with svc_phone) + $svc_phone{$_} = $cgi->param($_) + foreach qw( password isp_chg isp_prev vendor_qual_id ); -unless ( $custnum ) { - # pry the wrong place for this logic. also pretty expensive - #use FS::part_pkg; +} elsif ( $cgi->keywords ) { #editing - #false laziness, copied from FS::cust_pkg::order - my $pkgpart; - if ( scalar(@agents) == 1 ) { - # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART - my($agent)=qsearchs('agent',{'agentnum'=> $agentnum }); - $pkgpart = $agent->pkgpart_hashref; - } else { - #can't know (agent not chosen), so, allow all - my %typenum; - foreach my $agent ( @agents ) { - next if $typenum{$agent->typenum}++; - #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref } - foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround - } - } - #eslaf + die "access denied" + unless $curuser->access_right('Edit customer'); - my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } } - qsearch( 'part_pkg', { 'disabled' => '' } ); + my( $query ) = $cgi->keywords; + $query =~ /^(\d+)$/; + $custnum=$1; + $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or die "custnum $custnum not found"; + if ( $cust_main->dbdef_table->column('paycvv') + && length($cust_main->paycvv) ) { + my $paycvv = $cust_main->paycvv; + $paycvv =~ s/./*/g; + $cust_main->paycvv($paycvv); + } + @invoicing_list = $cust_main->invoicing_list; + $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss'); + $stateid = $cust_main->masked('stateid'); - if ( @part_pkg ) { +} else { #new customer -# print "

First package", &itable("#cccccc", "0 ALIGN=LEFT"), -#apiabuse & undesirable wrapping - print "

First package", &itable("#cccccc"), - qq!"; - - #false laziness: (mostly) copied from edit/svc_acct.cgi - #$ulen = $svc_acct->dbdef_table->column('username')->length; - $ulen = dbdef->table('svc_acct')->column('username')->length; - $ulen2 = $ulen+2; - my $passwordmax = $conf->config('passwordmax') || 8; - my $pmax2 = $passwordmax + 2; - print <Username - -Password - -(blank to generate) -END - - print 'Access number' - . - &FS::svc_acct_pop::popselector($popnum). - '' - ; + if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) { + my $pkgpart = $1; + my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } ) + or die "unknown pkgpart $pkgpart"; + my $svcpart = $part_pkg->svcpart; + $pkgpart_svcpart = $pkgpart.'_'.$svcpart; } + } -$otaker = $cust_main->otaker; -print qq!!, - qq!
!, - "", -; +my $title = $custnum ? 'Edit Customer' : 'Add Customer'; +$title = mt($title); +$title .= ": ". $cust_main->name if $custnum; + +my $r = qq!* !; -%> +