X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=de535aadc3695e54a28f902e1264ffaa1430b9e4;hb=22a1feb55c4bb705064a04646ff5c321b8112ce1;hp=788b1d3630d66543e67cae45130008fa55eb0d4a;hpb=b31455ec31222bd0e882b76895baa794d80acb17;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 788b1d363..de535aadc 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -10,7 +10,7 @@ use List::Util qw(max); use Tie::IxHash; use Time::Local qw( timelocal timelocal_nocheck ); use MIME::Entity; -use FS::UID qw( getotaker dbh ); +use FS::UID qw( getotaker dbh driver_name ); use FS::Misc qw( send_email ); use FS::Record qw( qsearch qsearchs fields ); use FS::CurrentUser; @@ -2616,6 +2616,39 @@ Returns the label of the location object (see L). #end of subs in location_Mixin.pm now... unfortunately the POD doesn't mixin +=item tax_locationnum + +Returns the foreign key to a L object for calculating +tax on this package, as determined by the C and +C configuration flags. + +=cut + +sub tax_locationnum { + my $self = shift; + my $conf = FS::Conf->new; + if ( $conf->exists('tax-pkg_address') ) { + return $self->locationnum; + } + elsif ( $conf->exists('tax-ship_address') ) { + return $self->cust_main->ship_locationnum; + } + else { + return $self->cust_main->bill_locationnum; + } +} + +=item tax_location + +Returns the L object for tax_locationnum. + +=cut + +sub tax_location { + my $self = shift; + FS::cust_location->by_key( $self->tax_locationnum ) +} + =item seconds_since TIMESTAMP Returns the number of seconds all accounts (see L) in this @@ -3602,6 +3635,25 @@ sub fcc_477_count { } +=item tax_locationnum_sql + +Returns an SQL expression for the tax location for a package, based +on the settings of 'tax-pkg_address' and 'tax-ship_address'. + +=cut + +sub tax_locationnum_sql { + my $conf = FS::Conf->new; + if ( $conf->exists('tax-pkg_address') ) { + 'cust_pkg.locationnum'; + } + elsif ( $conf->exists('tax-ship_address') ) { + 'cust_main.ship_locationnum'; + } + else { + 'cust_main.bill_locationnum'; + } +} =item location_sql @@ -3689,10 +3741,12 @@ sub _location_sql_where { my $or_empty_county = " OR ( ? = '' AND $table.${prefix}county IS NULL )"; my $or_empty_state = " OR ( ? = '' AND $table.${prefix}state IS NULL )"; + my $text = (driver_name =~ /^mysql/i) ? 'char' : 'text'; + # ( $table.${prefix}city = ? $or_empty_city $ornull ) " - ( $table.district = ? OR ? = '' OR CAST(? AS text) IS NULL ) - AND ( $table.${prefix}city = ? OR ? = '' OR CAST(? AS text) IS NULL ) + ( $table.district = ? OR ? = '' OR CAST(? AS $text) IS NULL ) + AND ( $table.${prefix}city = ? OR ? = '' OR CAST(? AS $text) IS NULL ) AND ( $table.${prefix}county = ? $or_empty_county $ornull ) AND ( $table.${prefix}state = ? $or_empty_state $ornull ) AND $table.${prefix}country = ?