1 package FS::cust_main_invoice;
4 use vars qw(@ISA $conf $mydomain);
6 use FS::Record qw( qsearchs );
11 @ISA = qw( FS::Record );
13 #ask FS::UID to run this stuff for us later
14 $FS::UID::callback{'FS::cust_main_invoice'} = sub {
16 $mydomain = $conf->config('domain');
21 FS::cust_main_invoice - Object methods for cust_main_invoice records
25 use FS::cust_main_invoice;
27 $record = new FS::cust_main_invoice \%hash;
28 $record = new FS::cust_main_invoice { 'column' => 'value' };
30 $error = $record->insert;
32 $error = $new_record->replace($old_record);
34 $error = $record->delete;
36 $error = $record->check;
38 $email_address = $record->address;
42 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
43 FS::Record. The following fields are currently supported:
47 =item destnum - primary key
49 =item custnum - customer (see L<FS::cust_main>)
51 =item dest - Invoice destination: If numeric, a <a href="#svc_acct">svcnum</a>, if string, a literal email address, or `POST' to enable mailing (the default if no cust_main_invoice records exist)
61 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
63 Note that this stores the hash reference, not a distinct copy of the hash it
64 points to. You can ask the object for a copy with the I<hash> method.
68 sub table { 'cust_main_invoice'; }
72 Adds this record to the database. If there is an error, returns the error,
73 otherwise returns false.
77 Delete this record from the database.
79 =item replace OLD_RECORD
81 Replaces the OLD_RECORD with this one in the database. If there is an error,
82 returns the error, otherwise returns false.
87 my ( $new, $old ) = ( shift, shift );
89 return "Can't change custnum!" unless $old->custnum eq $new->custnum;
97 Checks all fields to make sure this is a valid invoice destination. If there is
98 an error, returns the error, otherwise returns false. Called by the insert
106 my $error = $self->ut_number('destnum')
107 or $self->ut_number('custnum')
108 or $self->ut_text('dest')
110 return $error if $error;
112 return "Unknown customer"
113 unless qsearchs('cust_main',{ 'custnum' => $self->custnum });
115 if ( $self->dest eq 'POST' ) {
116 #contemplate our navel
117 } elsif ( $self->dest =~ /^(\d+)$/ ) {
118 return "Unknown local account (specified by svcnum)"
119 unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
120 } elsif ( $self->dest =~ /^([\w\.\-]+)\@(([\w\.\-]\.)+\w+)$/ ) {
121 my($user, $domain) = ($1, $2);
122 if ( $domain eq $mydomain ) {
123 my $svc_acct = qsearchs( 'svc_acct', { 'username' => $user } );
124 return "Unknown local account (specified literally)" unless $svc_acct;
125 $svc_acct->svcnum =~ /^(\d+)$/ or die "Non-numeric svcnum?!";
129 return "Illegal destination!";
137 Returns the literal email address for this record (or `POST').
143 if ( $self->dest =~ /(\d+)$/ ) {
144 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } );
145 $svc_acct->username . '@' . $mydomain;
155 $Id: cust_main_invoice.pm,v 1.3 1998-12-29 11:59:42 ivan Exp $
161 L<FS::Record>, L<FS::cust_main>
165 ivan@voicenet.com 97-jul-1
168 ivan@sisd.com 97-nov-13
170 $Log: cust_main_invoice.pm,v $
171 Revision 1.3 1998-12-29 11:59:42 ivan
172 mostly properly OO, some work still to be done with svc_ stuff
174 Revision 1.2 1998/12/16 09:58:53 ivan
175 library support for editing email invoice destinations (not in sub collect yet)
177 Revision 1.1 1998/12/16 07:40:02 ivan
180 Revision 1.3 1998/11/15 04:33:00 ivan
181 updates for newest versoin
183 Revision 1.2 1998/11/15 03:48:49 ivan
184 update for current version