package FS::cust_main_invoice;
use strict;
-use vars qw(@ISA $conf);
+use vars qw(@ISA $conf $mydomain);
use Exporter;
-use FS::Record; # qw(qsearch qsearchs);
+use FS::Record qw( qsearchs );
use FS::Conf;
+use FS::cust_main;
+use FS::svc_acct;
-@ISA = qw(FS::Record);
+@ISA = qw( FS::Record );
-$conf = new FS::Conf;
-my $mydomain = $conf->config('domain');
+#ask FS::UID to run this stuff for us later
+$FS::UID::callback{'FS::cust_main_invoice'} = sub {
+ $conf = new FS::Conf;
+ $mydomain = $conf->config('domain');
+};
=head1 NAME
use FS::cust_main_invoice;
- $record = create FS::cust_main_invoice \%hash;
- $record = create FS::cust_main_invoice { 'column' => 'value' };
+ $record = new FS::cust_main_invoice \%hash;
+ $record = new FS::cust_main_invoice { 'column' => 'value' };
$error = $record->insert;
$error = $record->check;
+ $email_address = $record->address;
+
=head1 DESCRIPTION
An FS::cust_main_invoice object represents an invoice destination. FS::cust_main_invoice inherits from
=over 4
-=item create HASHREF
+=item new HASHREF
Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">.
=cut
-sub create {
- my($proto,$hashref)=@_;
-
- $proto->new('cust_main_invoice',$hashref);
-
-}
+sub table { 'cust_main_invoice'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
-=cut
-
-sub insert {
- my($self)=@_;
-
- #local $SIG{HUP} = 'IGNORE';
- #local $SIG{INT} = 'IGNORE';
- #local $SIG{QUIT} = 'IGNORE';
- #local $SIG{TERM} = 'IGNORE';
- #local $SIG{TSTP} = 'IGNORE';
-
- $self->check or
- $self->add;
-}
-
=item delete
Delete this record from the database.
-=cut
-
-sub delete {
- my($self)=@_;
-
- $self->del;
-}
-
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
=cut
sub replace {
- my($new,$old)=@_;
- return "(Old) Not a cust_main_invoice record!" unless $old->table eq "cust_main_invoice";
+ my ( $new, $old ) = ( shift, shift );
- return "Can't change destnum!"
- unless $old->getfield('destnum') eq $new->getfield('destnum');
- return "Can't change custnum!"
- unless $old->getfield('custnum') eq $new->getfield('custnum');
+ return "Can't change custnum!" unless $old->custnum == $new->custnum;
- $new->check or
- $new->rep($old);
+ $new->SUPER::replace;
}
=cut
sub check {
- my($self)=@_;
- return "Not a cust_main_invoice record!" unless $self->table eq "cust_main_invoice";
+ my $self = shift;
- my $error = $self->ut_number('destnum')
- or $self->ut_number('custnum')
- or $self->ut_text('dest')
+ my $error = $self->ut_numbern('destnum')
+ || $self->ut_number('custnum')
+ || $self->checkdest;
;
return $error if $error;
return "Unknown customer"
unless qsearchs('cust_main',{ 'custnum' => $self->custnum });
+ ''; #noerror
+}
+
+=item checkdest
+
+Checks the dest field only.
+
+=cut
+
+sub checkdest {
+ my $self = shift;
+
+ my $error = $self->ut_text('dest');
+ return $error if $error;
+
if ( $self->dest eq 'POST' ) {
#contemplate our navel
} elsif ( $self->dest =~ /^(\d+)$/ ) {
return "Unknown local account (specified by svcnum)"
- unless qsearchs('svc_acct', { 'svcnum' => $self->dest } );
- } elsif ( $self->dest =~ /^([\w\.\-]+)\@(([\w\.\-]\.)+\w+)$/ ) {
+ unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
+ } elsif ( $self->dest =~ /^([\w\.\-]+)\@(([\w\.\-]+\.)+\w+)$/ ) {
my($user, $domain) = ($1, $2);
if ( $domain eq $mydomain ) {
- my $svc_acct = qsearchs('svc_acct', { 'username' => $user } );
+ my $svc_acct = qsearchs( 'svc_acct', { 'username' => $user } );
return "Unknown local account (specified literally)" unless $svc_acct;
$svc_acct->svcnum =~ /^(\d+)$/ or die "Non-numeric svcnum?!";
$self->dest($1);
''; #no error
}
+=item address
+
+Returns the literal email address for this record (or `POST').
+
+=cut
+
+sub address {
+ my $self = shift;
+ if ( $self->dest =~ /(\d+)$/ ) {
+ my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } );
+ $svc_acct->username . '@' . $mydomain;
+ } else {
+ $self->dest;
+ }
+}
+
=back
=head1 VERSION
-$Id: cust_main_invoice.pm,v 1.1 1998-12-16 07:40:02 ivan Exp $
+$Id: cust_main_invoice.pm,v 1.6 1999-01-25 12:26:10 ivan Exp $
=head1 BUGS
ivan@sisd.com 97-nov-13
$Log: cust_main_invoice.pm,v $
-Revision 1.1 1998-12-16 07:40:02 ivan
+Revision 1.6 1999-01-25 12:26:10 ivan
+yet more mod_perl stuff
+
+Revision 1.5 1999/01/18 21:58:05 ivan
+esthetic: eq and ne were used in a few places instead of == and !=
+
+Revision 1.4 1999/01/18 09:22:42 ivan
+changes to track email addresses for email invoicing
+
+Revision 1.3 1998/12/29 11:59:42 ivan
+mostly properly OO, some work still to be done with svc_ stuff
+
+Revision 1.2 1998/12/16 09:58:53 ivan
+library support for editing email invoice destinations (not in sub collect yet)
+
+Revision 1.1 1998/12/16 07:40:02 ivan
new table
Revision 1.3 1998/11/15 04:33:00 ivan