Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / agent_pkg_class.pm
1 package FS::agent_pkg_class;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::agent_pkg_class - Object methods for agent_pkg_class records
10
11 =head1 SYNOPSIS
12
13   use FS::agent_pkg_class;
14
15   $record = new FS::agent_pkg_class \%hash;
16   $record = new FS::agent_pkg_class { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::agent_pkg_class object represents an commission for a specific agent
29 and package class.  FS::agent_pkg_class inherits from FS::Record.  The
30 following fields are currently supported:
31
32 =over 4
33
34 =item agentpkgclassnum
35
36 primary key
37
38 =item agentnum
39
40 agentnum
41
42 =item classnum
43
44 classnum
45
46 =item commission_percent
47
48 commission_percent
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new record.  To add the record to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 sub table { 'agent_pkg_class'; }
67
68 =item insert
69
70 Adds this record to the database.  If there is an error, returns the error,
71 otherwise returns false.
72
73 =item delete
74
75 Delete this record from the database.
76
77 =item replace OLD_RECORD
78
79 Replaces the OLD_RECORD with this one in the database.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =item check
83
84 Checks all fields to make sure this is a valid record.  If there is
85 an error, returns the error, otherwise returns false.  Called by the insert
86 and replace methods.
87
88 =cut
89
90 sub check {
91   my $self = shift;
92
93   $self->commission_percent(0) unless length($self->commission_percent);
94
95   my $error = 
96     $self->ut_numbern('agentpkgclassnum')
97     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
98     || $self->ut_foreign_keyn('classnum', 'pkg_class', 'classnum')
99     || $self->ut_float('commission_percent')
100   ;
101   return $error if $error;
102
103   $self->SUPER::check;
104 }
105
106 =back
107
108 =head1 BUGS
109
110 =head1 SEE ALSO
111
112 L<FS::Record>, schema.html from the base documentation.
113
114 =cut
115
116 1;
117