4 use vars qw(@ISA @EXPORT_OK);
6 use FS::Record qw(fields qsearch qsearchs);
8 @ISA = qw(FS::Record Exporter);
9 @EXPORT_OK = qw(fields);
13 FS::agent - Object methods for agent records
19 $record = create FS::agent \%hash;
20 $record = create FS::agent { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
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:
38 =item agemtnum - primary key (assigned automatically for new agents)
40 =item agent - Text name of this agent
42 =item typenum - Agent type. See L<FS::agent_type>
44 =item prog - For future use.
46 =item freq - For future use.
56 Creates a new agent. To add the agent to the database, see L<"insert">.
61 my($proto,$hashref)=@_;
63 #now in FS::Record::new
65 #foreach $field (fields('agent')) {
66 # $hashref->{$field}='' unless defined $hashref->{$field};
69 $proto->new('agent',$hashref);
74 Adds this agent to the database. If there is an error, returns the error,
75 otherwise returns false.
88 Deletes this agent from the database. Only agents with no customers can be
89 deleted. If there is an error, returns the error, otherwise returns false.
95 return "Can't delete an agent with customers!"
96 if qsearch('cust_main',{'agentnum' => $self->agentnum});
100 =item replace OLD_RECORD
102 Replaces OLD_RECORD with this one in the database. If there is an error,
103 returns the error, otherwise returns false.
109 return "(Old) Not an agent record!" unless $old->table eq "agent";
110 return "Can't change agentnum!"
111 unless $old->getfield('agentnum') eq $new->getfield('agentnum');
118 Checks all fields to make sure this is a valid agent. If there is an error,
119 returns the error, otherwise returns false. Called by the insert and replace
126 return "Not a agent record!" unless $self->table eq "agent";
129 $self->ut_numbern('agentnum')
130 or $self->ut_text('agent')
131 or $self->ut_number('typenum')
132 or $self->ut_numbern('freq')
133 or $self->ut_textn('prog')
135 return $error if $error;
137 return "Unknown typenum!"
138 unless qsearchs('agent_type',{'typenum'=> $self->getfield('typenum') });
148 It doesn't properly override FS::Record yet.
152 L<FS::Record>, L<FS::agent_type>, L<FS::cust_main>, schema.html from the base
157 Class dealing with agent (resellers)
159 ivan@sisd.com 97-nov-13, 97-dec-10
161 pod, added check in ->delete ivan@sisd.com 98-sep-22