autoload methods returning foreign records, RT#13971
[freeside.git] / FS / FS / cust_bill_pkg_discount.pm
1 package FS::cust_bill_pkg_discount;
2 use base qw( FS::cust_main_Mixin FS::Record );
3
4 use strict;
5
6 =head1 NAME
7
8 FS::cust_bill_pkg_discount - Object methods for cust_bill_pkg_discount records
9
10 =head1 SYNOPSIS
11
12   use FS::cust_bill_pkg_discount;
13
14   $record = new FS::cust_bill_pkg_discount \%hash;
15   $record = new FS::cust_bill_pkg_discount { '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::cust_bill_pkg_discount object represents the slice of a customer
28 discount applied to a specific line item.  FS::cust_bill_pkg_discount inherits
29 from FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item billpkgdiscountnum
34
35 primary key
36
37 =item billpkgnum
38
39 Line item (see L<FS::cust_bill_pkg>)
40
41 =item pkgdiscountnum
42
43 Customer discount (see L<FS::cust_pkg_discount>)
44
45 =item amount
46
47 Amount discounted from the line itme.
48
49 =item months
50
51 Number of months of discount this represents.
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 # the new method can be inherited from FS::Record, if a table method is defined
69
70 sub table { 'cust_bill_pkg_discount'; }
71
72 =item insert
73
74 Adds this record to the database.  If there is an error, returns the error,
75 otherwise returns false.
76
77 =cut
78
79 # the insert method can be inherited from FS::Record
80
81 =item delete
82
83 Delete this record from the database.
84
85 =cut
86
87 # the delete method can be inherited from FS::Record
88
89 =item replace OLD_RECORD
90
91 Replaces the OLD_RECORD with this one in the database.  If there is an error,
92 returns the error, otherwise returns false.
93
94 =cut
95
96 # the replace method can be inherited from FS::Record
97
98 =item check
99
100 Checks all fields to make sure this is a valid record.  If there is
101 an error, returns the error, otherwise returns false.  Called by the insert
102 and replace methods.
103
104 =cut
105
106 sub check {
107   my $self = shift;
108
109   my $error = 
110     $self->ut_numbern('billpkgdiscountnum')
111     || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum' )
112     || $self->ut_foreign_key('pkgdiscountnum', 'cust_pkg_discount', 'pkgdiscountnum' )
113     || $self->ut_money('amount')
114     || $self->ut_float('months')
115   ;
116   return $error if $error;
117
118   $self->SUPER::check;
119 }
120
121 =item cust_bill_pkg
122
123 Returns the associated line item (see L<FS::cust_bill_pkg>).
124
125 =item cust_pkg_discount
126
127 Returns the associated customer discount (see L<FS::cust_pkg_discount>).
128
129 =back
130
131 =head1 BUGS
132
133 =head1 SEE ALSO
134
135 L<FS::Record>, schema.html from the base documentation.
136
137 =cut
138
139 1;
140