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
my @tax_exempt = grep { $cgi->param("tax_$_") eq 'Y' } @exempt_groups;
#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,
+ 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
}
+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>