-<%
-#<!-- $Id: cust_main.cgi,v 1.2 2001-08-11 05:52:56 ivan Exp $ -->
-
-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 $pkgpart $username $password $popnum $ulen $ulen2 );
-#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
- use FS::svc_acct_pop;
-
- #for (other) false laziness below
- use FS::agent;
- use FS::type_pkgs;
-
-$conf = new FS::Conf;
-
-#get record
-
-if ( $cgi->param('error') ) {
- $cust_main = new FS::cust_main ( {
- map { $_, scalar($cgi->param($_)) } fields('cust_main')
- } );
- $custnum = $cust_main->custnum;
- $pkgpart = $cgi->param('pkgpart_svcpart') || '';
- if ( $pkgpart =~ /^(\d+)_/ ) {
- $pkgpart = $1;
- } else {
- $pkgpart = '';
- }
- $username = $cgi->param('username');
- $password = $cgi->param('_password');
- $popnum = $cgi->param('popnum');
-} elsif ( $cgi->keywords ) { #editing
- my( $query ) = $cgi->keywords;
- $query =~ /^(\d+)$/;
- $custnum=$1;
- $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
- $pkgpart = 0;
- $username = '';
- $password = '';
- $popnum = 0;
-} else {
- $custnum='';
- $cust_main = new FS::cust_main ( {} );
- $cust_main->setfield('otaker',&getotaker);
- $pkgpart = 0;
- $username = '';
- $password = '';
- $popnum = 0;
-}
-$action = $custnum ? 'Edit' : 'Add';
-
-# top
-
-$p1 = popurl(1);
-print $cgi->header( '-expires' => 'now' ), header("Customer $action", '');
-print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
- "</FONT>"
- if $cgi->param('error');
-
-print qq!<FORM ACTION="${p1}process/cust_main.cgi" METHOD=POST NAME="form1">!,
- qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!,
- qq!Customer # !, ( $custnum ? $custnum : " (NEW)" ),
-
-;
-
-# agent
-
-$r = qq!<font color="#ff0000">*</font>!;
-
-@agents = qsearch( 'agent', {} );
-#die "No agents created!" unless @agents;
-die "You have not created any agents. You must create at least one agent before adding a customer. Go to ". popurl(2). "browse/agent.cgi and create one or more agents." unless @agents;
-$agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
-if ( scalar(@agents) == 1 ) {
- print qq!<INPUT TYPE="hidden" NAME="agentnum" VALUE="$agentnum">!;
-} else {
- print qq!<BR><BR>${r}Agent <SELECT NAME="agentnum" SIZE="1">!;
- my $agent;
- foreach $agent (sort {
- $a->agent cmp $b->agent;
- } @agents) {
- print '<OPTION VALUE="', $agent->agentnum, '"',
- " SELECTED"x($agent->agentnum==$agentnum),
- ">", $agent->agentnum,": ", $agent->agent;
- }
- print "</SELECT>";
-}
+%
+%
+% #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;
+%
+%my $conf = new FS::Conf;
+%
+%#get record
+%
+%my $error = '';
+%my($custnum, $username, $password, $popnum, $cust_main, $saved_pkgpart, $saved_domsvc);
+%my(@invoicing_list);
+%my ($ss,$stateid,$payinfo);
+%my $same = '';
+%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_domsvc = $cgi->param('domsvc') || '';
+% if ( $saved_domsvc =~ /^(\d+)$/ ) {
+% $saved_domsvc = $1;
+% } else {
+% $saved_domsvc = '';
+% }
+% $saved_pkgpart = $cgi->param('pkgpart_svcpart') || '';
+% if ( $saved_pkgpart =~ /^(\d+)_/ ) {
+% $saved_pkgpart = $1;
+% } else {
+% $saved_pkgpart = '';
+% }
+% $username = $cgi->param('username');
+% $password = $cgi->param('_password');
+% $popnum = $cgi->param('popnum');
+% @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
+% $same = $cgi->param('same');
+% $cust_main->setfield('paid' => $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
+% $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
+%} elsif ( $cgi->keywords ) { #editing
+% my( $query ) = $cgi->keywords;
+% $query =~ /^(\d+)$/;
+% $custnum=$1;
+% $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
+% if ( $cust_main->dbdef_table->column('paycvv')
+% && length($cust_main->paycvv) ) {
+% my $paycvv = $cust_main->paycvv;
+% $paycvv =~ s/./*/g;
+% $cust_main->paycvv($paycvv);
+% }
+% $saved_pkgpart = 0;
+% $saved_domsvc = 0;
+% $username = '';
+% $password = '';
+% $popnum = 0;
+% @invoicing_list = $cust_main->invoicing_list;
+% $ss = $cust_main->masked('ss');
+% $stateid = $cust_main->masked('stateid');
+% $payinfo = $cust_main->paymask;
+%} else {
+% $custnum='';
+% $cust_main = new FS::cust_main ( {} );
+% $cust_main->otaker( &getotaker );
+% $cust_main->referral_custnum( $cgi->param('referral_custnum') );
+% $saved_pkgpart = 0;
+% $saved_domsvc = 0;
+% $username = '';
+% $password = '';
+% $popnum = 0;
+% @invoicing_list = ();
+% push @invoicing_list, 'POST'
+% unless $conf->exists('disablepostalinvoicedefault');
+% $ss = '';
+% $stateid = '';
+% $payinfo = '';
+%}
+%$cgi->delete_all();
+%
+%my $action = $custnum ? 'Edit' : 'Add';
+%$action .= ": ". $cust_main->name if $custnum;
+%
+%my $r = qq!<font color="#ff0000">*</font> !;
+%
+%
+
+
+<!-- top -->
+
+<% include('/elements/header.html',
+ "Customer $action",
+ '',
+ ' onUnload="myclose()"'
+) %>
+% if ( $error ) {
+
+<FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT><BR><BR>
+% }
+
+
+<FORM NAME="topform" STYLE="margin-bottom: 0">
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
+% if ( $custnum ) {
+
+ Customer #<B><% $custnum %></B> -
+ <B><FONT COLOR="#<% $cust_main->statuscolor %>">
+ <% ucfirst($cust_main->status) %>
+ </FONT></B>
+ <BR><BR>
+% }
+
+
+<% &ntable("#cccccc") %>
+
+<!-- agent -->
+
+<% include('/elements/tr-select-agent.html',
+ 'curr_value' => $cust_main->agentnum,
+ 'label' => "<B>${r}Agent</B>",
+ 'empty_label' => 'Select agent',
+ 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
+ )
+%>
+
+<!-- referral (advertising source) -->
+%
+%my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
+%if ( $custnum && ! $conf->exists('editreferrals') ) {
+%
+
+
+ <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
+% } else {
+
+
+ <% include('/elements/tr-select-part_referral.html',
+ 'curr_value' => $refnum
+ )
+ %>
+% }
+
+
+<!-- referring customer -->
+%
+%my $referring_cust_main = '';
+%if ( $cust_main->referral_custnum
+% and $referring_cust_main =
+% qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
+%) {
+%
+
+
+ <TR>
+ <TD ALIGN="right">Referring customer</TD>
+ <TD>
+ <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name %></A>
+ </TD>
+ </TR>
+ <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
+% } elsif ( ! $conf->exists('disable_customer_referrals') ) {
+
+
+ <TR>
+ <TD ALIGN="right">Referring customer</TD>
+ <TD>
+ <!-- <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> -->
+ <% include('/elements/search-cust_main.html',
+ 'field_name' => 'referral_custnum',
+ )
+ %>
+ </TD>
+ </TR>
+% } else {
+
+
+ <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
+% }
+
+
+</TABLE>
+
+<!-- birthdate -->
+
+% if ( $conf->exists('cust_main-enable_birthdate') ) {
+
+ <BR>
+ <% ntable("#cccccc", 2) %>
+ <% include ('/elements/tr-input-date-field.html',
+ 'birthdate',
+ $cust_main->birthdate,
+ 'Date of Birth',
+ $conf->config('date_format') || "%m/%d/%Y",
+ 1)
+ %>
+
+ </TABLE>
+
+% }
+
+<!-- contact info -->
+
+% my $same_checked = '';
+% my $ship_disabled = '';
+% unless ( $cust_main->ship_last && $same ne 'Y' ) {
+% $same_checked = 'CHECKED';
+% $ship_disabled = 'DISABLED STYLE="background-color: #dddddd"';
+% foreach (
+% qw( last first company address1 address2 city county state zip country
+% daytime night fax )
+% ) {
+% $cust_main->set("ship_$_", $cust_main->get($_) );
+% }
+% }
+
+<BR><BR>
+Billing address
+<% include('cust_main/contact.html',
+ 'cust_main' => $cust_main,
+ 'pre' => '',
+ 'onchange' => 'bill_changed(this)',
+ 'disabled' => '',
+ 'ss' => $ss,
+ 'stateid' => $stateid,
+ 'same_checked' => $same_checked, #for address2 "Unit #" labeling
+ )
+%>