X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_tax_exempt_pkg.pm;h=29f631473bc93a1b9eab68ccec32d2507affe241;hb=70d833ddf56f47fa89f429c6a5e84378da848ff9;hp=bbabb5b0a34c6c0ab2649fcb960b0a44614365af;hpb=3185fe4edea62dd3fa9818cf80902e96fe2a2d21;p=freeside.git diff --git a/FS/FS/cust_tax_exempt_pkg.pm b/FS/FS/cust_tax_exempt_pkg.pm index bbabb5b0a..29f631473 100644 --- a/FS/FS/cust_tax_exempt_pkg.pm +++ b/FS/FS/cust_tax_exempt_pkg.pm @@ -6,6 +6,7 @@ use FS::Record qw( qsearch qsearchs ); use FS::cust_main_Mixin; use FS::cust_bill_pkg; use FS::cust_main_county; +use FS::tax_rate; use FS::cust_credit_bill_pkg; use FS::UID qw(dbh); use FS::upgrade_journal; @@ -50,6 +51,9 @@ currently supported: =item billpkgnum - invoice line item (see L) that was exempted from tax. +=item taxtype - the object class of the tax record ('FS::cust_main_county' +or 'FS::tax_rate'). + =item taxnum - tax rate (see L) =item year - the year in which the exemption occurred. NULL if this @@ -138,7 +142,7 @@ sub check { my $error = $self->ut_numbern('exemptnum') || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum') - || $self->ut_foreign_key('taxnum', 'cust_main_county', 'taxnum') + || $self->ut_enum('taxtype', [ 'FS::cust_main_county', 'FS::tax_rate' ]) || $self->ut_foreign_keyn('creditbillpkgnum', 'cust_credit_bill_pkg', 'creditbillpkgnum') @@ -152,6 +156,10 @@ sub check { || $self->SUPER::check ; + $self->get('taxtype') =~ /^FS::(\w+)$/; + my $rate_table = $1; + $error ||= $self->ut_foreign_key('taxnum', $rate_table, 'taxnum'); + return $error if $error; if ( $self->get('exempt_cust') ) { @@ -178,6 +186,8 @@ sub check { =item cust_main_county +=item tax_rate + Returns the associated tax definition if it still exists in the database. Otherwise returns false. @@ -185,7 +195,14 @@ Otherwise returns false. sub cust_main_county { my $self = shift; - qsearchs( 'cust_main_county', { 'taxnum', $self->taxnum } ); + my $class = $self->taxtype; + $class->by_key($self->taxnum); +} + +sub tax_rate { + my $self = shift; + my $class = $self->taxtype; + $class->by_key($self->taxnum); } sub _upgrade_data { @@ -198,6 +215,19 @@ sub _upgrade_data { dbh->do($sql) or die dbh->errstr; FS::upgrade_journal->set_done($journal); } + + $journal = 'cust_tax_exempt_pkg_taxtype'; + if ( !FS::upgrade_journal->is_done($journal) ) { + my $sql = "UPDATE cust_tax_exempt_pkg ". + "SET taxtype = 'FS::cust_main_county' WHERE taxtype IS NULL"; + dbh->do($sql) or die dbh->errstr; + $sql = "UPDATE cust_tax_exempt_pkg_void ". + "SET taxtype = 'FS::cust_main_county' WHERE taxtype IS NULL"; + dbh->do($sql) or die dbh->errstr; + FS::upgrade_journal->set_done($journal); + } + + } =back