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 invnum - invoice (see L<FS::cust_bill>)
41 =item pkgnum - package (see L<FS::cust_pkg>) or 0 for the special virtual sales tax package
43 =item setup - setup fee
45 =item recur - recurring fee
47 =item sdate - starting date of recurring fee
49 =item edate - ending date of recurring fee
51 =item itemdesc - Line item description (currentlty used only when pkgnum is 0)
55 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">. Also
56 see L<Time::Local> and L<Date::Parse> for conversion functions.
64 Creates a new line item. To add the line item to the database, see
65 L<"insert">. Line items are normally created by calling the bill method of a
66 customer object (see L<FS::cust_main>).
70 sub table { 'cust_bill_pkg'; }
74 Adds this line item to the database. If there is an error, returns the error,
75 otherwise returns false.
82 local $SIG{HUP} = 'IGNORE';
83 local $SIG{INT} = 'IGNORE';
84 local $SIG{QUIT} = 'IGNORE';
85 local $SIG{TERM} = 'IGNORE';
86 local $SIG{TSTP} = 'IGNORE';
87 local $SIG{PIPE} = 'IGNORE';
89 my $oldAutoCommit = $FS::UID::AutoCommit;
90 local $FS::UID::AutoCommit = 0;
93 my $error = $self->SUPER::insert;
95 $dbh->rollback if $oldAutoCommit;
99 unless ( defined dbdef->table('cust_bill_pkg_detail') && $self->get('details') ) {
100 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
104 foreach my $detail ( @{$self->get('details')} ) {
105 my $cust_bill_pkg_detail = new FS::cust_bill_pkg_detail {
106 'pkgnum' => $self->pkgnum,
107 'invnum' => $self->invnum,
110 $error = $cust_bill_pkg_detail->insert;
112 $dbh->rollback if $oldAutoCommit;
117 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
124 Currently unimplemented. I don't remove line items because there would then be
125 no record the items ever existed (which is bad, no?)
130 return "Can't delete cust_bill_pkg records!";
133 =item replace OLD_RECORD
135 Currently unimplemented. This would be even more of an accounting nightmare
136 than deleteing the items. Just don't do it.
141 return "Can't modify cust_bill_pkg records!";
146 Checks all fields to make sure this is a valid line item. If there is an
147 error, returns the error, otherwise returns false. Called by the insert
156 $self->ut_number('pkgnum')
157 || $self->ut_number('invnum')
158 || $self->ut_money('setup')
159 || $self->ut_money('recur')
160 || $self->ut_numbern('sdate')
161 || $self->ut_numbern('edate')
162 || $self->ut_textn('itemdesc')
164 return $error if $error;
166 if ( $self->pkgnum != 0 ) { #allow unchecked pkgnum 0 for tax! (add to part_pkg?)
167 return "Unknown pkgnum ". $self->pkgnum
168 unless qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
171 return "Unknown invnum"
172 unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
179 Returns the package (see L<FS::cust_pkg>) for this invoice line item.
185 qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
190 Returns an array of detail information for the invoice line item.
196 return () unless defined dbdef->table('cust_bill_pkg_detail');
198 qsearch ( 'cust_bill_pkg_detail', { 'pkgnum' => $self->pkgnum,
199 'invnum' => $self->invnum, } );
200 #qsearch ( 'cust_bill_pkg_detail', { 'lineitemnum' => $self->lineitemnum });
209 L<FS::Record>, L<FS::cust_bill>, L<FS::cust_pkg>, L<FS::cust_main>, schema.html
210 from the base documentation.