cleaned up the new one-screen signup bits in htdocs/edit/cust_main.cgi to
[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 use FS::agent;
7 use FS::type_pkgs;
8
9 @ISA = qw( FS::Record );
10
11 =head1 NAME
12
13 FS::agent_type - Object methods for agent_type records
14
15 =head1 SYNOPSIS
16
17   use FS::agent_type;
18
19   $record = new FS::agent_type \%hash;
20   $record = new FS::agent_type { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30   $hashref = $record->pkgpart_hashref;
31   #may purchase $pkgpart if $hashref->{$pkgpart};
32
33   @type_pkgs = $record->type_pkgs;
34
35   @pkgparts = $record->pkgpart;
36
37 =head1 DESCRIPTION
38
39 An FS::agent_type object represents an agent type.  Every agent (see
40 L<FS::agent>) has an agent type.  Agent types define which packages (see
41 L<FS::part_pkg>) may be purchased by customers (see L<FS::cust_main>), via 
42 FS::type_pkgs records (see L<FS::type_pkgs>).  FS::agent_type inherits from
43 FS::Record.  The following fields are currently supported:
44
45 =over 4
46
47 =item typenum - primary key (assigned automatically for new agent types)
48
49 =item atype - Text name of this agent type
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new agent type.  To add the agent type to the database, see
60 L<"insert">.
61
62 =cut
63
64 sub table { 'agent_type'; }
65
66 =item insert
67
68 Adds this agent type to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =item delete
72
73 Deletes this agent type from the database.  Only agent types with no agents
74 can be deleted.  If there is an error, returns the error, otherwise returns
75 false.
76
77 =cut
78
79 sub delete {
80   my $self = shift;
81
82   return "Can't delete an agent_type with agents!"
83     if qsearch( 'agent', { 'typenum' => $self->typenum } );
84
85   $self->SUPER::delete;
86 }
87
88 =item replace OLD_RECORD
89
90 Replaces OLD_RECORD with this one in the database.  If there is an error,
91 returns the error, otherwise returns false.
92
93 =item check
94
95 Checks all fields to make sure this is a valid agent type.  If there is an
96 error, returns the error, otherwise returns false.  Called by the insert and
97 replace methods.
98
99 =cut
100
101 sub check {
102   my $self = shift;
103
104   $self->ut_numbern('typenum')
105   or $self->ut_text('atype');
106
107 }
108
109 =item pkgpart_hashref
110
111 Returns a hash reference.  The keys of the hash are pkgparts.  The value is
112 true iff this agent may purchase the specified package definition.  See
113 L<FS::part_pkg>.
114
115 =cut
116
117 sub pkgpart_hashref {
118   my $self = shift;
119   my %pkgpart;
120   $pkgpart{$_}++ foreach $self->pkgpart;
121   \%pkgpart;
122 }
123
124 =item type_pkgs
125
126 Returns all FS::type_pkgs objects (see L<FS::type_pkgs>) for this agent type.
127
128 =cut
129
130 sub type_pkgs {
131   my $self = shift;
132   qsearch('type_pkgs', { 'typenum' => $self->typenum } );
133 }
134
135 =item pkgpart
136
137 Returns the pkgpart of all package definitions (see L<FS::part_pkg>) for this
138 agent type.
139
140 =cut
141
142 sub pkgpart {
143   my $self = shift;
144   map $_->pkgpart, $self->type_pkgs;
145 }
146
147 =back
148
149 =head1 VERSION
150
151 $Id: agent_type.pm,v 1.3 1999-07-20 10:37:05 ivan Exp $
152
153 =head1 BUGS
154
155 =head1 SEE ALSO
156
157 L<FS::Record>, L<FS::agent>, L<FS::type_pkgs>, L<FS::cust_main>,
158 L<FS::part_pkg>, schema.html from the base documentation.
159
160 =head1 HISTORY
161
162 Class for the different sets of allowable packages you can assign to an
163 agent.
164
165 ivan@sisd.com 97-nov-13
166
167 ut_ FS::Record methods
168 ivan@sisd.com 97-dec-10
169
170 Changed 'type' to 'atype' because Pg6.3 reserves the type word
171         bmccane@maxbaud.net     98-apr-3
172
173 pod, added check in delete ivan@sisd.com 98-sep-21
174
175 $Log: agent_type.pm,v $
176 Revision 1.3  1999-07-20 10:37:05  ivan
177 cleaned up the new one-screen signup bits in htdocs/edit/cust_main.cgi to
178 prepare for a signup server
179
180 Revision 1.2  1998/12/29 11:59:35  ivan
181 mostly properly OO, some work still to be done with svc_ stuff
182
183
184 =cut
185
186 1;
187