X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=site_perl%2Fagent.pm;h=cc4fb10883e24b58ef4e0a8f121a8b2510767165;hp=7fc370ed0d6c6d85cc85622796ad3a1e65e8bf8c;hb=7613e14fd13aabb2a44bb26ca8640053f44930ea;hpb=4478d24bd8f66aaff7e2f304d3c2fe2cc1d3bf04 diff --git a/site_perl/agent.pm b/site_perl/agent.pm index 7fc370ed0..cc4fb1088 100644 --- a/site_perl/agent.pm +++ b/site_perl/agent.pm @@ -1,12 +1,12 @@ package FS::agent; use strict; -use vars qw(@ISA @EXPORT_OK); -use Exporter; -use FS::Record qw(fields qsearch qsearchs); +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); +use FS::cust_main; +use FS::agent_type; -@ISA = qw(FS::Record Exporter); -@EXPORT_OK = qw(fields); +@ISA = qw( FS::Record ); =head1 NAME @@ -16,8 +16,8 @@ FS::agent - Object methods for agent records use FS::agent; - $record = create FS::agent \%hash; - $record = create FS::agent { 'column' => 'value' }; + $record = new FS::agent \%hash; + $record = new FS::agent { 'column' => 'value' }; $error = $record->insert; @@ -51,38 +51,19 @@ from FS::Record. The following fields are currently supported: =over 4 -=item create HASHREF +=item new HASHREF Creates a new agent. To add the agent to the database, see L<"insert">. =cut -sub create { - my($proto,$hashref)=@_; - - #now in FS::Record::new - #my($field); - #foreach $field (fields('agent')) { - # $hashref->{$field}='' unless defined $hashref->{$field}; - #} - - $proto->new('agent',$hashref); -} +sub table { 'agent'; } =item insert Adds this agent to the database. If there is an error, returns the error, otherwise returns false. -=cut - -sub insert { - my($self)=@_; - - $self->check or - $self->add; -} - =item delete Deletes this agent from the database. Only agents with no customers can be @@ -91,10 +72,12 @@ deleted. If there is an error, returns the error, otherwise returns false. =cut sub delete { - my($self)=@_; + my $self = shift; + return "Can't delete an agent with customers!" - if qsearch('cust_main',{'agentnum' => $self->agentnum}); - $self->del; + if qsearch( 'cust_main', { 'agentnum' => $self->agentnum } ); + + $self->SUPER::delete; } =item replace OLD_RECORD @@ -102,17 +85,6 @@ sub delete { Replaces OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. -=cut - -sub replace { - my($new,$old)=@_; - return "(Old) Not an agent record!" unless $old->table eq "agent"; - return "Can't change agentnum!" - unless $old->getfield('agentnum') eq $new->getfield('agentnum'); - $new->check or - $new->rep($old); -} - =item check Checks all fields to make sure this is a valid agent. If there is an error, @@ -122,20 +94,19 @@ methods. =cut sub check { - my($self)=@_; - return "Not a agent record!" unless $self->table eq "agent"; + my $self = shift; - my($error)= + my $error = $self->ut_numbern('agentnum') - or $self->ut_text('agent') - or $self->ut_number('typenum') - or $self->ut_numbern('freq') - or $self->ut_textn('prog') + || $self->ut_text('agent') + || $self->ut_number('typenum') + || $self->ut_numbern('freq') + || $self->ut_textn('prog') ; return $error if $error; return "Unknown typenum!" - unless qsearchs('agent_type',{'typenum'=> $self->getfield('typenum') }); + unless qsearchs( 'agent_type', { 'typenum' => $self->typenum } ); ''; @@ -143,9 +114,11 @@ sub check { =back -=head1 BUGS +=head1 VERSION -It doesn't properly override FS::Record yet. +$Id: agent.pm,v 1.4 1998-12-30 00:30:44 ivan Exp $ + +=head1 BUGS =head1 SEE ALSO