discounts, RT#6679
[freeside.git] / FS / FS / cust_pkg_discount.pm
1 package FS::cust_pkg_discount;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record; # qw( qsearch qsearchs );
6 use FS::cust_pkg;
7 use FS::discount;
8
9 =head1 NAME
10
11 FS::cust_pkg_discount - Object methods for cust_pkg_discount records
12
13 =head1 SYNOPSIS
14
15   use FS::cust_pkg_discount;
16
17   $record = new FS::cust_pkg_discount \%hash;
18   $record = new FS::cust_pkg_discount { '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::cust_pkg_discount object represents the application of a discount to a
31 customer package.  FS::cust_pkg_discount inherits from FS::Record.  The
32 following fields are currently supported:
33
34 =over 4
35
36 =item pkgdiscountnum
37
38 primary key
39
40 =item pkgnum
41
42 Customer package (see L<FS::cust_pkg>)
43
44 =item discountnum
45
46 Discount (see L<FS::discount>)
47
48 =item months_used
49
50 months_used
51
52 =item end_date
53
54 end_date
55
56 =item otaker
57
58 otaker
59
60
61 =back
62
63 =head1 METHODS
64
65 =over 4
66
67 =item new HASHREF
68
69 Creates a new discount application.  To add the record to the database, see
70  L<"insert">.
71
72 Note that this stores the hash reference, not a distinct copy of the hash it
73 points to.  You can ask the object for a copy with the I<hash> method.
74
75 =cut
76
77 # the new method can be inherited from FS::Record, if a table method is defined
78
79 sub table { 'cust_pkg_discount'; }
80
81 =item insert
82
83 Adds this record to the database.  If there is an error, returns the error,
84 otherwise returns false.
85
86 =cut
87
88 # the insert method can be inherited from FS::Record
89
90 =item delete
91
92 Delete this record from the database.
93
94 =cut
95
96 # the delete method can be inherited from FS::Record
97
98 =item replace OLD_RECORD
99
100 Replaces the OLD_RECORD with this one in the database.  If there is an error,
101 returns the error, otherwise returns false.
102
103 =cut
104
105 # the replace method can be inherited from FS::Record
106
107 =item check
108
109 Checks all fields to make sure this is a valid discount applciation.  If there
110 is an error, returns the error, otherwise returns false.  Called by the insert
111 and replace methods.
112
113 =cut
114
115 # the check method should currently be supplied - FS::Record contains some
116 # data checking routines
117
118 sub check {
119   my $self = shift;
120
121   my $error = 
122     $self->ut_numbern('pkgdiscountnum')
123     || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum')
124     || $self->ut_foreign_key('discountnum', 'discount', 'discountnum' )
125     || $self->ut_float('months_used') #actually decimal, but this will do
126     || $self->ut_numbern('end_date')
127     || $self->ut_text('otaker')
128   ;
129   return $error if $error;
130
131   $self->SUPER::check;
132 }
133
134 =back
135
136 =head1 BUGS
137
138 =head1 SEE ALSO
139
140 L<FS::discount>, L<FS::cust_pkg>, L<FS::Record>, schema.html from the base documentation.
141
142 =cut
143
144 1;
145