1 package FS::cust_main_invoice;
4 use vars qw(@ISA $conf);
6 use FS::Record qw( qsearchs );
11 @ISA = qw( FS::Record );
15 FS::cust_main_invoice - Object methods for cust_main_invoice records
19 use FS::cust_main_invoice;
21 $record = new FS::cust_main_invoice \%hash;
22 $record = new FS::cust_main_invoice { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
32 $email_address = $record->address;
36 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
37 FS::Record. The following fields are currently supported:
41 =item destnum - primary key
43 =item custnum - customer (see L<FS::cust_main>)
45 =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)
55 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 sub table { 'cust_main_invoice'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
71 Delete this record from the database.
73 =item replace OLD_RECORD
75 Replaces the OLD_RECORD with this one in the database. If there is an error,
76 returns the error, otherwise returns false.
81 my ( $new, $old ) = ( shift, shift );
83 return "Can't change custnum!" unless $old->custnum == $new->custnum;
85 $new->SUPER::replace($old);
91 Checks all fields to make sure this is a valid invoice destination. If there is
92 an error, returns the error, otherwise returns false. Called by the insert
100 my $error = $self->ut_numbern('destnum')
101 || $self->ut_number('custnum')
104 return $error if $error;
106 return "Unknown customer"
107 unless qsearchs('cust_main',{ 'custnum' => $self->custnum });
114 Checks the dest field only. If it finds that the account ends in the
115 same domain configured as the B<domain> configuration file, it will change the
116 invoice destination from an email address to a service number (see
124 my $error = $self->ut_text('dest');
125 return $error if $error;
127 if ( $self->dest eq 'POST' ) {
128 #contemplate our navel
129 } elsif ( $self->dest =~ /^(\d+)$/ ) {
130 return "Unknown local account (specified by svcnum: ". $self->dest. ")"
131 unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
132 } elsif ( $self->dest =~ /^([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)$/ ) {
133 my($user, $domain) = ($1, $2);
134 # if ( $domain eq $mydomain ) {
135 # my $svc_acct = qsearchs( 'svc_acct', { 'username' => $user } );
136 # return "Unknown local account: $user\@$domain (specified literally)"
138 # $svc_acct->svcnum =~ /^(\d+)$/ or die "Non-numeric svcnum?!";
141 $self->dest("$1\@$2");
143 return "Illegal destination!";
151 Returns the literal email address for this record (or `POST').
157 if ( $self->dest =~ /^(\d+)$/ ) {
158 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } )
170 $Id: cust_main_invoice.pm,v 1.10 2002-02-10 17:02:37 ivan Exp $
176 L<FS::Record>, L<FS::cust_main>