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