1 package FS::cust_bill_pkg_detail;
4 use vars qw( @ISA $me $DEBUG );
5 use FS::Record qw( qsearch qsearchs dbdef );
9 $me = '[ FS::cust_bill_pkg_detail ]';
14 FS::cust_bill_pkg_detail - Object methods for cust_bill_pkg_detail records
18 use FS::cust_bill_pkg_detail;
20 $record = new FS::cust_bill_pkg_detail \%hash;
21 $record = new FS::cust_bill_pkg_detail { '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_detail object represents additional detail information for
34 an invoice line item (see L<FS::cust_bill_pkg>). FS::cust_bill_pkg_detail
35 inherits from FS::Record. The following fields are currently supported:
39 =item detailnum - primary key
41 =item billpkgnum - link to cust_bill_pkg
43 =item detail - detail description
53 Creates a new line item detail. To add the line item detail to the database,
56 Note that this stores the hash reference, not a distinct copy of the hash it
57 points to. You can ask the object for a copy with the I<hash> method.
61 # the new method can be inherited from FS::Record, if a table method is defined
63 sub table { 'cust_bill_pkg_detail'; }
67 Adds this record to the database. If there is an error, returns the error,
68 otherwise returns false.
72 # the insert method can be inherited from FS::Record
76 Delete this record from the database.
80 # the delete method can be inherited from FS::Record
82 =item replace OLD_RECORD
84 Replaces the OLD_RECORD with this one in the database. If there is an error,
85 returns the error, otherwise returns false.
89 # the replace method can be inherited from FS::Record
93 Checks all fields to make sure this is a valid line item detail. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
99 # the check method should currently be supplied - FS::Record contains some
100 # data checking routines
105 $self->ut_numbern('detailnum')
106 || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
107 || $self->ut_enum('format', [ '', 'C' ] )
108 || $self->ut_text('detail')
109 || $self->SUPER::check
116 # Used by FS::Upgrade to migrate to a new database.
118 sub _upgrade_data { # class method
120 my ($class, %opts) = @_;
122 warn "$me upgrading $class\n" if $DEBUG;
124 if ( defined( dbdef->table($class->table)->column('billpkgnum') ) &&
125 defined( dbdef->table($class->table)->column('invnum') ) &&
126 defined( dbdef->table($class->table)->column('pkgnum') )
129 warn "$me Checking for unmigrated invoice line item details\n" if $DEBUG;
131 my @cbpd = qsearch({ 'table' => $class->table,
133 'extra_sql' => 'WHERE invnum IS NOT NULL AND '.
134 'pkgnum IS NOT NULL',
138 warn "$me Found unmigrated invoice line item details\n" if $DEBUG;
140 foreach my $cbpd ( @cbpd ) {
141 my $detailnum = $cbpd->detailnum;
142 warn "$me Contemplating detail $detailnum\n" if $DEBUG > 1;
144 qsearchs({ 'table' => 'cust_bill_pkg',
145 'hashref' => { 'invnum' => $cbpd->invnum,
146 'pkgnum' => $cbpd->pkgnum,
148 'order_by' => 'ORDER BY billpkgnum LIMIT 1',
150 if ($cust_bill_pkg) {
151 $cbpd->billpkgnum($cust_bill_pkg->billpkgnum);
154 my $error = $cbpd->replace;
156 warn "*** WARNING: error replacing line item detail ".
157 "(cust_bill_pkg_detail) $detailnum: $error ***\n"
160 warn "Found orphaned line item detail $detailnum during upgrade.\n";
167 } # if billpkgnum, invnum, and pkgnum columns defined
179 L<FS::cust_bill_pkg>, L<FS::Record>, schema.html from the base documentation.