1 package FS::cust_bill_pkg;
5 use FS::Record qw( qsearch qsearchs dbdef dbh );
6 use FS::cust_main_Mixin;
9 use FS::cust_bill_pkg_detail;
11 @ISA = qw( FS::cust_main_Mixin FS::Record );
15 FS::cust_bill_pkg - Object methods for cust_bill_pkg records
19 use FS::cust_bill_pkg;
21 $record = new FS::cust_bill_pkg \%hash;
22 $record = new FS::cust_bill_pkg { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::cust_bill_pkg object represents an invoice line item.
35 FS::cust_bill_pkg inherits from FS::Record. The following fields are currently
40 =item billpkgnum - primary key
42 =item invnum - invoice (see L<FS::cust_bill>)
44 =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)
46 =item setup - setup fee
48 =item recur - recurring fee
50 =item sdate - starting date of recurring fee
52 =item edate - ending date of recurring fee
54 =item itemdesc - Line item description (currentlty used only when pkgnum is 0 or -1)
58 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">. Also
59 see L<Time::Local> and L<Date::Parse> for conversion functions.
67 Creates a new line item. To add the line item to the database, see
68 L<"insert">. Line items are normally created by calling the bill method of a
69 customer object (see L<FS::cust_main>).
73 sub table { 'cust_bill_pkg'; }
77 Adds this line item to the database. If there is an error, returns the error,
78 otherwise returns false.
85 local $SIG{HUP} = 'IGNORE';
86 local $SIG{INT} = 'IGNORE';
87 local $SIG{QUIT} = 'IGNORE';
88 local $SIG{TERM} = 'IGNORE';
89 local $SIG{TSTP} = 'IGNORE';
90 local $SIG{PIPE} = 'IGNORE';
92 my $oldAutoCommit = $FS::UID::AutoCommit;
93 local $FS::UID::AutoCommit = 0;
96 my $error = $self->SUPER::insert;
98 $dbh->rollback if $oldAutoCommit;
102 unless ( defined dbdef->table('cust_bill_pkg_detail') && $self->get('details') ) {
103 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
107 foreach my $detail ( @{$self->get('details')} ) {
108 my $cust_bill_pkg_detail = new FS::cust_bill_pkg_detail {
109 'pkgnum' => $self->pkgnum,
110 'invnum' => $self->invnum,
113 $error = $cust_bill_pkg_detail->insert;
115 $dbh->rollback if $oldAutoCommit;
120 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
127 Currently unimplemented. I don't remove line items because there would then be
128 no record the items ever existed (which is bad, no?)
133 return "Can't delete cust_bill_pkg records!";
136 =item replace OLD_RECORD
138 Currently unimplemented. This would be even more of an accounting nightmare
139 than deleteing the items. Just don't do it.
144 return "Can't modify cust_bill_pkg records!";
149 Checks all fields to make sure this is a valid line item. If there is an
150 error, returns the error, otherwise returns false. Called by the insert
159 $self->ut_numbern('billpkgnum')
160 || $self->ut_snumber('pkgnum')
161 || $self->ut_number('invnum')
162 || $self->ut_money('setup')
163 || $self->ut_money('recur')
164 || $self->ut_numbern('sdate')
165 || $self->ut_numbern('edate')
166 || $self->ut_textn('itemdesc')
168 return $error if $error;
170 #if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
171 if ( $self->pkgnum > 0 ) { #allow -1 for non-pkg line items and 0 for tax (add to part_pkg?)
172 return "Unknown pkgnum ". $self->pkgnum
173 unless qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
176 return "Unknown invnum"
177 unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
184 Returns the package (see L<FS::cust_pkg>) for this invoice line item.
190 qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
195 Returns an array of detail information for the invoice line item.
201 return () unless defined dbdef->table('cust_bill_pkg_detail');
203 qsearch ( 'cust_bill_pkg_detail', { 'pkgnum' => $self->pkgnum,
204 'invnum' => $self->invnum, } );
205 #qsearch ( 'cust_bill_pkg_detail', { 'lineitemnum' => $self->lineitemnum });
210 Returns a description for this line item. For typical line items, this is the
211 I<pkg> field of the corresponding B<FS::part_pkg> object (see L<FS::part_pkg>).
212 For one-shot line items and named taxes, it is the I<itemdesc> field of this
213 line item, and for generic taxes, simply returns "Tax".
220 if ( $self->pkgnum > 0 ) {
221 $self->cust_pkg->part_pkg->pkg;
223 $self->itemdesc || 'Tax';
241 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
242 from the base documentation.