1 package FS::cust_main_invoice;
4 use vars qw(@ISA $conf);
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, or `POST' to enable mailing (the default if no cust_main_invoice records exist)
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 if ( $self->dest eq 'POST' ) {
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 ( $self->dest =~ /^([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)$/ ) {
136 my($user, $domain) = ($1, $2);
137 $self->dest("$1\@$2");
139 return gettext("illegal_email_invoice_address");
147 Returns the literal email address for this record (or `POST').
153 if ( $self->dest =~ /^(\d+)$/ ) {
154 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } )
168 L<FS::Record>, L<FS::cust_main>