*** empty log message ***
[freeside.git] / site_perl / agent.pm
1 package FS::agent;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cust_main;
7 use FS::agent_type;
8
9 @ISA = qw( FS::Record );
10
11 =head1 NAME
12
13 FS::agent - Object methods for agent records
14
15 =head1 SYNOPSIS
16
17   use FS::agent;
18
19   $record = new FS::agent \%hash;
20   $record = new FS::agent { '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 =head1 DESCRIPTION
31
32 An FS::agent object represents an agent.  Every customer has an agent.  Agents
33 can be used to track things like resellers or salespeople.  FS::agent inherits
34 from FS::Record.  The following fields are currently supported:
35
36 =over 4
37
38 =item agemtnum - primary key (assigned automatically for new agents)
39
40 =item agent - Text name of this agent
41
42 =item typenum - Agent type.  See L<FS::agent_type>
43
44 =item prog - For future use.
45
46 =item freq - For future use.
47
48 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item new HASHREF
55
56 Creates a new agent.  To add the agent to the database, see L<"insert">.
57
58 =cut
59
60 sub table { 'agent'; }
61
62 =item insert
63
64 Adds this agent to the database.  If there is an error, returns the error,
65 otherwise returns false.
66
67 =item delete
68
69 Deletes this agent from the database.  Only agents with no customers can be
70 deleted.  If there is an error, returns the error, otherwise returns false.
71
72 =cut
73
74 sub delete {
75   my $self = shift;
76
77   return "Can't delete an agent with customers!"
78     if qsearch( 'cust_main', { 'agentnum' => $self->agentnum } );
79
80   $self->SUPER::delete;
81 }
82
83 =item replace OLD_RECORD
84
85 Replaces OLD_RECORD with this one in the database.  If there is an error,
86 returns the error, otherwise returns false.
87
88 =item check
89
90 Checks all fields to make sure this is a valid agent.  If there is an error,
91 returns the error, otherwise returns false.  Called by the insert and replace
92 methods.
93
94 =cut
95
96 sub check {
97   my $self = shift;
98
99   my $error =
100     $self->ut_numbern('agentnum')
101       || $self->ut_text('agent')
102       || $self->ut_number('typenum')
103       || $self->ut_numbern('freq')
104       || $self->ut_textn('prog')
105   ;
106   return $error if $error;
107
108   return "Unknown typenum!"
109     unless qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
110
111   '';
112
113 }
114
115 =back
116
117 =head1 VERSION
118
119 $Id: agent.pm,v 1.4 1998-12-30 00:30:44 ivan Exp $
120
121 =head1 BUGS
122
123 =head1 SEE ALSO
124
125 L<FS::Record>, L<FS::agent_type>, L<FS::cust_main>, schema.html from the base
126 documentation.
127
128 =head1 HISTORY
129
130 Class dealing with agent (resellers)
131
132 ivan@sisd.com 97-nov-13, 97-dec-10
133
134 pod, added check in ->delete ivan@sisd.com 98-sep-22
135
136 =cut
137
138 1;
139