diff options
author | jeff <jeff> | 2008-07-23 14:36:16 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-07-23 14:36:16 +0000 |
commit | 7ab646de8cf19249ba3e41591e60ec05025e4ef4 (patch) | |
tree | 7ecf72c0bdac757f12e137c284df4c9d528bd276 /FS | |
parent | 5307e2b96c57b03e5f7068af3c5483be4915b041 (diff) |
add disabled column to new tax rates, false laziness elimination, and bug fixes - closes #3566
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/tax_rate.pm | 94 |
2 files changed, 90 insertions, 5 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 90d9d5d7b..cc97a4635 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -707,6 +707,7 @@ sub tables_hashref { 'setuptax', 'char', 'NULL', 1, '', '', # Y = setup tax exempt 'recurtax', 'char', 'NULL', 1, '', '', # Y = recur tax exempt 'manual', 'char', 'NULL', 1, '', '', # Y = manually edited + 'disabled', 'char', 'NULL', 1, '', '', # Y = tax disabled ], 'primary_key' => 'taxnum', 'unique' => [], diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index 81b63abd7..69dc12821 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -219,6 +219,7 @@ sub check { || $self->ut_enum('setuptax', [ '', 'Y' ] ) || $self->ut_enum('recurtax', [ '', 'Y' ] ) || $self->ut_enum('manual', [ '', 'Y' ] ) + || $self->ut_enum('disabled', [ '', 'Y' ] ) || $self->SUPER::check ; @@ -349,6 +350,14 @@ of packages/amounts. If an error occurs, a message is returned as a scalar. sub taxline { my $self = shift; + my $name = $self->taxname; + $name = 'Other surcharges' + if ($self->passtype == 2); + my $amount = 0; + + return [$name, $amount] # we always know how to handle disabled taxes + if $self->disabled; + my $taxable_charged = 0; my @cust_bill_pkg = grep { $taxable_charged += $_ unless ref; ref; } @_; @@ -378,11 +387,6 @@ sub taxline { '" basis'; } - my $name = $self->taxname; - $name = 'Other surcharges' - if ($self->passtype == 2); - my $amount = 0; - unless ($self->setuptax =~ /^Y$/i) { $taxable_charged += $_->setup foreach @cust_bill_pkg; } @@ -862,6 +866,86 @@ sub process_batch { } +=item browse_queries PARAMS + +Returns a list consisting of a hashref suited for use as the argument +to qsearch, and sql query string. Each is based on the PARAMS hashref +of keys and values which frequently would be passed as C<scalar($cgi->Vars)> +from a form. This conveniently creates the query hashref and count_query +string required by the browse and search elements. As a side effect, +the PARAMS hashref is untainted and keys with unexpected values are removed. + +=cut + +sub browse_queries { + my $params = shift; + + my $query = { + 'table' => 'tax_rate', + 'hashref' => {}, + 'order_by' => 'ORDER BY geocode, taxclassnum', + }, + + my $extra_sql = ''; + + if ( $params->{data_vendor} =~ /^(\w+)$/ ) { + $extra_sql .= ' WHERE data_vendor = '. dbh->quote($1); + } else { + delete $params->{data_vendor}; + } + + if ( $params->{geocode} =~ /^(\w+)$/ ) { + $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ). + 'geocode LIKE '. dbh->quote($1.'%'); + } else { + delete $params->{geocode}; + } + + if ( $params->{taxclassnum} =~ /^(\d+)$/ && + qsearchs( 'tax_class', {'taxclassnum' => $1} ) + ) + { + $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ). + ' taxclassnum = '. dbh->quote($1) + } else { + delete $params->{taxclassnun}; + } + + my $tax_type = $1 + if ( $params->{tax_type} =~ /^(\d+)$/ ); + delete $params->{tax_type} + unless $tax_type; + + my $tax_cat = $1 + if ( $params->{tax_cat} =~ /^(\d+)$/ ); + delete $params->{tax_cat} + unless $tax_cat; + + my @taxclassnum = (); + if ($tax_type || $tax_cat ) { + my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'"; + $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat); + @taxclassnum = map { $_->taxclassnum } + qsearch({ 'table' => 'tax_class', + 'hashref' => {}, + 'extra_sql' => "WHERE taxclass $compare", + }); + } + + $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ). '( '. + join(' OR ', map { " taxclassnum = $_ " } @taxclassnum ). ' )' + if ( @taxclassnum ); + + unless ($params->{'showdisabled'}) { + $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ). + "( disabled = '' OR disabled IS NULL )"; + } + + $query->{extra_sql} = $extra_sql; + + return ($query, "SELECT COUNT(*) FROM tax_rate $extra_sql"); +} + =back =head1 BUGS |