diff options
| author | ivan <ivan> | 2008-02-20 01:21:17 +0000 | 
|---|---|---|
| committer | ivan <ivan> | 2008-02-20 01:21:17 +0000 | 
| commit | 9f2de9917c8ff7fecd1d17ac7567472b5ac75df0 (patch) | |
| tree | 3c896e6091676eb46ab14c8408ea08483a08f918 /FS | |
| parent | 7e5ae6bd612f2eff6065b4aea0a52edc696e5d36 (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 d256a6148..11e63ea71 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -860,6 +860,16 @@ sub tables_hashref {        'index' => [ [ 'promo_code' ], [ 'disabled' ] ],      }, +    '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 | 
