1 package FS::cust_main_invoice;
6 use FS::Record qw( qsearchs );
10 use FS::Msgcat qw(gettext);
12 @ISA = qw( FS::Record );
16 FS::cust_main_invoice - Object methods for cust_main_invoice records
20 use FS::cust_main_invoice;
22 $record = new FS::cust_main_invoice \%hash;
23 $record = new FS::cust_main_invoice { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
33 $email_address = $record->address;
37 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
38 FS::Record. The following fields are currently supported:
42 =item destnum - primary key
44 =item custnum - customer (see L<FS::cust_main>)
46 =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.
56 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to. You can ask the object for a copy with the I<hash> method.
63 sub table { 'cust_main_invoice'; }
67 Adds this record to the database. If there is an error, returns the error,
68 otherwise returns false.
72 Delete this record from the database.
74 =item replace OLD_RECORD
76 Replaces the OLD_RECORD with this one in the database. If there is an error,
77 returns the error, otherwise returns false.
82 my ( $new, $old ) = ( shift, shift );
84 return "Can't change custnum!" unless $old->custnum == $new->custnum;
86 $new->SUPER::replace($old);
92 Checks all fields to make sure this is a valid invoice destination. If there is
93 an error, returns the error, otherwise returns false. Called by the insert
101 my $error = $self->ut_numbern('destnum')
102 || $self->ut_number('custnum')
105 return $error if $error;
107 return "Unknown customer"
108 unless qsearchs('cust_main',{ 'custnum' => $self->custnum });
115 Checks the dest field only.
117 #If it finds that the account ends in the
118 #same domain configured as the B<domain> configuration file, it will change the
119 #invoice destination from an email address to a service number (see
127 my $error = $self->ut_text('dest');
128 return $error if $error;
130 my $conf = new FS::Conf;
132 if ( $self->dest =~ /^(POST|FAX)$/ ) {
133 #contemplate our navel
134 } elsif ( $self->dest =~ /^(\d+)$/ ) {
135 return "Unknown local account (specified by svcnum: ". $self->dest. ")"
136 unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
137 } elsif ( $conf->exists('emailinvoice-apostrophe')
138 ? $self->dest =~ /^\s*([\w\.\-\&\+\']+)\@(([\w\.\-]+\.)+\w+)\s*$/
139 : $self->dest =~ /^\s*([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ){
140 my($user, $domain) = ($1, $2);
141 $self->dest("$1\@$2");
143 return gettext("illegal_email_invoice_address"). ': '. $self->dest;
151 Returns the literal email address for this record (or `POST' or `FAX').
157 if ( $self->dest =~ /^(\d+)$/ ) {
158 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } )
168 Returns the parent customer object (see L<FS::cust_main>).
174 qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
183 L<FS::Record>, L<FS::cust_main>