summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill_pkg_detail.pm
diff options
context:
space:
mode:
authorjeff <jeff>2008-08-02 04:10:01 +0000
committerjeff <jeff>2008-08-02 04:10:01 +0000
commit6038f6fe5fe3590bcc8063f15ba8ce4cb6a985dc (patch)
tree8aab827e01ca373c0b90b57d970b9e08ec841489 /FS/FS/cust_bill_pkg_detail.pm
parent8cbef37a14f86dfb6313284cdc7b131a3072393f (diff)
improve CDR usage presentation
Diffstat (limited to 'FS/FS/cust_bill_pkg_detail.pm')
-rw-r--r--FS/FS/cust_bill_pkg_detail.pm73
1 files changed, 66 insertions, 7 deletions
diff --git a/FS/FS/cust_bill_pkg_detail.pm b/FS/FS/cust_bill_pkg_detail.pm
index a69998a..8a48888 100644
--- a/FS/FS/cust_bill_pkg_detail.pm
+++ b/FS/FS/cust_bill_pkg_detail.pm
@@ -1,10 +1,13 @@
package FS::cust_bill_pkg_detail;
use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs );
+use vars qw( @ISA $me $DEBUG );
+use FS::Record qw( qsearch qsearchs dbdef );
+use FS::cust_bill_pkg;
@ISA = qw(FS::Record);
+$me = '[ FS::cust_bill_pkg_detail ]';
+$DEBUG = 0;
=head1 NAME
@@ -35,9 +38,7 @@ inherits from FS::Record. The following fields are currently supported:
=item detailnum - primary key
-=item pkgnum -
-
-=item invnum -
+=item billpkgnum - link to cust_bill_pkg
=item detail - detail description
@@ -102,8 +103,7 @@ sub check {
my $self = shift;
$self->ut_numbern('detailnum')
- || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum')
- || $self->ut_foreign_key('invnum', 'cust_bill', 'invnum')
+ || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum')
|| $self->ut_enum('format', [ '', 'C' ] )
|| $self->ut_text('detail')
|| $self->SUPER::check
@@ -111,6 +111,65 @@ sub check {
}
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+
+sub _upgrade_data { # class method
+
+ my ($class, %opts) = @_;
+
+ warn "$me upgrading $class\n" if $DEBUG;
+
+ if ( defined( dbdef->table($class->table)->column('billpkgnum') ) &&
+ defined( dbdef->table($class->table)->column('invnum') ) &&
+ defined( dbdef->table($class->table)->column('pkgnum') )
+ ) {
+
+ warn "$me Checking for unmigrated invoice line item details\n" if $DEBUG;
+
+ my @cbpd = qsearch({ 'table' => $class->table,
+ 'hashref' => {},
+ 'extra_sql' => 'WHERE invnum IS NOT NULL AND '.
+ 'pkgnum IS NOT NULL',
+ });
+
+ if (scalar(@cbpd)) {
+ warn "$me Found unmigrated invoice line item details\n" if $DEBUG;
+
+ foreach my $cbpd ( @cbpd ) {
+ my $detailnum = $cbpd->detailnum;
+ warn "$me Contemplating detail $detailnum\n" if $DEBUG > 1;
+ my $cust_bill_pkg =
+ qsearchs({ 'table' => 'cust_bill_pkg',
+ 'hashref' => { 'invnum' => $cbpd->invnum,
+ 'pkgnum' => $cbpd->pkgnum,
+ },
+ 'order_by' => 'ORDER BY billpkgnum LIMIT 1',
+ });
+ if ($cust_bill_pkg) {
+ $cbpd->billpkgnum($cust_bill_pkg->billpkgnum);
+ $cbpd->invnum('');
+ $cbpd->pkgnum('');
+ my $error = $cbpd->replace;
+
+ warn "*** WARNING: error replacing line item detail ".
+ "(cust_bill_pkg_detail) $detailnum: $error ***\n"
+ if $error;
+ } else {
+ warn "Found orphaned line item detail $detailnum during upgrade.\n";
+ }
+
+ } # foreach $cbpd
+
+ } # if @cbpd
+
+ } # if billpkgnum, invnum, and pkgnum columns defined
+
+ '';
+
+}
+
=back
=head1 BUGS