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 use FS::cust_main_invoice;
18 $record = new FS::cust_main_invoice \%hash;
19 $record = new FS::cust_main_invoice { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
29 $email_address = $record->address;
33 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
34 FS::Record. The following fields are currently supported:
38 =item destnum - primary key
40 =item custnum - customer (see L<FS::cust_main>)
42 =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.
52 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to. You can ask the object for a copy with the I<hash> method.
59 sub table { 'cust_main_invoice'; }
63 Adds this record to the database. If there is an error, returns the error,
64 otherwise returns false.
68 Delete this record from the database.
70 =item replace OLD_RECORD
72 Replaces the OLD_RECORD with this one in the database. If there is an error,
73 returns the error, otherwise returns false.
78 my ( $new, $old ) = ( shift, shift );
80 return "Can't change custnum!" unless $old->custnum == $new->custnum;
82 $new->SUPER::replace($old);
88 Checks all fields to make sure this is a valid invoice destination. If there is
89 an error, returns the error, otherwise returns false. Called by the insert
97 my $error = $self->ut_numbern('destnum')
98 || $self->ut_number('custnum')
101 return $error if $error;
108 Checks the dest field only.
110 #If it finds that the account ends in the
111 #same domain configured as the B<domain> configuration file, it will change the
112 #invoice destination from an email address to a service number (see
120 my $error = $self->ut_text('dest');
121 return $error if $error;
123 my $conf = new FS::Conf;
125 if ( $self->dest =~ /^(POST|FAX)$/ ) {
126 #contemplate our navel
127 } elsif ( $self->dest =~ /^(\d+)$/ ) {
128 return "Unknown local account (specified by svcnum: ". $self->dest. ")"
129 unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
130 } elsif ( $conf->exists('emailinvoice-apostrophe')
131 ? $self->dest =~ /^\s*([\w\.\-\&\+\']+)\@(([\w\.\-]+\.)+\w+)\s*$/
132 : $self->dest =~ /^\s*([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ){
133 my($user, $domain) = ($1, $2);
134 $self->dest("$1\@$2");
136 return gettext("illegal_email_invoice_address"). ': '. $self->dest;
144 Returns the literal email address for this record (or `POST' or `FAX').
150 if ( $self->dest =~ /^(\d+)$/ ) {
151 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } )
161 Returns the parent customer object (see L<FS::cust_main>).
169 L<FS::Record>, L<FS::cust_main>