summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/tax_rate.pm94
-rwxr-xr-xhttemplate/browse/tax_rate.cgi62
-rwxr-xr-xhttemplate/misc/enable_or_disable_tax.html74
-rwxr-xr-xhttemplate/misc/process/enable_or_disable_tax.html70
5 files changed, 118 insertions, 183 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
diff --git a/httemplate/browse/tax_rate.cgi b/httemplate/browse/tax_rate.cgi
index 71cfb28ac..cb997fada 100755
--- a/httemplate/browse/tax_rate.cgi
+++ b/httemplate/browse/tax_rate.cgi
@@ -1,24 +1,21 @@
<% include( 'elements/browse.html',
- 'title' => "Tax Rates $title",
- 'name_singular' => 'tax rate',
- 'menubar' => \@menubar,
- 'html_init' => $html_init,
- 'html_form' => $html_form,
- 'query' => {
- 'table' => 'tax_rate',
- 'hashref' => $hashref,
- 'order_by' => 'ORDER BY geocode, taxclassnum',
- 'extra_sql' => $extra_sql,
- },
- 'count_query' => $count_query,
- 'header' => \@header,
- 'header2' => \@header2,
- 'fields' => \@fields,
- 'align' => $align,
- 'color' => \@color,
- 'cell_style' => \@cell_style,
- 'links' => \@links,
- 'link_onclicks' => \@link_onclicks,
+ 'title' => "Tax Rates $title",
+ 'name_singular' => 'tax rate',
+ 'menubar' => \@menubar,
+ 'html_init' => $html_init,
+ 'html_form' => $html_form,
+ 'disableable' => 1,
+ 'disabled_statuspos' => 5,
+ 'query' => $query,
+ 'count_query' => $count_query,
+ 'header' => \@header,
+ 'header2' => \@header2,
+ 'fields' => \@fields,
+ 'align' => $align,
+ 'color' => \@color,
+ 'cell_style' => \@cell_style,
+ 'links' => \@links,
+ 'link_onclicks' => \@link_onclicks,
)
%>
<%once>
@@ -156,7 +153,6 @@ my $tax_type = $1
my $tax_cat = $1
if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
-my @taxclassnum = ();
if ($tax_type || $tax_cat ) {
my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
$compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
@@ -166,7 +162,6 @@ if ($tax_type || $tax_cat ) {
'extra_sql' => "WHERE taxclass $compare",
});
if (@tax_class) {
- @taxclassnum = map { $_->taxclassnum } @tax_class;
$tax_class[0]->description =~ /^(.*):(.*)/;
$title .= " for";
$title .= " $tax_type ($1) tax type" if $tax_type;
@@ -208,28 +203,7 @@ my $html_form = include('/elements/init_overlib.html'). '<BR><BR>'.
qw(disable enable)
);
-my $hashref = {};
-my $extra_sql = '';
-if ( $data_vendor ) {
- $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
-}
-
-if ( $geocode ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' geocode LIKE '. dbh->quote($geocode.'%');
-}
-
-if ( $taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' taxclassnum = '. dbh->quote($taxclassnum);
-}
-
-if ( @taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- join(' OR ', map { " taxclassnum = $_ " } @taxclassnum );
-}
-
-my $count_query = "SELECT COUNT(*) FROM tax_rate $extra_sql";
+my ($query, $count_query) = FS::tax_rate::browse_queries(scalar($cgi->Vars));
$cell_style = '';
diff --git a/httemplate/misc/enable_or_disable_tax.html b/httemplate/misc/enable_or_disable_tax.html
index 0d4c05105..0efd07d19 100755
--- a/httemplate/misc/enable_or_disable_tax.html
+++ b/httemplate/misc/enable_or_disable_tax.html
@@ -3,11 +3,12 @@
<FORM ACTION="<% popurl(1) %>process/enable_or_disable_tax.html" METHOD=POST>
<INPUT TYPE="hidden" NAME="action" VALUE="<% $action %>">
-<INPUT TYPE="hidden" NAME="data_vendor" VALUE="<% $data_vendor %>">
-<INPUT TYPE="hidden" NAME="geocode" VALUE="<% $geocode %>">
-<INPUT TYPE="hidden" NAME="taxclassnum" VALUE="<% $taxclassnum %>">
-<INPUT TYPE="hidden" NAME="tax_type" VALUE="<% $tax_type %>">
-<INPUT TYPE="hidden" NAME="tax_cat" VALUE="<% $tax_cat %>">
+<INPUT TYPE="hidden" NAME="data_vendor" VALUE="<% $cgi->param('data_vendor') %>">
+<INPUT TYPE="hidden" NAME="geocode" VALUE="<% $cgi->param('geocode') %>">
+<INPUT TYPE="hidden" NAME="taxclassnum" VALUE="<% $cgi->param('taxclassnum') %>">
+<INPUT TYPE="hidden" NAME="tax_type" VALUE="<% $cgi->param('tax_type') %>">
+<INPUT TYPE="hidden" NAME="tax_cat" VALUE="<% $cgi->param('tax_cat') %>">
+<INPUT TYPE="hidden" NAME="showdisabled" VALUE="<% $cgi->param('showdisabled') |h %>">
This will <B><% $action %></B> <% $count %> tax
<% $count == 1 ? 'rate' : 'rates' %>. Are you <B>certain</B> you want to do
@@ -25,68 +26,7 @@ if ( $cgi->param('action') =~ /^(\w+)$/ ) {
$action = $1;
}
-my $data_vendor = '';
-if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
- $data_vendor = $1;
-}
-
-my $geocode = '';
-if ( $cgi->param('geocode') =~ /^(\w+)$/ ) {
- $geocode = $1;
-}
-
-my $taxclassnum = '';
-if ( $cgi->param('taxclassnum') =~ /^(\d+)$/ ) {
- $taxclassnum = $1;
- my $tax_class = qsearchs('tax_class', {'taxclassnum' => $taxclassnum});
- $taxclassnum = ''
- unless ($tax_class);
-}
-
-my $tax_type = $1
- if ( $cgi->param('tax_type') =~ /^(\d+)$/ );
-my $tax_cat = $1
- if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
-
-my @taxclassnum = ();
-if ($tax_type || $tax_cat ) {
- my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
- $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
- my @tax_class =
- qsearch({ 'table' => 'tax_class',
- 'hashref' => {},
- 'extra_sql' => "WHERE taxclass $compare",
- });
- if (@tax_class) {
- @taxclassnum = map { $_->taxclassnum } @tax_class;
- $tax_class[0]->description =~ /^(.*):(.*)/;
- }else{
- $tax_type = '';
- $tax_cat = '';
- }
-}
-
-my $extra_sql = '';
-if ( $data_vendor ) {
- $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
-}
-
-if ( $geocode ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' geocode LIKE '. dbh->quote($geocode.'%');
-}
-
-if ( $taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' taxclassnum = '. dbh->quote($taxclassnum);
-}
-
-if ( @taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- join(' OR ', map { " taxclassnum = $_ " } @taxclassnum );
-}
-
-my $count_query = "SELECT COUNT(*) FROM tax_rate $extra_sql";
+my ($query, $count_query) = FS::tax_rate::browse_queries(scalar($cgi->Vars));
my $count_sth = dbh->prepare($count_query)
or die "Error preparing $count_query: ". dbh->errstr;
diff --git a/httemplate/misc/process/enable_or_disable_tax.html b/httemplate/misc/process/enable_or_disable_tax.html
index a46a35b61..9b7324b0d 100755
--- a/httemplate/misc/process/enable_or_disable_tax.html
+++ b/httemplate/misc/process/enable_or_disable_tax.html
@@ -20,79 +20,15 @@ if ( $cgi->param('action') =~ /^(\w+)$/ ) {
$action = $1;
}
-my $data_vendor = '';
-if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
- $data_vendor = $1;
-}
-
-my $geocode = '';
-if ( $cgi->param('geocode') =~ /^(\w+)$/ ) {
- $geocode = $1;
-}
-
-my $taxclassnum = '';
-if ( $cgi->param('taxclassnum') =~ /^(\d+)$/ ) {
- $taxclassnum = $1;
- my $tax_class = qsearchs('tax_class', {'taxclassnum' => $taxclassnum});
- $taxclassnum = ''
- unless ($tax_class);
-}
-
-my $tax_type = $1
- if ( $cgi->param('tax_type') =~ /^(\d+)$/ );
-my $tax_cat = $1
- if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
-
-my @taxclassnum = ();
-if ($tax_type || $tax_cat ) {
- my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
- $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
- my @tax_class =
- qsearch({ 'table' => 'tax_class',
- 'hashref' => {},
- 'extra_sql' => "WHERE taxclass $compare",
- });
- if (@tax_class) {
- @taxclassnum = map { $_->taxclassnum } @tax_class;
- $tax_class[0]->description =~ /^(.*):(.*)/;
- }else{
- $tax_type = '';
- $tax_cat = '';
- }
-}
-
-my $extra_sql = '';
-if ( $data_vendor ) {
- $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
-}
-
-if ( $geocode ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' geocode LIKE '. dbh->quote($geocode.'%');
-}
-
-if ( $taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- ' taxclassnum = '. dbh->quote($taxclassnum);
-}
-
-if ( @taxclassnum ) {
- $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
- join(' OR ', map { " taxclassnum = $_ " } @taxclassnum );
-}
-
-my @tax_rate = qsearch({ 'table' => 'tax_rate',
- 'hashref' => {},
- 'extra_sql' => $extra_sql,
- });
+my ($query, $count_query) = FS::tax_rate::browse_queries(scalar($cgi->Vars));
+my @tax_rate = qsearch( $query );
#transaction?
my $error;
$error = "Invalid action" unless ($action =~ /enable|disable/);
foreach my $tax_rate (@tax_rate) {
- $action eq 'enable' ? $tax_rate->setuptax('') : $tax_rate->setuptax('Y');
- $action eq 'enable' ? $tax_rate->recurtax('') : $tax_rate->recurtax('Y');
+ $action eq 'enable' ? $tax_rate->disabled('') : $tax_rate->disabled('Y');
# $tax_rate->manual('Y');
$error ||= $tax_rate->replace;
last if $error;