2 use base qw( FS::Password_Mixin
6 use vars qw( $skip_fuzzyfiles );
8 use Scalar::Util qw( blessed );
9 use FS::Record qw( qsearch qsearchs dbh );
11 use FS::contact_phone;
12 use FS::contact_email;
13 use FS::contact::Import;
15 use FS::phone_type; #for cgi_contact_fields
17 use FS::prospect_contact;
23 FS::contact - Object methods for contact records
29 $record = new FS::contact \%hash;
30 $record = new FS::contact { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
42 An FS::contact object represents an specific contact person for a prospect or
43 customer. FS::contact inherits from FS::Record. The following fields are
80 =item selfservice_access
86 =item _password_encoding
102 Creates a new contact. To add the contact to the database, see L<"insert">.
104 Note that this stores the hash reference, not a distinct copy of the hash it
105 points to. You can ask the object for a copy with the I<hash> method.
109 sub table { 'contact'; }
113 Adds this record to the database. If there is an error, returns the error,
114 otherwise returns false.
116 If the object has an C<emailaddress> field, L<FS::contact_email> records
117 will be created for each (comma-separated) email address in that field. If
118 any of these coincide with an existing email address, this contact will be
119 merged with the contact with that address.
121 Then, if the object has any fields named C<phonetypenumN> an
122 L<FS::contact_phone> record will be created for each of them. Those fields
123 should contain phone numbers of the appropriate types (where N is the key of
124 an L<FS::phone_type> record identifying the type of number: daytime, night,
127 After inserting the record, if the object has a 'custnum' or 'prospectnum'
128 field, an L<FS::cust_contact> or L<FS::prospect_contact> record will be
129 created to link the contact to the customer. The following fields will also
130 be included in that record, if they are set on the object:
141 local $SIG{INT} = 'IGNORE';
142 local $SIG{QUIT} = 'IGNORE';
143 local $SIG{TERM} = 'IGNORE';
144 local $SIG{TSTP} = 'IGNORE';
145 local $SIG{PIPE} = 'IGNORE';
147 my $oldAutoCommit = $FS::UID::AutoCommit;
148 local $FS::UID::AutoCommit = 0;
151 #save off and blank values that move to cust_contact / prospect_contact now
152 my $prospectnum = $self->prospectnum;
153 $self->prospectnum('');
154 my $custnum = $self->custnum;
158 for (qw( classnum comment selfservice_access invoice_dest message_dest)) {
159 $link_hash{$_} = $self->get($_);
163 #look for an existing contact with this email address
164 my $existing_contact = '';
165 if ( $self->get('emailaddress') =~ /\S/ ) {
167 my %existing_contact = ();
169 foreach my $email ( split(/\s*,\s*/, $self->get('emailaddress') ) ) {
171 my $contact_email = qsearchs('contact_email', { emailaddress=>$email } )
174 my $contact = $contact_email->contact;
175 $existing_contact{ $contact->contactnum } = $contact;
179 if ( scalar( keys %existing_contact ) > 1 ) {
180 $dbh->rollback if $oldAutoCommit;
181 return 'Multiple email addresses specified '.
182 ' that already belong to separate contacts';
183 } elsif ( scalar( keys %existing_contact ) ) {
184 ($existing_contact) = values %existing_contact;
190 if ( $existing_contact ) {
192 $self->$_($existing_contact->$_())
193 for qw( contactnum _password _password_encoding );
194 $error = $self->SUPER::replace($existing_contact);
198 $error = $self->SUPER::insert;
203 $dbh->rollback if $oldAutoCommit;
207 my $cust_contact = '';
208 # if $self->custnum was set, then the customer-specific properties
209 # (custnum, classnum, invoice_dest, selfservice_access, comment) are in
210 # pseudo-fields, and are now in %link_hash. otherwise, ignore all those
213 my %hash = ( 'contactnum' => $self->contactnum,
214 'custnum' => $custnum,
216 $cust_contact = qsearchs('cust_contact', \%hash )
217 || new FS::cust_contact { %hash, %link_hash };
218 my $error = $cust_contact->custcontactnum ? $cust_contact->replace
219 : $cust_contact->insert;
221 $dbh->rollback if $oldAutoCommit;
226 if ( $prospectnum ) {
227 my %hash = ( 'contactnum' => $self->contactnum,
228 'prospectnum' => $prospectnum,
230 my $prospect_contact = qsearchs('prospect_contact', \%hash )
231 || new FS::prospect_contact { %hash, %link_hash };
233 $prospect_contact->prospectcontactnum ? $prospect_contact->replace
234 : $prospect_contact->insert;
236 $dbh->rollback if $oldAutoCommit;
241 foreach my $pf ( grep { /^phonetypenum(\d+)$/ && $self->get($_) =~ /\S/ }
242 keys %{ $self->hashref } ) {
243 $pf =~ /^phonetypenum(\d+)$/ or die "wtf (daily, the)";
244 my $phonetypenum = $1;
246 my %hash = ( 'contactnum' => $self->contactnum,
247 'phonetypenum' => $phonetypenum,
250 qsearchs('contact_phone', \%hash)
251 || new FS::contact_phone { %hash, _parse_phonestring($self->get($pf)) };
252 my $error = $contact_phone->contactphonenum ? $contact_phone->replace
253 : $contact_phone->insert;
255 $dbh->rollback if $oldAutoCommit;
260 if ( $self->get('emailaddress') =~ /\S/ ) {
262 foreach my $email ( split(/\s*,\s*/, $self->get('emailaddress') ) ) {
264 'contactnum' => $self->contactnum,
265 'emailaddress' => $email,
267 unless ( qsearchs('contact_email', \%hash) ) {
268 my $contact_email = new FS::contact_email \%hash;
269 my $error = $contact_email->insert;
271 $dbh->rollback if $oldAutoCommit;
279 unless ( $skip_fuzzyfiles ) { #unless ( $import || $skip_fuzzyfiles ) {
280 #warn " queueing fuzzyfiles update\n"
282 my $error = $self->queue_fuzzyfiles_update;
284 $dbh->rollback if $oldAutoCommit;
285 return "updating fuzzy search cache: $error";
289 if ( $link_hash{'selfservice_access'} eq 'R'
290 or ( $link_hash{'selfservice_access'}
292 && ! length($self->_password)
296 my $error = $self->send_reset_email( queue=>1 );
298 $dbh->rollback if $oldAutoCommit;
303 if ( $self->get('password') ) {
304 my $error = $self->is_password_allowed($self->get('password'))
305 || $self->change_password($self->get('password'));
307 $dbh->rollback if $oldAutoCommit;
312 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
320 Delete this record from the database.
327 local $SIG{HUP} = 'IGNORE';
328 local $SIG{INT} = 'IGNORE';
329 local $SIG{QUIT} = 'IGNORE';
330 local $SIG{TERM} = 'IGNORE';
331 local $SIG{TSTP} = 'IGNORE';
332 local $SIG{PIPE} = 'IGNORE';
334 my $oldAutoCommit = $FS::UID::AutoCommit;
335 local $FS::UID::AutoCommit = 0;
338 #got a prospetnum or custnum? delete the prospect_contact or cust_contact link
340 if ( $self->prospectnum ) {
341 my $prospect_contact = qsearchs('prospect_contact', {
342 'contactnum' => $self->contactnum,
343 'prospectnum' => $self->prospectnum,
345 my $error = $prospect_contact->delete;
347 $dbh->rollback if $oldAutoCommit;
352 # if $self->custnum was set, then we're removing the contact from this
354 if ( $self->custnum ) {
355 my $cust_contact = qsearchs('cust_contact', {
356 'contactnum' => $self->contactnum,
357 'custnum' => $self->custnum,
359 my $error = $cust_contact->delete;
361 $dbh->rollback if $oldAutoCommit;
366 # then, proceed with deletion only if the contact isn't attached to any other
367 # prospects or customers
369 #inefficient, but how many prospects/customers can a single contact be
370 # attached too? (and is removing them from one a common operation?)
371 if ( $self->prospect_contact || $self->cust_contact ) {
372 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
376 #proceed with deletion
378 foreach my $cust_pkg ( $self->cust_pkg ) {
379 $cust_pkg->contactnum('');
380 my $error = $cust_pkg->replace;
382 $dbh->rollback if $oldAutoCommit;
387 foreach my $object ( $self->contact_phone, $self->contact_email ) {
388 my $error = $object->delete;
390 $dbh->rollback if $oldAutoCommit;
395 my $error = $self->delete_password_history
396 || $self->SUPER::delete;
398 $dbh->rollback if $oldAutoCommit;
402 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
407 =item replace OLD_RECORD
409 Replaces the OLD_RECORD with this one in the database. If there is an error,
410 returns the error, otherwise returns false.
417 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
419 : $self->replace_old;
421 $self->$_( $self->$_ || $old->$_ ) for qw( _password _password_encoding );
423 local $SIG{INT} = 'IGNORE';
424 local $SIG{QUIT} = 'IGNORE';
425 local $SIG{TERM} = 'IGNORE';
426 local $SIG{TSTP} = 'IGNORE';
427 local $SIG{PIPE} = 'IGNORE';
429 my $oldAutoCommit = $FS::UID::AutoCommit;
430 local $FS::UID::AutoCommit = 0;
433 #save off and blank values that move to cust_contact / prospect_contact now
434 my $prospectnum = $self->prospectnum;
435 $self->prospectnum('');
436 my $custnum = $self->custnum;
437 $self->custnum(''); $old->custnum(''); # remove because now stored cust_contact
440 for (qw( classnum comment selfservice_access invoice_dest message_dest )) {
441 $link_hash{$_} = $self->get($_);
442 $old->$_(''); ##remove values from old record, causes problem with history
446 my $error = $self->SUPER::replace($old);
447 if ( $old->_password ne $self->_password ) {
448 $error ||= $self->insert_password_history;
451 $dbh->rollback if $oldAutoCommit;
455 my $cust_contact = '';
456 # if $self->custnum was set, then the customer-specific properties
457 # (custnum, classnum, invoice_dest, selfservice_access, comment) are in
458 # pseudo-fields, and are now in %link_hash. otherwise, ignore all those
461 my %hash = ( 'contactnum' => $self->contactnum,
462 'custnum' => $custnum,
465 if ( $cust_contact = qsearchs('cust_contact', \%hash ) ) {
466 $cust_contact->$_($link_hash{$_}) for keys %link_hash;
467 $error = $cust_contact->replace;
469 $cust_contact = new FS::cust_contact { %hash, %link_hash };
470 $error = $cust_contact->insert;
473 $dbh->rollback if $oldAutoCommit;
478 if ( $prospectnum ) {
479 my %hash = ( 'contactnum' => $self->contactnum,
480 'prospectnum' => $prospectnum,
483 if ( my $prospect_contact = qsearchs('prospect_contact', \%hash ) ) {
484 $prospect_contact->$_($link_hash{$_}) for keys %link_hash;
485 $error = $prospect_contact->replace;
487 my $prospect_contact = new FS::prospect_contact { %hash, %link_hash };
488 $error = $prospect_contact->insert;
491 $dbh->rollback if $oldAutoCommit;
496 foreach my $pf ( grep { /^phonetypenum(\d+)$/ }
497 keys %{ $self->hashref } ) {
498 $pf =~ /^phonetypenum(\d+)$/ or die "wtf (daily, the)";
499 my $phonetypenum = $1;
501 my %cp = ( 'contactnum' => $self->contactnum,
502 'phonetypenum' => $phonetypenum,
504 my $contact_phone = qsearchs('contact_phone', \%cp);
506 my $pv = $self->get($pf);
509 #if new value is empty, delete old entry
511 if ($contact_phone) {
512 $error = $contact_phone->delete;
514 $dbh->rollback if $oldAutoCommit;
521 $contact_phone ||= new FS::contact_phone \%cp;
523 my %cpd = _parse_phonestring( $pv );
524 $contact_phone->set( $_ => $cpd{$_} ) foreach keys %cpd;
526 my $method = $contact_phone->contactphonenum ? 'replace' : 'insert';
528 $error = $contact_phone->$method;
530 $dbh->rollback if $oldAutoCommit;
535 if ( defined($self->hashref->{'emailaddress'}) ) {
537 #ineffecient but whatever, how many email addresses can there be?
539 foreach my $contact_email ( $self->contact_email ) {
540 my $error = $contact_email->delete;
542 $dbh->rollback if $oldAutoCommit;
547 foreach my $email ( split(/\s*,\s*/, $self->get('emailaddress') ) ) {
549 my $contact_email = new FS::contact_email {
550 'contactnum' => $self->contactnum,
551 'emailaddress' => $email,
553 $error = $contact_email->insert;
555 $dbh->rollback if $oldAutoCommit;
563 unless ( $skip_fuzzyfiles ) { #unless ( $import || $skip_fuzzyfiles ) {
564 #warn " queueing fuzzyfiles update\n"
566 $error = $self->queue_fuzzyfiles_update;
568 $dbh->rollback if $oldAutoCommit;
569 return "updating fuzzy search cache: $error";
573 if ( $cust_contact and (
574 ( $cust_contact->selfservice_access eq ''
575 && $link_hash{selfservice_access}
576 && ! length($self->_password)
578 || $cust_contact->_resend()
582 my $error = $self->send_reset_email( queue=>1 );
584 $dbh->rollback if $oldAutoCommit;
589 if ( $self->get('password') ) {
590 my $error = $self->is_password_allowed($self->get('password'))
591 || $self->change_password($self->get('password'));
593 $dbh->rollback if $oldAutoCommit;
598 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
604 =item _parse_phonestring PHONENUMBER_STRING
606 Subroutine, takes a string and returns a list (suitable for assigning to a hash)
607 with keys 'countrycode', 'phonenum' and 'extension'
609 (Should probably be moved to contact_phone.pm, hence the initial underscore.)
613 sub _parse_phonestring {
616 my($countrycode, $extension) = ('1', '');
619 if ( $value =~ s/^\s*\+\s*(\d+)// ) {
625 if ( $value =~ s/\s*(ext|x)\s*(\d+)\s*$//i ) {
629 ( 'countrycode' => $countrycode,
630 'phonenum' => $value,
631 'extension' => $extension,
635 =item queue_fuzzyfiles_update
637 Used by insert & replace to update the fuzzy search cache
641 use FS::cust_main::Search;
642 sub queue_fuzzyfiles_update {
645 local $SIG{HUP} = 'IGNORE';
646 local $SIG{INT} = 'IGNORE';
647 local $SIG{QUIT} = 'IGNORE';
648 local $SIG{TERM} = 'IGNORE';
649 local $SIG{TSTP} = 'IGNORE';
650 local $SIG{PIPE} = 'IGNORE';
652 my $oldAutoCommit = $FS::UID::AutoCommit;
653 local $FS::UID::AutoCommit = 0;
656 foreach my $field ( 'first', 'last' ) {
657 my $queue = new FS::queue {
658 'job' => 'FS::cust_main::Search::append_fuzzyfiles_fuzzyfield'
660 my @args = "contact.$field", $self->get($field);
661 my $error = $queue->insert( @args );
663 $dbh->rollback if $oldAutoCommit;
664 return "queueing job (transaction rolled back): $error";
668 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
675 Checks all fields to make sure this is a valid contact. If there is
676 an error, returns the error, otherwise returns false. Called by the insert
684 if ( $self->selfservice_access eq 'R' || $self->selfservice_access eq 'P' ) {
685 $self->selfservice_access('Y');
690 $self->ut_numbern('contactnum')
691 || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
692 || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
693 || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
694 || $self->ut_foreign_keyn('classnum', 'contact_class', 'classnum')
695 || $self->ut_namen('last')
696 || $self->ut_namen('first')
697 || $self->ut_textn('title')
698 || $self->ut_textn('comment')
699 || $self->ut_enum('selfservice_access', [ '', 'Y' ])
700 || $self->ut_textn('_password')
701 || $self->ut_enum('_password_encoding', [ '', 'bcrypt'])
702 || $self->ut_enum('disabled', [ '', 'Y' ])
704 return $error if $error;
706 return "Prospect and customer!" if $self->prospectnum && $self->custnum;
708 return "One of first name, last name, or title must have a value"
709 if ! grep $self->$_(), qw( first last title);
716 Returns a formatted string representing this contact, including name, title and
723 my $data = $self->first. ' '. $self->last;
724 $data .= ', '. $self->title
726 $data .= ' ('. $self->comment. ')'
733 Returns a formatted string representing this contact, with just the name.
739 $self->first . ' ' . $self->last;
742 #=item contact_classname PROSPECT_OBJ | CUST_MAIN_OBJ
744 #Returns the name of this contact's class for the specified prospect or
745 #customer (see L<FS::prospect_contact>, L<FS::cust_contact> and
746 #L<FS::contact_class>).
750 #sub contact_classname {
751 # my( $self, $prospect_or_cust ) = @_;
754 # if ( ref($prospect_or_cust) eq 'FS::prospect_main' ) {
755 # $link = qsearchs('prospect_contact', {
756 # 'contactnum' => $self->contactnum,
757 # 'prospectnum' => $prospect_or_cust->prospectnum,
759 # } elsif ( ref($prospect_or_cust) eq 'FS::cust_main' ) {
760 # $link = qsearchs('cust_contact', {
761 # 'contactnum' => $self->contactnum,
762 # 'custnum' => $prospect_or_cust->custnum,
765 # croak "$prospect_or_cust is not an FS::prospect_main or FS::cust_main object";
768 # my $contact_class = $link->contact_class or return '';
769 # $contact_class->classname;
772 =item by_selfservice_email EMAILADDRESS
774 Alternate search constructor (class method). Given an email address, returns
775 the contact for that address. If that contact doesn't have selfservice access,
776 or there isn't one, returns the empty string.
780 sub by_selfservice_email {
781 my($class, $email) = @_;
783 my $contact_email = qsearchs({
784 'table' => 'contact_email',
785 'addl_from' => ' LEFT JOIN contact USING ( contactnum ) ',
786 'hashref' => { 'emailaddress' => $email, },
788 AND ( contact.disabled IS NULL )
789 AND EXISTS ( SELECT 1 FROM cust_contact
790 WHERE contact.contactnum = cust_contact.contactnum
791 AND cust_contact.selfservice_access = 'Y'
796 $contact_email->contact;
800 #these three functions are very much false laziness w/FS/FS/Auth/internal.pm
801 # and should maybe be libraried in some way for other password needs
803 use Crypt::Eksblowfish::Bcrypt qw( bcrypt_hash en_base64 de_base64);
805 sub authenticate_password {
806 my($self, $check_password) = @_;
808 if ( $self->_password_encoding eq 'bcrypt' ) {
810 my( $cost, $salt, $hash ) = split(',', $self->_password);
812 my $check_hash = en_base64( bcrypt_hash( { key_nul => 1,
814 salt => de_base64($salt),
820 $hash eq $check_hash;
824 return 0 if $self->_password eq '';
826 $self->_password eq $check_password;
832 =item change_password NEW_PASSWORD
834 Changes the contact's selfservice access password to NEW_PASSWORD. This does
835 not check password policy rules (see C<is_password_allowed>) and will return
836 an error only if editing the record fails for some reason.
838 If NEW_PASSWORD is the same as the existing password, this does nothing.
842 sub change_password {
843 my($self, $new_password) = @_;
845 # do nothing if the password is unchanged
846 return if $self->authenticate_password($new_password);
848 $self->change_password_fields( $new_password );
854 sub change_password_fields {
855 my($self, $new_password) = @_;
857 $self->_password_encoding('bcrypt');
861 my $salt = pack( 'C*', map int(rand(256)), 1..16 );
863 my $hash = bcrypt_hash( { key_nul => 1,
871 join(',', $cost, en_base64($salt), en_base64($hash) )
876 # end of false laziness w/FS/FS/Auth/internal.pm
879 #false laziness w/ClientAPI/MyAccount/reset_passwd
880 use Digest::SHA qw(sha512_hex);
882 use FS::ClientAPI_SessionCache;
883 sub send_reset_email {
884 my( $self, %opt ) = @_;
886 my @contact_email = $self->contact_email or return '';
888 my $reset_session = {
889 'contactnum' => $self->contactnum,
890 'svcnum' => $opt{'svcnum'},
894 my $conf = new FS::Conf;
896 ($conf->config('selfservice-password_reset_hours') || 24 ). ' hours';
898 my $reset_session_id;
900 $reset_session_id = sha512_hex(time(). {}. rand(). $$)
901 } until ( ! defined $self->myaccount_cache->get("reset_passwd_$reset_session_id") );
904 $self->myaccount_cache->set( "reset_passwd_$reset_session_id", $reset_session, $timeout );
909 my @cust_contact = grep $_->selfservice_access, $self->cust_contact;
910 $cust_main = $cust_contact[0]->cust_main if scalar(@cust_contact) == 1;
912 my $agentnum = $cust_main ? $cust_main->agentnum : '';
913 my $msgnum = $conf->config('selfservice-password_reset_msgnum', $agentnum);
914 #die "selfservice-password_reset_msgnum unset" unless $msgnum;
915 return "selfservice-password_reset_msgnum unset" unless $msgnum;
916 my $msg_template = qsearchs('msg_template', { msgnum => $msgnum } );
917 return "selfservice-password_reset_msgnum cannot be loaded" unless $msg_template;
919 'to' => join(',', map $_->emailaddress, @contact_email ),
920 'cust_main' => $cust_main,
922 'substitutions' => { 'session_id' => $reset_session_id }
925 if ( $opt{'queue'} ) { #or should queueing just be the default?
927 my $cust_msg = $msg_template->prepare( %msg_template );
928 my $error = $cust_msg->insert;
929 return $error if $error;
930 my $queue = new FS::queue {
931 'job' => 'FS::cust_msg::process_send',
932 'custnum' => $cust_main ? $cust_main->custnum : '',
934 $queue->insert( $cust_msg->custmsgnum );
938 $msg_template->send( %msg_template );
944 use vars qw( $myaccount_cache );
945 sub myaccount_cache {
947 $myaccount_cache ||= new FS::ClientAPI_SessionCache( {
948 'namespace' => 'FS::ClientAPI::MyAccount',
952 =item cgi_contact_fields
954 Returns a list reference containing the set of contact fields used in the web
955 interface for one-line editing (i.e. excluding contactnum, prospectnum, custnum
956 and locationnum, as well as password fields, but including fields for
957 contact_email and contact_phone records.)
961 sub cgi_contact_fields {
964 my @contact_fields = qw(
965 classnum first last title comment emailaddress selfservice_access
966 invoice_dest message_dest password
969 push @contact_fields, 'phonetypenum'. $_->phonetypenum
970 foreach qsearch({table=>'phone_type', order_by=>'weight'});
976 use FS::upgrade_journal;
977 sub _upgrade_data { #class method
978 my ($class, %opts) = @_;
980 # before anything else, migrate contact.custnum to cust_contact records
981 unless ( FS::upgrade_journal->is_done('contact_invoice_dest') ) {
983 local($skip_fuzzyfiles) = 1;
985 foreach my $contact (qsearch('contact', {})) {
986 my $error = $contact->replace;
987 die $error if $error;
990 FS::upgrade_journal->set_done('contact_invoice_dest');
994 # always migrate cust_main_invoice records over
995 local $FS::cust_main::import = 1; # override require_phone and such
996 my $search = FS::Cursor->new('cust_main_invoice', {});
998 while (my $cust_main_invoice = $search->fetch) {
999 my $custnum = $cust_main_invoice->custnum;
1000 my $dest = $cust_main_invoice->dest;
1001 my $cust_main = $cust_main_invoice->cust_main;
1003 if ( $dest =~ /^\d+$/ ) {
1004 my $svc_acct = FS::svc_acct->by_key($dest);
1005 die "custnum $custnum, invoice destination svcnum $svc_acct does not exist\n"
1007 $dest = $svc_acct->email;
1009 push @{ $custnum_dest{$custnum} ||= [] }, $dest;
1011 my $error = $cust_main_invoice->delete;
1013 die "custnum $custnum, cleaning up cust_main_invoice: $error\n";
1017 foreach my $custnum (keys %custnum_dest) {
1018 my $dests = $custnum_dest{$custnum};
1019 my $cust_main = FS::cust_main->by_key($custnum);
1020 my $error = $cust_main->replace( invoicing_list => $dests );
1022 die "custnum $custnum, creating contact: $error\n";
1034 L<FS::Record>, schema.html from the base documentation.