mostly properly OO, some work still to be done with svc_ stuff
[freeside.git] / site_perl / agent_type.pm
1 package FS::agent_type;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch );
6
7 @ISA = qw( FS::Record );
8
9 =head1 NAME
10
11 FS::agent_type - Object methods for agent_type records
12
13 =head1 SYNOPSIS
14
15   use FS::agent_type;
16
17   $record = new FS::agent_type \%hash;
18   $record = new FS::agent_type { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::agent_type object represents an agent type.  Every agent (see
31 L<FS::agent>) has an agent type.  Agent types define which packages (see
32 L<FS::part_pkg>) may be purchased by customers (see L<FS::cust_main>), via 
33 FS::type_pkgs records (see L<FS::type_pkgs>).  FS::agent_type inherits from
34 FS::Record.  The following fields are currently supported:
35
36 =over 4
37
38 =item typenum - primary key (assigned automatically for new agent types)
39
40 =item atype - Text name of this agent type
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new agent type.  To add the agent type to the database, see
51 L<"insert">.
52
53 =cut
54
55 sub table { 'agent_type'; }
56
57 =item insert
58
59 Adds this agent type to the database.  If there is an error, returns the error,
60 otherwise returns false.
61
62 =item delete
63
64 Deletes this agent type from the database.  Only agent types with no agents
65 can be deleted.  If there is an error, returns the error, otherwise returns
66 false.
67
68 =cut
69
70 sub delete {
71   my $self = shift;
72
73   return "Can't delete an agent_type with agents!"
74     if qsearch( 'agent', { 'typenum' => $self->typenum } );
75
76   $self->SUPER::delete;
77 }
78
79 =item replace OLD_RECORD
80
81 Replaces OLD_RECORD with this one in the database.  If there is an error,
82 returns the error, otherwise returns false.
83
84 =item check
85
86 Checks all fields to make sure this is a valid agent type.  If there is an
87 error, returns the error, otherwise returns false.  Called by the insert and
88 replace methods.
89
90 =cut
91
92 sub check {
93   my $self = shift;
94
95   $self->ut_numbern('typenum')
96   or $self->ut_text('atype');
97
98 }
99
100 =back
101
102 =head1 VERSION
103
104 $Id: agent_type.pm,v 1.2 1998-12-29 11:59:35 ivan Exp $
105
106 =head1 BUGS
107
108 =head1 SEE ALSO
109
110 L<FS::Record>, L<FS::agent>, L<FS::type_pkgs>, L<FS::cust_main>,
111 L<FS::part_pkg>, schema.html from the base documentation.
112
113 =head1 HISTORY
114
115 Class for the different sets of allowable packages you can assign to an
116 agent.
117
118 ivan@sisd.com 97-nov-13
119
120 ut_ FS::Record methods
121 ivan@sisd.com 97-dec-10
122
123 Changed 'type' to 'atype' because Pg6.3 reserves the type word
124         bmccane@maxbaud.net     98-apr-3
125
126 pod, added check in delete ivan@sisd.com 98-sep-21
127
128 $Log: agent_type.pm,v $
129 Revision 1.2  1998-12-29 11:59:35  ivan
130 mostly properly OO, some work still to be done with svc_ stuff
131
132
133 =cut
134
135 1;
136