4 use vars qw(@ISA @EXPORT_OK);
6 use FS::Record qw(fields qsearch qsearchs);
10 @ISA = qw(FS::Record Exporter);
11 @EXPORT_OK = qw(fields);
15 FS::agent - Object methods for agent records
21 $record = create FS::agent \%hash;
22 $record = create FS::agent { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::agent object represents an agent. Every customer has an agent. Agents
35 can be used to track things like resellers or salespeople. FS::agent inherits
36 from FS::Record. The following fields are currently supported:
40 =item agemtnum - primary key (assigned automatically for new agents)
42 =item agent - Text name of this agent
44 =item typenum - Agent type. See L<FS::agent_type>
46 =item prog - For future use.
48 =item freq - For future use.
58 Creates a new agent. To add the agent to the database, see L<"insert">.
63 my($proto,$hashref)=@_;
65 #now in FS::Record::new
67 #foreach $field (fields('agent')) {
68 # $hashref->{$field}='' unless defined $hashref->{$field};
71 $proto->new('agent',$hashref);
76 Adds this agent to the database. If there is an error, returns the error,
77 otherwise returns false.
90 Deletes this agent from the database. Only agents with no customers can be
91 deleted. If there is an error, returns the error, otherwise returns false.
97 return "Can't delete an agent with customers!"
98 if qsearch('cust_main',{'agentnum' => $self->agentnum});
102 =item replace OLD_RECORD
104 Replaces OLD_RECORD with this one in the database. If there is an error,
105 returns the error, otherwise returns false.
111 return "(Old) Not an agent record!" unless $old->table eq "agent";
112 return "Can't change agentnum!"
113 unless $old->getfield('agentnum') eq $new->getfield('agentnum');
120 Checks all fields to make sure this is a valid agent. If there is an error,
121 returns the error, otherwise returns false. Called by the insert and replace
128 return "Not a agent record!" unless $self->table eq "agent";
131 $self->ut_numbern('agentnum')
132 or $self->ut_text('agent')
133 or $self->ut_number('typenum')
134 or $self->ut_numbern('freq')
135 or $self->ut_textn('prog')
137 return $error if $error;
139 return "Unknown typenum!"
140 unless qsearchs('agent_type',{'typenum'=> $self->getfield('typenum') });
150 It doesn't properly override FS::Record yet.
154 L<FS::Record>, L<FS::agent_type>, L<FS::cust_main>, schema.html from the base
159 Class dealing with agent (resellers)
161 ivan@sisd.com 97-nov-13, 97-dec-10
163 pod, added check in ->delete ivan@sisd.com 98-sep-22