+ #save off and blank values that move to cust_contact / prospect_contact now
+ my $prospectnum = $self->prospectnum;
+ $self->prospectnum('');
+ my $custnum = $self->custnum;
+ $self->custnum(''); $old->custnum(''); # remove because now stored cust_contact
+
+ my %link_hash = ();
+ for (qw( classnum comment selfservice_access invoice_dest message_dest )) {
+ $link_hash{$_} = $self->get($_);
+ $old->$_(''); ##remove values from old record, causes problem with history
+ $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 = ();
+ $contact_nums{$self->contactnum} = '1' if $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 {
+ $contact_nums{$contact->contactnum} = '1';
+ }
+
+ }
+
+ ## were all emails duplicates? if so reset original emails
+ if (scalar @contact_emails < 1 && scalar (keys %contact_nums) > 1) {
+ foreach (qsearch('contact_email', {'contactnum' => $self->contactnum})) {
+ push @contact_emails, $_->emailaddress;
+ }
+ }
+
+ my $emails = join(' , ', @contact_emails);
+ $self->emailaddress($emails);
+
+ }
+