diff options
author | ivan <ivan> | 2008-02-20 01:21:15 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-02-20 01:21:15 +0000 |
commit | 1d920e3661c29398763d05c82bbe3a493a19fbae (patch) | |
tree | 31d979a1ccd6559eace6d7f07675ba3176054c86 /FS | |
parent | 70838ab866bfcb2d596ed2ca96bb2c23c6cba5c1 (diff) |
update the tax class editor to enable taxclass adding, RT#2929
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 10 | ||||
-rw-r--r-- | FS/FS/Upgrade.pm | 12 | ||||
-rw-r--r-- | FS/FS/part_pkg_taxclass.pm | 36 |
3 files changed, 54 insertions, 4 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 7f8e6dace..9548aa760 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -943,6 +943,16 @@ sub tables_hashref { 'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ], }, + 'part_pkg_taxclass' => { + 'columns' => [ + 'taxclassnum', 'serial', '', '', '', '', + 'taxclass', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'taxclassnum', + 'unique' => [ [ 'taxclass' ] ], + 'index' => [], + }, + # 'part_title' => { # 'columns' => [ # 'titlenum', 'int', '', '', diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 90e66d87d..cb4823012 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -49,8 +49,12 @@ sub upgrade { eval "use $class;"; die $@ if $@; - $class->_upgrade_data(%opt) - if $class->can('_upgrade_data'); + if ( $class->can('_upgrade_data') ) { + $class->_upgrade_data(%opt); + } else { + warn "WARNING: asked for upgrade of $table,". + " but FS::$table has no _upgrade_data method\n"; + } # my @records = @{ $data->{$table} }; # @@ -88,6 +92,10 @@ sub upgrade_data { #populate cust_pay.otaker 'cust_pay' => [], + + #populate part_pkg_taxclass for starters + 'part_pkg_taxclass' => [], + ; \%hash; 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 |