1 package FS::cust_bill_pkg;
5 use FS::Record qw( qsearch qsearchs dbdef dbh );
8 use FS::cust_bill_pkg_detail;
10 @ISA = qw( FS::Record );
14 FS::cust_bill_pkg - Object methods for cust_bill_pkg records
18 use FS::cust_bill_pkg;
20 $record = new FS::cust_bill_pkg \%hash;
21 $record = new FS::cust_bill_pkg { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::cust_bill_pkg object represents an invoice line item.
34 FS::cust_bill_pkg inherits from FS::Record. The following fields are currently
39 =item billpkgnum - primary key
41 =item invnum - invoice (see L<FS::cust_bill>)
43 =item pkgnum - package (see L<FS::cust_pkg>) or 0 for the special virtual sales tax package, or -1 for the virtual line item (itemdesc is used for the line)
45 =item setup - setup fee
47 =item recur - recurring fee
49 =item sdate - starting date of recurring fee
51 =item edate - ending date of recurring fee
53 =item itemdesc - Line item description (currentlty used only when pkgnum is 0 or -1)
57 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">. Also
58 see L<Time::Local> and L<Date::Parse> for conversion functions.
66 Creates a new line item. To add the line item to the database, see
67 L<"insert">. Line items are normally created by calling the bill method of a
68 customer object (see L<FS::cust_main>).
72 sub table { 'cust_bill_pkg'; }
76 Adds this line item to the database. If there is an error, returns the error,
77 otherwise returns false.
84 local $SIG{HUP} = 'IGNORE';
85 local $SIG{INT} = 'IGNORE';
86 local $SIG{QUIT} = 'IGNORE';
87 local $SIG{TERM} = 'IGNORE';
88 local $SIG{TSTP} = 'IGNORE';
89 local $SIG{PIPE} = 'IGNORE';
91 my $oldAutoCommit = $FS::UID::AutoCommit;
92 local $FS::UID::AutoCommit = 0;
95 my $error = $self->SUPER::insert;
97 $dbh->rollback if $oldAutoCommit;
101 unless ( defined dbdef->table('cust_bill_pkg_detail') && $self->get('details') ) {
102 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
106 foreach my $detail ( @{$self->get('details')} ) {
107 my $cust_bill_pkg_detail = new FS::cust_bill_pkg_detail {
108 'pkgnum' => $self->pkgnum,
109 'invnum' => $self->invnum,
112 $error = $cust_bill_pkg_detail->insert;
114 $dbh->rollback if $oldAutoCommit;
119 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
126 Currently unimplemented. I don't remove line items because there would then be
127 no record the items ever existed (which is bad, no?)
132 return "Can't delete cust_bill_pkg records!";
135 =item replace OLD_RECORD
137 Currently unimplemented. This would be even more of an accounting nightmare
138 than deleteing the items. Just don't do it.
143 return "Can't modify cust_bill_pkg records!";
148 Checks all fields to make sure this is a valid line item. If there is an
149 error, returns the error, otherwise returns false. Called by the insert
158 $self->ut_numbern('billpkgnum')
159 || $self->ut_snumber('pkgnum')
160 || $self->ut_number('invnum')
161 || $self->ut_money('setup')
162 || $self->ut_money('recur')
163 || $self->ut_numbern('sdate')
164 || $self->ut_numbern('edate')
165 || $self->ut_textn('itemdesc')
167 return $error if $error;
169 #if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
170 if ( $self->pkgnum > 0 ) { #allow -1 for non-pkg line items and 0 for tax (add to part_pkg?)
171 return "Unknown pkgnum ". $self->pkgnum
172 unless qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
175 return "Unknown invnum"
176 unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
183 Returns the package (see L<FS::cust_pkg>) for this invoice line item.
189 qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
194 Returns an array of detail information for the invoice line item.
200 return () unless defined dbdef->table('cust_bill_pkg_detail');
202 qsearch ( 'cust_bill_pkg_detail', { 'pkgnum' => $self->pkgnum,
203 'invnum' => $self->invnum, } );
204 #qsearch ( 'cust_bill_pkg_detail', { 'lineitemnum' => $self->lineitemnum });
209 Returns a description for this line item. For typical line items, this is the
210 I<pkg> field of the corresponding B<FS::part_pkg> object (see L<FS::part_pkg>).
211 For one-shot line items and named taxes, it is the I<itemdesc> field of this
212 line item, and for generic taxes, simply returns "Tax".
219 if ( $self->pkgnum > 0 ) {
220 $self->cust_pkg->part_pkg->pkg;
222 $self->itemdesc || 'Tax';
232 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
233 from the base documentation.