2 % $cgi->param('error', $error);
4 <% $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string ) %>
8 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum) %>
14 unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
20 $cgi->param('tax','') unless defined $cgi->param('tax');
22 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
24 #my $payby = $cgi->param('payby');
25 my $payby = $cgi->param('select'); # XXX key
31 $payby = $noauto{$payby}
32 if ! $cgi->param('payauto') && exists $noauto{$payby};
34 $cgi->param('payby', $payby);
37 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
38 $cgi->param('payinfo',
39 $cgi->param('payinfo1'). '@'. $cgi->param('payinfo2') );
41 $cgi->param('paydate',
42 $cgi->param( 'exp_month' ). '-'. $cgi->param( 'exp_year' ) );
45 my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
46 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
47 push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
48 $cgi->param('invoicing_list', join(',', @invoicing_list) );
51 #create new record object
53 my $new = new FS::cust_main ( {
55 $_, scalar($cgi->param($_))
56 # } qw(custnum agentnum last first ss company address1 address2 city county
57 # state zip daytime night fax payby payinfo paydate payname tax
62 delete( $new->hashref->{'agent_custid'} )
63 unless $new->hashref->{'agent_custid'};
65 if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
66 $new->setfield("ship_$_", '') foreach qw(
67 last first company address1 address2 city county state zip
68 country daytime night fax
72 if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/) {
73 my $conf = new FS::Conf;
74 my $format = $conf->config('date_format') || "%m/%d/%Y";
75 my $parser = DateTime::Format::Strptime->new(pattern => $format,
76 time_zone => 'floating',
78 my $dt = $parser->parse_datetime($1);
80 $new->setfield('birthdate', $dt->epoch);
81 $cgi->param('birthdate', $dt->epoch);
83 # $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg;
84 $error ||= "Invalid birthdate: " . $cgi->param('birthdate') . ".";
85 $cgi->param('birthdate', '');
89 $new->setfield('paid', $cgi->param('paid') )
90 if $cgi->param('paid');
92 #perhaps this stuff should go to cust_main.pm
95 if ( $new->custnum eq '' ) {
97 if ( $cgi->param('pkgpart_svcpart') ) {
98 my $x = $cgi->param('pkgpart_svcpart');
99 $x =~ /^(\d+)_(\d+)$/ or die "illegal pkgpart_svcpart $x\n";
100 my($pkgpart, $svcpart) = ($1, $2);
101 #false laziness: copied from FS::cust_pkg::order (which should become a
102 #FS::cust_main method)
105 # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
106 my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
108 #foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
109 # my($pkgpart)=$type_pkgs->pkgpart;
110 # $part_pkg{$pkgpart}++;
112 # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
113 my $pkgpart_href = $agent->pkgpart_hashref;
116 # this should wind up in FS::cust_pkg!
117 $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't ".
118 "purchase pkgpart ". $pkgpart
119 #unless $part_pkg{ $pkgpart };
120 unless $pkgpart_href->{ $pkgpart };
122 $cust_pkg = new FS::cust_pkg ( {
123 #later 'custnum' => $custnum,
124 'pkgpart' => $pkgpart,
126 #$error ||= $cust_pkg->check;
128 #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
130 #$error ||= $cust_svc->check;
133 'svcpart' => $svcpart,
134 'username' => $cgi->param('username'),
135 '_password' => $cgi->param('_password'),
136 'popnum' => $cgi->param('popnum'),
138 $svc_acct{'domsvc'} = $cgi->param('domsvc')
139 if $cgi->param('domsvc');
141 $svc_acct = new FS::svc_acct \%svc_acct;
143 #and just in case you were silly
144 $svc_acct->svcpart($svcpart);
145 $svc_acct->username($cgi->param('username'));
146 $svc_acct->_password($cgi->param('_password'));
147 $svc_acct->popnum($cgi->param('popnum'));
149 #$error ||= $svc_acct->check;
151 } elsif ( $cgi->param('username') ) { #good thing to catch
152 $error = "Can't assign username without a package!";
156 tie my %hash, 'Tie::RefHash';
157 %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
158 $error ||= $new->insert( \%hash, \@invoicing_list );
160 my $conf = new FS::Conf;
161 if ( $conf->exists('backend-realtime') && ! $error ) {
163 my $berror = $new->bill
164 || $new->apply_payments_and_credits
165 || $new->collect( 'realtime' => 1 );
166 warn "Warning, error billing during backend-realtime: $berror" if $berror;
170 } else { #create old record object
172 my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
173 $error ||= "Old record not found!" unless $old;
174 if ( length($old->paycvv) && $new->paycvv =~ /^\s*\*+\s*$/ ) {
175 $new->paycvv($old->paycvv);
177 if ($new->ss =~ /xx/) {
180 if ($new->stateid =~ /^xxx/) {
181 $new->stateid($old->stateid);
183 if ($new->payby =~ /^(CARD|DCRD)$/ && $new->payinfo =~ /xx/) {
184 $new->payinfo($old->payinfo);
185 } elsif ($new->payby =~ /^(CHEK|DCHK)$/ && $new->payinfo =~ /xx/) {
186 #fix for #3085 "edit of customer's routing code only surprisingly causes
187 #nothing to happen...
188 # this probably won't do the right thing when we don't have the
189 # public key (can't actually get the real $old->payinfo)
190 my($new_account, $new_aba) = split('@', $new->payinfo);
191 my($old_account, $old_aba) = split('@', $old->payinfo);
192 $new_account = $old_account if $new_account =~ /xx/;
193 $new_aba = $old_aba if $new_aba =~ /xx/;
194 $new->payinfo($new_account.'@'.$new_aba);
196 $error ||= $new->replace($old, \@invoicing_list);