This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / part_pkg_discount.pm
1 package FS::part_pkg_discount;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::discount;
7 use FS::part_pkg;
8
9 =head1 NAME
10
11 FS::part_pkg_discount - Object methods for part_pkg_discount records
12
13 =head1 SYNOPSIS
14
15   use FS::part_pkg_discount;
16
17   $record = new FS::part_pkg_discount \%hash;
18   $record = new FS::part_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::part_pkg_discount object represents a link from a package definition
31 to a discount.  This permits discounts for lengthened terms.  FS::part_pkg_discount inherits from
32 FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item pkgdiscountnum
37
38 primary key
39
40 =item pkgpart
41
42 pkgpart
43
44 =item discountnum
45
46 discountnum
47
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Creates a new part_pkg_discount.  To add the example to the database, see L<"insert">.
58
59 Note that this stores the hash reference, not a distinct copy of the hash it
60 points to.  You can ask the object for a copy with the I<hash> method.
61
62 =cut
63
64 sub table { 'part_pkg_discount'; }
65
66 =item insert
67
68 Adds this record to the database.  If there is an error, returns the error,
69 otherwise returns false.
70
71 =cut
72
73 =item delete
74
75 Delete this record from the database.
76
77 =cut
78
79 =item replace OLD_RECORD
80
81 Replaces the OLD_RECORD with this one in the database.  If there is an error,
82 returns the error, otherwise returns false.
83
84 =cut
85
86 =item check
87
88 Checks all fields to make sure this is a valid example.  If there is
89 an error, returns the error, otherwise returns false.  Called by the insert
90 and replace methods.
91
92 =cut
93
94 sub check {
95   my $self = shift;
96
97   my $error = 
98     $self->ut_numbern('pkgdiscountnum')
99     || $self->ut_number('pkgpart')
100     || $self->ut_number('discountnum')
101   ;
102   return $error if $error;
103
104   $self->SUPER::check;
105 }
106
107 =item discount
108
109 Returns the discount associated with this part_pkg_discount.
110
111 =cut
112
113 sub discount {
114   my $self = shift;
115   qsearch('discount', { 'discountnum' => $self->discountnum });
116 }
117
118 =back
119
120 =head1 BUGS
121
122 =head1 SEE ALSO
123
124 L<FS::Record>, schema.html from the base documentation.
125
126 =cut
127
128 1;
129