if ( $payby ) {
if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
- $cgi->param('payinfo',
- $cgi->param('payinfo1'). '@'. $cgi->param('payinfo2') );
+ my $payinfo = $cgi->param('payinfo1'). '@';
+ $payinfo .= $cgi->param('payinfo3').'.'
+ if $conf->config('echeck-country') eq 'CA';
+ $payinfo .= $cgi->param('payinfo2');
+ $cgi->param('payinfo',$payinfo);
}
$cgi->param('paydate',
$cgi->param( 'exp_month' ). '-'. $cgi->param( 'exp_year' ) );
} fields('cust_main')
} );
+$cgi->param('duplicate_of_custnum') =~ /^(\d+)$/;
+my $duplicate_of = $1;
+if ( $duplicate_of ) {
+ # then negate all changes to the customer; the only change we should
+ # make is to order a package, if requested
+ $new = qsearchs('cust_main', { 'custnum' => $duplicate_of })
+ # this should never happen
+ or die "nonexistent existing customer (custnum $duplicate_of)";
+}
+
if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
$new->setfield("ship_$_", '') foreach qw(
last first company address1 address2 city county state zip
$new->tagnum( [ $cgi->param('tagnum') ] );
-my %usedatetime = ( 'birthdate' => 1 );
+my %usedatetime = ( 'birthdate' => 1,
+ 'spouse_birthdate' => 1,
+ );
-foreach my $dfield (qw( birthdate signupdate )) {
+foreach my $dfield (qw( birthdate spouse_birthdate signupdate )) {
if ( $cgi->param($dfield) && $cgi->param($dfield) =~ /^([ 0-9\-\/]{0,10})$/) {
my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
my @tax_exempt = grep { $cgi->param("tax_$_") eq 'Y' } @exempt_groups;
+my %tax_exempt = map { $_ => scalar($cgi->param("tax_$_".'_num')) } @tax_exempt;
#perhaps this stuff should go to cust_main.pm
-if ( $new->custnum eq '' ) {
+if ( $new->custnum eq '' or $duplicate_of ) {
my $cust_pkg = '';
my $svc;
}
+
use Tie::RefHash;
tie my %hash, 'Tie::RefHash';
%hash = ( $cust_pkg => [ $svc ] ) if $cust_pkg;
- $error ||= $new->insert( \%hash, \@invoicing_list,
- 'tax_exemption'=> \@tax_exempt,
+ if ( $duplicate_of ) {
+ # order the package and service normally
+ $error ||= $new->order_pkgs( \%hash ) if $cust_pkg;
+ }
+ else {
+ # create the customer
+ $error ||= $new->insert( \%hash, \@invoicing_list,
+ 'tax_exemption'=> \%tax_exempt,
'prospectnum' => scalar($cgi->param('prospectnum')),
- );
+ );
- my $conf = new FS::Conf;
- if ( $conf->exists('backend-realtime') && ! $error ) {
+ 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;
+ my $berror = $new->bill
+ || $new->apply_payments_and_credits
+ || $new->collect( 'realtime' => 1 );
+ warn "Warning, error billing during backend-realtime: $berror" if $berror;
- }
+ }
+ } #if $duplicate_of
} else { #create old record object
local($FS::Record::DEBUG) = $DEBUG if $DEBUG;
$error ||= $new->replace( $old, \@invoicing_list,
- 'tax_exemption' => \@tax_exempt,
+ 'tax_exemption' => \%tax_exempt,
);
warn "$me returned from replace" if $DEBUG;
}
+unless ( $error ) { #XXX i guess i should be transactional... all in the insert
+ # or replace call
+ my @contact_fields = qw( classnum first last title comment emailaddress );
+ foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
+ push @contact_fields, 'phonetypenum'.$phone_type->phonetypenum;
+ }
+
+ $error = $new->process_o2m( 'table' => 'contact',
+ 'fields' => \@contact_fields,
+ 'params' => scalar($cgi->Vars),
+ );
+}
+
</%init>