X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=site_perl%2Fagent_type.pm;h=6ea3d2a70f652c5f987a7c8f6b168ff1aa1c9bb6;hb=19c3d2717fb417187fb0f020a7ba2b065f3f8e30;hp=002c36f54a2f44cf4010d9257a3f8ff53e8ccf89;hpb=762e8ec0ead5dc8c8978d93695adbcc1265ca83a;p=freeside.git diff --git a/site_perl/agent_type.pm b/site_perl/agent_type.pm index 002c36f54..6ea3d2a70 100644 --- a/site_perl/agent_type.pm +++ b/site_perl/agent_type.pm @@ -1,12 +1,12 @@ package FS::agent_type; use strict; -use vars qw(@ISA @EXPORT_OK); -use Exporter; -use FS::Record qw(qsearch fields); +use vars qw( @ISA ); +use FS::Record qw( qsearch ); +use FS::agent; +use FS::type_pkgs; -@ISA = qw(FS::Record Exporter); -@EXPORT_OK = qw(fields); +@ISA = qw( FS::Record ); =head1 NAME @@ -16,8 +16,8 @@ FS::agent_type - Object methods for agent_type records use FS::agent_type; - $record = create FS::agent_type \%hash; - $record = create FS::agent_type { 'column' => 'value' }; + $record = new FS::agent_type \%hash; + $record = new FS::agent_type { 'column' => 'value' }; $error = $record->insert; @@ -27,6 +27,13 @@ FS::agent_type - Object methods for agent_type records $error = $record->check; + $hashref = $record->pkgpart_hashref; + #may purchase $pkgpart if $hashref->{$pkgpart}; + + @type_pkgs = $record->type_pkgs; + + @pkgparts = $record->pkgpart; + =head1 DESCRIPTION An FS::agent_type object represents an agent type. Every agent (see @@ -47,40 +54,20 @@ FS::Record. The following fields are currently supported: =over 4 -=item create HASHREF +=item new HASHREF Creates a new agent type. To add the agent type to the database, see L<"insert">. =cut -sub create { - my($proto,$hashref)=@_; - - #now in FS::Record::new - #my($field); - #foreach $field (fields('agent_type')) { - # $hashref->{$field}='' unless defined $hashref->{$field}; - #} - - $proto->new('agent_type',$hashref); - -} +sub table { 'agent_type'; } =item insert Adds this agent type 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 type from the database. Only agent types with no agents @@ -90,10 +77,12 @@ false. =cut sub delete { - my($self)=@_; + my $self = shift; + return "Can't delete an agent_type with agents!" - if qsearch('agent',{'typenum' => $self->typenum}); - $self->del; + if qsearch( 'agent', { 'typenum' => $self->typenum } ); + + $self->SUPER::delete; } =item replace OLD_RECORD @@ -101,17 +90,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 a agent_type record!" unless $old->table eq "agent_type"; - return "Can't change typenum!" - unless $old->getfield('typenum') eq $new->getfield('typenum'); - $new->check or - $new->rep($old); -} - =item check Checks all fields to make sure this is a valid agent type. If there is an @@ -121,19 +99,58 @@ replace methods. =cut sub check { - my($self)=@_; - return "Not a agent_type record!" unless $self->table eq "agent_type"; + my $self = shift; $self->ut_numbern('typenum') or $self->ut_text('atype'); } +=item pkgpart_hashref + +Returns a hash reference. The keys of the hash are pkgparts. The value is +true iff this agent may purchase the specified package definition. See +L. + +=cut + +sub pkgpart_hashref { + my $self = shift; + my %pkgpart; + $pkgpart{$_}++ foreach $self->pkgpart; + \%pkgpart; +} + +=item type_pkgs + +Returns all FS::type_pkgs objects (see L) for this agent type. + +=cut + +sub type_pkgs { + my $self = shift; + qsearch('type_pkgs', { 'typenum' => $self->typenum } ); +} + +=item pkgpart + +Returns the pkgpart of all package definitions (see L) for this +agent type. + +=cut + +sub pkgpart { + my $self = shift; + map $_->pkgpart, $self->type_pkgs; +} + =back -=head1 BUGS +=head1 VERSION -It doesn't properly override FS::Record yet. +$Id: agent_type.pm,v 1.3 1999-07-20 10:37:05 ivan Exp $ + +=head1 BUGS =head1 SEE ALSO @@ -155,6 +172,15 @@ Changed 'type' to 'atype' because Pg6.3 reserves the type word pod, added check in delete ivan@sisd.com 98-sep-21 +$Log: agent_type.pm,v $ +Revision 1.3 1999-07-20 10:37:05 ivan +cleaned up the new one-screen signup bits in htdocs/edit/cust_main.cgi to +prepare for a signup server + +Revision 1.2 1998/12/29 11:59:35 ivan +mostly properly OO, some work still to be done with svc_ stuff + + =cut 1;