+ # always migrate cust_main_invoice records over
+ local $FS::cust_main::import = 1; # override require_phone and such
+ my $search = FS::Cursor->new('cust_main_invoice', {});
+ while (my $cust_main_invoice = $search->fetch) {
+ my $custnum = $cust_main_invoice->custnum;
+ my $dest = $cust_main_invoice->dest;
+ my $cust_main = $cust_main_invoice->cust_main;
+
+ if ( $dest =~ /^\d+$/ ) {
+ my $svc_acct = FS::svc_acct->by_key($dest);
+ die "custnum $custnum, invoice destination svcnum $svc_acct does not exist\n"
+ if !$svc_acct;
+ $dest = $svc_acct->email;
+ }
+
+ my $error = $cust_main->replace( invoicing_list => [ $dest ] );
+
+ if ( $error ) {
+ die "custnum $custnum, invoice destination $dest, creating contact: $error\n";
+ }
+
+ $error = $cust_main_invoice->delete;
+ die "custnum $custnum, cleaning up cust_main_invoice: $error\n" if $error;
+
+ } # while $search->fetch
+
+ unless ( FS::upgrade_journal->is_done('contact_invoice_dest') ) {