5 use FS::Record qw( qsearch qsearchs );
9 @ISA = qw( FS::Record );
13 FS::agent - Object methods for agent records
19 $record = new FS::agent \%hash;
20 $record = new FS::agent { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
30 $agent_type = $record->agent_type;
32 $hashref = $record->pkgpart_hashref;
33 #may purchase $pkgpart if $hashref->{$pkgpart};
37 An FS::agent object represents an agent. Every customer has an agent. Agents
38 can be used to track things like resellers or salespeople. FS::agent inherits
39 from FS::Record. The following fields are currently supported:
43 =item agemtnum - primary key (assigned automatically for new agents)
45 =item agent - Text name of this agent
47 =item typenum - Agent type. See L<FS::agent_type>
49 =item prog - For future use.
51 =item freq - For future use.
61 Creates a new agent. To add the agent to the database, see L<"insert">.
65 sub table { 'agent'; }
69 Adds this agent to the database. If there is an error, returns the error,
70 otherwise returns false.
74 Deletes this agent from the database. Only agents with no customers can be
75 deleted. If there is an error, returns the error, otherwise returns false.
82 return "Can't delete an agent with customers!"
83 if qsearch( 'cust_main', { 'agentnum' => $self->agentnum } );
88 =item replace OLD_RECORD
90 Replaces OLD_RECORD with this one in the database. If there is an error,
91 returns the error, otherwise returns false.
95 Checks all fields to make sure this is a valid agent. If there is an error,
96 returns the error, otherwise returns false. Called by the insert and replace
105 $self->ut_numbern('agentnum')
106 || $self->ut_text('agent')
107 || $self->ut_number('typenum')
108 || $self->ut_numbern('freq')
109 || $self->ut_textn('prog')
111 return $error if $error;
113 return "Unknown typenum!"
114 unless $self->agent_type;
122 Returns the FS::agent_type object (see L<FS::agent_type>) for this agent.
128 qsearchs( 'agent_type', { 'typenum' => $self->typenum } );
131 =item pkgpart_hashref
133 Returns a hash reference. The keys of the hash are pkgparts. The value is
134 true if this agent may purchase the specified package definition. See
139 sub pkgpart_hashref {
141 $self->agent_type->pkgpart_hashref;
148 $Id: agent.pm,v 1.2 2000-12-03 13:45:15 ivan Exp $
154 L<FS::Record>, L<FS::agent_type>, L<FS::cust_main>, L<FS::part_pkg>,
155 schema.html from the base documentation.