1 package FS::cust_bill_pkg_detail;
4 use vars qw( @ISA $me $DEBUG %GetInfoType );
5 use FS::Record qw( qsearch qsearchs dbdef dbh );
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 my $columndef = dbdef->table($class->table)->column('classnum');
125 unless ($columndef->type eq 'int4') {
128 if ( $dbh->{Driver}->{Name} eq 'Pg' ) {
130 eval "use DBI::Const::GetInfoType;";
133 my $major_version = 0;
134 $dbh->get_info( $GetInfoType{SQL_DBMS_VER} ) =~ /^(\d{2})/
135 && ( $major_version = sprintf("%d", $1) );
137 if ( $major_version > 7 ) {
139 # ideally this would be supported in DBIx-DBSchema and friends
141 foreach my $table ( qw( cust_bill_pkg_detail h_cust_bill_pkg_detail ) ){
143 warn "updating $table column classnum to integer\n" if $DEBUG;
144 my $sql = "ALTER TABLE $table ALTER classnum TYPE int USING ".
146 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
147 $sth->execute or die $sth->errstr;
153 die "cust_bill_pkg_detail classnum upgrade unsupported for this Pg version\n";
159 die "cust_bill_pkg_detail classnum upgrade only supported for Pg 8+\n";
166 if ( defined( dbdef->table($class->table)->column('billpkgnum') ) &&
167 defined( dbdef->table($class->table)->column('invnum') ) &&
168 defined( dbdef->table($class->table)->column('pkgnum') )
171 warn "$me Checking for unmigrated invoice line item details\n" if $DEBUG;
173 my @cbpd = qsearch({ 'table' => $class->table,
175 'extra_sql' => 'WHERE invnum IS NOT NULL AND '.
176 'pkgnum IS NOT NULL',
180 warn "$me Found unmigrated invoice line item details\n" if $DEBUG;
182 foreach my $cbpd ( @cbpd ) {
183 my $detailnum = $cbpd->detailnum;
184 warn "$me Contemplating detail $detailnum\n" if $DEBUG > 1;
186 qsearchs({ 'table' => 'cust_bill_pkg',
187 'hashref' => { 'invnum' => $cbpd->invnum,
188 'pkgnum' => $cbpd->pkgnum,
190 'order_by' => 'ORDER BY billpkgnum LIMIT 1',
192 if ($cust_bill_pkg) {
193 $cbpd->billpkgnum($cust_bill_pkg->billpkgnum);
196 my $error = $cbpd->replace;
198 warn "*** WARNING: error replacing line item detail ".
199 "(cust_bill_pkg_detail) $detailnum: $error ***\n"
202 warn "Found orphaned line item detail $detailnum during upgrade.\n";
209 } # if billpkgnum, invnum, and pkgnum columns defined
221 L<FS::cust_bill_pkg>, L<FS::Record>, schema.html from the base documentation.