+ if ( @param && ref($param[0]) eq 'ARRAY' ) { # INVOICING_LIST_ARYREF
+ my $invoicing_list = shift @param;
+ my $email = '';
+ foreach (@$invoicing_list) {
+ if ($_ eq 'POST') {
+ $self->set('postal_invoice', 'Y');
+ } else {
+ $email .= ',' if length($email);
+ $email .= $_;
+ }
+ }
+ my @contacts = map { $_->contact } $self->cust_contact;
+ # if possible, use a contact that matches the customer's name
+ my ($contact) = grep { $_->first eq $old->get('first') and
+ $_->last eq $old->get('last') }
+ @contacts;
+ $contact ||= FS::contact->new({
+ 'custnum' => $self->custnum,
+ 'locationnum' => $self->get('bill_locationnum'),
+ });
+ $contact->set('last', $self->get('last'));
+ $contact->set('first', $self->get('first'));
+ $contact->set('emailaddress', $email);
+ $contact->set('invoice_dest', 'Y');
+
+ my $error;
+ if ( $contact->contactnum ) {
+ $error = $contact->replace;
+ } elsif ( length($email) ) { # don't create a new contact if email is empty
+ $error = $contact->insert;
+ }
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ }
+