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