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