1 package FS::cust_main_invoice;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearchs );
8 use FS::Msgcat qw(gettext);
12 FS::cust_main_invoice - Object methods for cust_main_invoice records
16 This is deprecated in version 4. Instead, contacts with the "invoice_dest"
17 attribute should be used.
21 use FS::cust_main_invoice;
23 $record = new FS::cust_main_invoice \%hash;
24 $record = new FS::cust_main_invoice { 'column' => 'value' };
26 $error = $record->insert;
28 $error = $new_record->replace($old_record);
30 $error = $record->delete;
32 $error = $record->check;
34 $email_address = $record->address;
38 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
39 FS::Record. The following fields are currently supported:
43 =item destnum - primary key
45 =item custnum - customer (see L<FS::cust_main>)
47 =item dest - Invoice destination: If numeric, a svcnum (see L<FS::svc_acct>), if string, a literal email address, `POST' to enable mailing (the default if no cust_main_invoice records exist), or `FAX' to enable faxing via a HylaFAX server.
57 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to. You can ask the object for a copy with the I<hash> method.
64 sub table { 'cust_main_invoice'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 Delete this record from the database.
75 =item replace OLD_RECORD
77 Replaces the OLD_RECORD with this one in the database. If there is an error,
78 returns the error, otherwise returns false.
83 my ( $new, $old ) = ( shift, shift );
85 return "Can't change custnum!" unless $old->custnum == $new->custnum;
87 $new->SUPER::replace($old);
93 Checks all fields to make sure this is a valid invoice destination. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
102 my $error = $self->ut_numbern('destnum')
103 || $self->ut_number('custnum')
106 return $error if $error;
113 Checks the dest field only.
115 #If it finds that the account ends in the
116 #same domain configured as the B<domain> configuration file, it will change the
117 #invoice destination from an email address to a service number (see
125 my $error = $self->ut_text('dest');
126 return $error if $error;
128 my $conf = new FS::Conf;
130 if ( $self->dest =~ /^(POST|FAX)$/ ) {
131 #contemplate our navel
132 } elsif ( $self->dest =~ /^(\d+)$/ ) {
133 return "Unknown local account (specified by svcnum: ". $self->dest. ")"
134 unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
135 } elsif ( $conf->exists('emailinvoice-apostrophe')
136 ? $self->dest =~ /^\s*([\w\.\-\&\+\']+)\@(([\w\.\-]+\.)+\w+)\s*$/
137 : $self->dest =~ /^\s*([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ){
138 my($user, $domain) = ($1, $2);
139 $self->dest("$1\@$2");
141 return gettext("illegal_email_invoice_address"). ': '. $self->dest;
149 Returns the literal email address for this record (or `POST' or `FAX').
155 if ( $self->dest =~ /^(\d+)$/ ) {
156 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } )
166 Returns the parent customer object (see L<FS::cust_main>).
174 L<FS::Record>, L<FS::cust_main>