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