summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Burger <burgerc@freeside.biz>2019-01-21 14:12:14 -0500
committerChristopher Burger <burgerc@freeside.biz>2019-01-22 11:05:47 -0500
commitf2fc2590baf357d179126fc2ad0ea8a9348ac945 (patch)
treefe0b8ca82efac34f1ec5588020347a59d6f48cf9
parenta0a446d2f9b98e706bd221159f9212fa0cac0af8 (diff)
RT# 79352 - updated contact replace to attach existing contact to customer
-rw-r--r--FS/FS/contact.pm59
1 files changed, 45 insertions, 14 deletions
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 1801545..2c208c5 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -443,6 +443,33 @@ sub replace {
$self->$_('');
}
+ ## check for an existing contact with this email address other than current customer
+ ## if found, just add that contact to cust_contact with link_hash credentials
+ ## as email can not be tied to two contacts.
+ my @contact_emails = ();
+ my @contact_nums = ($self->contactnum,);
+ if ( $self->get('emailaddress') =~ /\S/ ) {
+
+ foreach my $email ( split(/\s*,\s*/, $self->get('emailaddress') ) ) {
+
+ my $contact_email = qsearchs('contact_email', { emailaddress=>$email } );
+ unless ($contact_email) { push @contact_emails, $email; next; }
+
+ my $contact = $contact_email->contact;
+ if ($contact->contactnum eq $self->contactnum) {
+ push @contact_emails, $email;
+ }
+ else {
+ push @contact_nums, $contact->contactnum;
+ }
+
+ }
+
+ my $emails = join(' , ', @contact_emails);
+ $self->emailaddress($emails);
+
+ }
+
my $error = $self->SUPER::replace($old);
if ( $old->_password ne $self->_password ) {
$error ||= $self->insert_password_history;
@@ -458,20 +485,24 @@ sub replace {
# pseudo-fields, and are now in %link_hash. otherwise, ignore all those
# fields.
if ( $custnum ) {
- my %hash = ( 'contactnum' => $self->contactnum,
- 'custnum' => $custnum,
- );
- my $error;
- if ( $cust_contact = qsearchs('cust_contact', \%hash ) ) {
- $cust_contact->$_($link_hash{$_}) for keys %link_hash;
- $error = $cust_contact->replace;
- } else {
- $cust_contact = new FS::cust_contact { %hash, %link_hash };
- $error = $cust_contact->insert;
- }
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
+
+ foreach my $contactnum (@contact_nums) {
+
+ my %hash = ( 'contactnum' => $contactnum, #$self->contactnum,
+ 'custnum' => $custnum,
+ );
+ my $error;
+ if ( $cust_contact = qsearchs('cust_contact', \%hash ) ) {
+ $cust_contact->$_($link_hash{$_}) for keys %link_hash;
+ $error = $cust_contact->replace;
+ } else {
+ $cust_contact = new FS::cust_contact { %hash, %link_hash };
+ $error = $cust_contact->insert;
+ }
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
}
}