+ } # else it stays equal to $bill_location
+
+ # Step 2: Extract shipping address contact fields into contact
+ my %unlike = map { $_ => 1 }
+ grep { $cust_main->get($_) ne $cust_main->get("ship_$_") }
+ qw( last first company daytime night fax mobile );
+
+ if ( %unlike ) {
+ # then there IS a service contact
+ my $contact = FS::contact->new({
+ 'custnum' => $custnum,
+ 'classnum' => $opt{service_contact_class}->classnum,
+ 'locationnum' => $ship_location->locationnum,
+ 'last' => $cust_main->get('ship_last'),
+ 'first' => $cust_main->get('ship_first'),
+ });
+ if ( !$cust_main->get('ship_last') or !$cust_main->get('ship_first') )
+ {
+ warn "customer $custnum has no service contact name; substituting ".
+ "customer name\n";
+ $contact->set('last' => $cust_main->get('last'));
+ $contact->set('first' => $cust_main->get('first'));
+ }
+
+ if ( $unlike{'company'} ) {
+ # there's no contact.company field, but keep a record of it
+ $contact->set(comment => 'Company: '.$cust_main->get('ship_company'));
+ }
+ $error = $contact->insert;
+ return "error migrating service contact for customer $custnum: $error"