1 package FS::cust_main_invoice;
4 use vars qw(@ISA $conf $mydomain);
6 use FS::Record; # qw(qsearch qsearchs);
11 #ask FS::UID to run this stuff for us later
12 $FS::UID::callback{'FS::cust_main_invoice'} = sub {
14 $mydomain = $conf->config('domain');
19 FS::cust_main_invoice - Object methods for cust_main_invoice records
23 use FS::cust_main_invoice;
25 $record = create FS::cust_main_invoice \%hash;
26 $record = create FS::cust_main_invoice { 'column' => 'value' };
28 $error = $record->insert;
30 $error = $new_record->replace($old_record);
32 $error = $record->delete;
34 $error = $record->check;
36 $email_address = $record->address;
40 An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
41 FS::Record. The following fields are currently supported:
45 =item destnum - primary key
47 =item custnum - customer (see L<FS::cust_main>)
49 =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)
59 Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to. You can ask the object for a copy with the I<hash> method.
67 my($proto,$hashref)=@_;
69 $proto->new('cust_main_invoice',$hashref);
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
83 #local $SIG{HUP} = 'IGNORE';
84 #local $SIG{INT} = 'IGNORE';
85 #local $SIG{QUIT} = 'IGNORE';
86 #local $SIG{TERM} = 'IGNORE';
87 #local $SIG{TSTP} = 'IGNORE';
95 Delete this record from the database.
105 =item replace OLD_RECORD
107 Replaces the OLD_RECORD with this one in the database. If there is an error,
108 returns the error, otherwise returns false.
114 return "(Old) Not a cust_main_invoice record!" unless $old->table eq "cust_main_invoice";
116 return "Can't change destnum!"
117 unless $old->getfield('destnum') eq $new->getfield('destnum');
118 return "Can't change custnum!"
119 unless $old->getfield('custnum') eq $new->getfield('custnum');
128 Checks all fields to make sure this is a valid invoice destination. If there is
129 an error, returns the error, otherwise returns false. Called by the insert
136 return "Not a cust_main_invoice record!" unless $self->table eq "cust_main_invoice";
138 my $error = $self->ut_number('destnum')
139 or $self->ut_number('custnum')
140 or $self->ut_text('dest')
142 return $error if $error;
144 return "Unknown customer"
145 unless qsearchs('cust_main',{ 'custnum' => $self->custnum });
147 if ( $self->dest eq 'POST' ) {
148 #contemplate our navel
149 } elsif ( $self->dest =~ /^(\d+)$/ ) {
150 return "Unknown local account (specified by svcnum)"
151 unless qsearchs('svc_acct', { 'svcnum' => $self->dest } );
152 } elsif ( $self->dest =~ /^([\w\.\-]+)\@(([\w\.\-]\.)+\w+)$/ ) {
153 my($user, $domain) = ($1, $2);
154 if ( $domain eq $mydomain ) {
155 my $svc_acct = qsearchs('svc_acct', { 'username' => $user } );
156 return "Unknown local account (specified literally)" unless $svc_acct;
157 $svc_acct->svcnum =~ /^(\d+)$/ or die "Non-numeric svcnum?!";
161 return "Illegal destination!";
169 Returns the literal email address for this record (or `POST').
175 if ( $self->dest =~ /(\d+)$/ ) {
176 my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $1 } );
177 $svc_acct->username . '@' . $mydomain;
187 $Id: cust_main_invoice.pm,v 1.2 1998-12-16 09:58:53 ivan Exp $
193 L<FS::Record>, L<FS::cust_main>
197 ivan@voicenet.com 97-jul-1
200 ivan@sisd.com 97-nov-13
202 $Log: cust_main_invoice.pm,v $
203 Revision 1.2 1998-12-16 09:58:53 ivan
204 library support for editing email invoice destinations (not in sub collect yet)
206 Revision 1.1 1998/12/16 07:40:02 ivan
209 Revision 1.3 1998/11/15 04:33:00 ivan
210 updates for newest versoin
212 Revision 1.2 1998/11/15 03:48:49 ivan
213 update for current version