Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 an instruction to display a 
31 line item in a specific invoice section.  FS::cust_bill_pkg_display inherits
32 from FS::Record and is many-to-one with FS::cust_bill_pkg (invoice line 
33 items).
34
35 The following fields are currently supported:
36
37 =over 4
38
39 =item billpkgdisplaynum - primary key
40
41 =item billpkgnum - the line item number (L<FS::cust_bill_pkg> foreign key)
42
43 =item section - the section name where this item should be shown.  Defaults
44 to the package category name, if there is one.
45
46 =cut
47
48 # actually it defaults to null, but then calling ->section will return the 
49 # category name.
50 sub section {
51   my ( $self, $value ) = @_;
52   if ( defined($value) ) {
53     $self->setfield('section', $value);
54   } else {
55     my $section = $self->getfield('section');
56     unless ($section) {
57       my $cust_bill_pkg = $self->cust_bill_pkg;
58       if ( $cust_bill_pkg->pkgnum > 0 && !$cust_bill_pkg->hidden ) {
59         my $part_pkg = $cust_bill_pkg->part_pkg;
60         $section = $part_pkg->categoryname if $part_pkg;
61       }
62     }
63     $section;
64   }
65 }
66
67 =item post_total - 'Y' to have this item shown in a "late" section (below
68 the invoice totals).
69
70 =item type - Which portion of the item's charges to show in the specified
71 position.  'S' to show setup fees (including tax and one-time charge),
72 'R' to show the non-usage recurring charge, 'U' to show the usage charge,
73 null to show all three as a single amount.
74
75 =item summary - 'Y' to show a usage summary of this line item.  This has
76 the following effects if type = 'U':
77 - The description will always be "Usage charges" rather than the package name.
78 - Service labels and usage details (CDRs) are hidden.
79 - It will only display on multisection invoices.
80
81 =back
82
83 =head1 METHODS
84
85 =over 4
86
87 =item new HASHREF
88
89 Creates a new line item display object.  To add the record to the database, 
90 see L<"insert">.
91
92 Note that this stores the hash reference, not a distinct copy of the hash it
93 points to.  You can ask the object for a copy with the I<hash> method.
94
95 =cut
96
97 sub table { 'cust_bill_pkg_display'; }
98
99 =item insert
100
101 Adds this record to the database.  If there is an error, returns the error,
102 otherwise returns false.
103
104 =cut
105
106 =item delete
107
108 Delete this record from the database.
109
110 =cut
111
112 =item replace OLD_RECORD
113
114 Replaces the OLD_RECORD with this one in the database.  If there is an error,
115 returns the error, otherwise returns false.
116
117 =cut
118
119 =item check
120
121 Checks all fields to make sure this is a valid line item display object.
122 If there is an error, returns the error, otherwise returns false.  Called by
123 the insert and replace methods.
124
125 =cut
126
127 sub check {
128   my $self = shift;
129
130   my $error = 
131     $self->ut_numbern('billpkgdisplaynum')
132     || $self->ut_number('billpkgnum')
133     || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
134     || $self->ut_textn('section')
135     || $self->ut_enum('post_total', [ '', 'Y' ])
136     || $self->ut_enum('type', [ '', 'S', 'R', 'U' ])
137     || $self->ut_enum('summary', [ '', 'Y' ])
138   ;
139   return $error if $error;
140
141   $self->SUPER::check;
142 }
143
144 =item cust_bill_pkg
145
146 Returns the associated cust_bill_pkg (see L<FS::cust_bill_pkg>) for this
147 line item display object.
148
149 =cut
150
151 sub cust_bill_pkg {
152   my $self = shift;
153   qsearchs( 'cust_bill_pkg', { 'billpkgnum' => $self->billpkgnum } ) ;
154 }
155
156 =back
157
158 =head1 BUGS
159
160
161 =head1 SEE ALSO
162
163 L<FS::Record>, L<FS::cust_bill_pkg>, schema.html from the base documentation.
164
165 =cut
166
167 1;
168