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