X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg_taxclass.pm;h=fda200ee9bea6537742e7ef845c06337ad213a4b;hb=97b377f991f6e9475e8e95c211f67e1186d33062;hp=341be0ebd90677ee46ac993aeb4be90c2b743398;hpb=3a7497433b36b3aa882d30d2d0b6b519a7e1a675;p=freeside.git diff --git a/FS/FS/part_pkg_taxclass.pm b/FS/FS/part_pkg_taxclass.pm index 341be0ebd..fda200ee9 100644 --- a/FS/FS/part_pkg_taxclass.pm +++ b/FS/FS/part_pkg_taxclass.pm @@ -2,6 +2,7 @@ package FS::part_pkg_taxclass; use strict; use vars qw( @ISA ); +use FS::UID qw(dbh); use FS::Record qw( qsearch qsearchs ); @ISA = qw(FS::Record); @@ -100,8 +101,7 @@ sub check { my $self = shift; my $error = - $self->ut_numbern('serial') - || $self->ut_number('taxclassnum') + $self->ut_numbern('taxclassnum') || $self->ut_text('taxclass') ; return $error if $error; @@ -111,6 +111,38 @@ sub check { =back +=cut + +# _upgrade_data +# +# Used by FS::Upgrade to migrate to a new database. + +sub _upgrade_data { # class method + my ($class, %opts) = @_; + + my $sth = dbh->prepare(' + SELECT DISTINCT taxclass + FROM cust_main_county + LEFT JOIN part_pkg_taxclass USING ( taxclass ) + WHERE taxclassnum IS NULL + AND taxclass IS NOT NULL + ') or die dbh->errstr; + $sth->execute or die $sth->errstr; + my %taxclass = map { $_->[0] => 1 } @{$sth->fetchall_arrayref}; + my @taxclass = grep $_, keys %taxclass; + + foreach my $taxclass ( @taxclass ) { + + my $part_pkg_taxclass = new FS::part_pkg_taxclass ( { + 'taxclass' => $taxclass, + } ); + my $error = $part_pkg_taxclass->insert; + die $error if $error; + + } + +} + =head1 BUGS Other tables (cust_main_county, part_pkg, agent_payment_gateway) have a text