X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=site_perl%2Fcust_main_invoice.pm;h=2823294c18f648b82b92f04d494bab37c7184ee3;hb=ba645a8c36119b3a0448b1ae1eeaecbaef13b244;hp=90d653a4ae8bc6f352221a4bc5dccf6e1b89203e;hpb=819a983adc011bdc6eb2f3aaabd4ef1da1d4a8d8;p=freeside.git diff --git a/site_perl/cust_main_invoice.pm b/site_perl/cust_main_invoice.pm index 90d653a4a..2823294c1 100644 --- a/site_perl/cust_main_invoice.pm +++ b/site_perl/cust_main_invoice.pm @@ -3,10 +3,12 @@ package FS::cust_main_invoice; use strict; 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 ); #ask FS::UID to run this stuff for us later $FS::UID::callback{'FS::cust_main_invoice'} = sub { @@ -22,8 +24,8 @@ FS::cust_main_invoice - Object methods for cust_main_invoice records 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; @@ -54,7 +56,7 @@ FS::Record. The following fields are currently supported: =over 4 -=item create HASHREF +=item new HASHREF Creates a new invoice destination. To add the invoice destination to the database, see L<"insert">. @@ -63,45 +65,17 @@ points to. You can ask the object for a copy with the I method. =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, @@ -110,16 +84,11 @@ returns the error, otherwise returns false. =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; } @@ -132,27 +101,41 @@ and repalce methods. =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); @@ -173,7 +156,7 @@ Returns the literal email address for this record (or `POST'). sub address { my $self = shift; if ( $self->dest =~ /(\d+)$/ ) { - my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $1 } ); + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } ); $svc_acct->username . '@' . $mydomain; } else { $self->dest; @@ -184,7 +167,7 @@ sub address { =head1 VERSION -$Id: cust_main_invoice.pm,v 1.2 1998-12-16 09:58:53 ivan Exp $ +$Id: cust_main_invoice.pm,v 1.6 1999-01-25 12:26:10 ivan Exp $ =head1 BUGS @@ -200,7 +183,19 @@ added hfields ivan@sisd.com 97-nov-13 $Log: cust_main_invoice.pm,v $ -Revision 1.2 1998-12-16 09:58:53 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