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