X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_main.cgi;h=ddcb3cac82f80592333d70d514f255dbaa66ba8a;hb=a8d483fa8f540586674300da75f2b5c5b4bb7b15;hp=d2773a60e3fcd0d173479776ccc2065202357655;hpb=18c025613fa052cf4ba8d484f1296cc2a1719a24;p=freeside.git diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index d2773a60e..ddcb3cac8 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -1,4 +1,23 @@ -<% +% if ( $error ) { +% $cgi->param('error', $error); +% +<% $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string ) %> +% +% } else { +% +<% $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum) %> +% +% } +<%once> + +my $me = '[edit/process/cust_main.cgi]'; +my $DEBUG = 0; + + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Edit customer'); my $error = ''; @@ -8,19 +27,25 @@ $cgi->param('tax','') unless defined $cgi->param('tax'); $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] ); -my $payby = $cgi->param('payby'); +#my $payby = $cgi->param('payby'); +my $payby = $cgi->param('select'); # XXX key + +my %noauto = ( + 'CARD' => 'DCRD', + 'CHEK' => 'DCHK', +); +$payby = $noauto{$payby} + if ! $cgi->param('payauto') && exists $noauto{$payby}; + +$cgi->param('payby', $payby); + if ( $payby ) { if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) { $cgi->param('payinfo', - $cgi->param($payby. '_payinfo1'). '@'. $cgi->param($payby. '_payinfo2') ); - } else { - $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) ); + $cgi->param('payinfo1'). '@'. $cgi->param('payinfo2') ); } $cgi->param('paydate', - $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) ); - $cgi->param('payname', $cgi->param( $payby. '_payname' ) ); - $cgi->param('paycvv', $cgi->param( $payby. '_paycvv' ) ) - if defined $cgi->param( $payby. '_paycvv' ); + $cgi->param( 'exp_month' ). '-'. $cgi->param( 'exp_year' ) ); } my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') ); @@ -40,6 +65,9 @@ my $new = new FS::cust_main ( { } fields('cust_main') } ); + delete( $new->hashref->{'agent_custid'} ) + unless $new->hashref->{'agent_custid'}; + if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) { $new->setfield("ship_$_", '') foreach qw( last first company address1 address2 city county state zip @@ -47,6 +75,26 @@ if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) { ); } +if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/) { + my $conf = new FS::Conf; + my $format = $conf->config('date_format') || "%m/%d/%Y"; + my $parser = DateTime::Format::Strptime->new(pattern => $format, + time_zone => 'floating', + ); + my $dt = $parser->parse_datetime($1); + if ($dt) { + $new->setfield('birthdate', $dt->epoch); + $cgi->param('birthdate', $dt->epoch); + } else { +# $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg; + $error ||= "Invalid birthdate: " . $cgi->param('birthdate') . "."; + $cgi->param('birthdate', ''); + } +} + +$new->setfield('paid', $cgi->param('paid') ) + if $cgi->param('paid'); + #perhaps this stuff should go to cust_main.pm my $cust_pkg = ''; my $svc_acct = ''; @@ -87,15 +135,17 @@ if ( $new->custnum eq '' ) { #$error ||= $cust_svc->check; - $svc_acct = new FS::svc_acct ( { - 'svcpart' => $svcpart, - 'username' => $cgi->param('username'), - '_password' => $cgi->param('_password'), - 'popnum' => $cgi->param('popnum'), - } ); + my %svc_acct = ( + 'svcpart' => $svcpart, + 'username' => $cgi->param('username'), + '_password' => $cgi->param('_password'), + 'popnum' => $cgi->param('popnum'), + ); + $svc_acct{'domsvc'} = $cgi->param('domsvc') + if $cgi->param('domsvc'); + + $svc_acct = new FS::svc_acct \%svc_acct; - my $y = $svc_acct->setdefault; # arguably should be in new method - $error ||= $y unless ref($y); #and just in case you were silly $svc_acct->svcpart($svcpart); $svc_acct->username($cgi->param('username')); @@ -112,21 +162,52 @@ if ( $new->custnum eq '' ) { tie my %hash, 'Tie::RefHash'; %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg; $error ||= $new->insert( \%hash, \@invoicing_list ); + + my $conf = new FS::Conf; + if ( $conf->exists('backend-realtime') && ! $error ) { + + my $berror = $new->bill + || $new->apply_payments_and_credits + || $new->collect( 'realtime' => 1 ); + warn "Warning, error billing during backend-realtime: $berror" if $berror; + + } + } else { #create old record object + my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } ); $error ||= "Old record not found!" unless $old; - if ( defined dbdef->table('cust_main')->column('paycvv') - && length($old->paycvv) - && $new->paycvv =~ /^\s*\*+\s*$/ ) { + if ( length($old->paycvv) && $new->paycvv =~ /^\s*\*+\s*$/ ) { $new->paycvv($old->paycvv); } + if ($new->ss =~ /xx/) { + $new->ss($old->ss); + } + if ($new->stateid =~ /^xxx/) { + $new->stateid($old->stateid); + } + if ($new->payby =~ /^(CARD|DCRD)$/ && $new->payinfo =~ /xx/) { + $new->payinfo($old->payinfo); + } elsif ($new->payby =~ /^(CHEK|DCHK)$/ && $new->payinfo =~ /xx/) { + #fix for #3085 "edit of customer's routing code only surprisingly causes + #nothing to happen... + # this probably won't do the right thing when we don't have the + # public key (can't actually get the real $old->payinfo) + my($new_account, $new_aba) = split('@', $new->payinfo); + my($old_account, $old_aba) = split('@', $old->payinfo); + $new_account = $old_account if $new_account =~ /xx/; + $new_aba = $old_aba if $new_aba =~ /xx/; + $new->payinfo($new_account.'@'.$new_aba); + } + + warn "$me calling $new -> replace( $old, \ @invoicing_list )" if $DEBUG; + local($FS::cust_main::DEBUG) = $DEBUG if $DEBUG; + local($FS::Record::DEBUG) = $DEBUG if $DEBUG; + $error ||= $new->replace($old, \@invoicing_list); + + warn "$me returned from replace" if $DEBUG; + } -if ( $error ) { - $cgi->param('error', $error); - print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string ); -} else { - print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum); -} -%> +