-<%
-
-warn join('', map { "$_ => ". $cgi->param($_). "\n" } $cgi->param );
+% 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;
+
+</%once>
+<%init>
my $error = '';
} 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
);
}
+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');
#$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'));
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|CHEK|DCHK)$/ && $new->payinfo =~ /xx/) {
+ $new->payinfo($old->payinfo);
+ }
+
+ 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);
-}
-%>
+</%init>