diff options
author | jeff <jeff> | 2008-06-18 18:50:46 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-06-18 18:50:46 +0000 |
commit | 8e026f7a5e492cdc9d1d2792453b27f60fc31e03 (patch) | |
tree | 61f84295d67f0a9240279c712b3b9a6290b493bb | |
parent | 63f34c9c207f3925ce18658b72f4634fecaf9867 (diff) |
allow enabling and disabling if tax_rate rows in groups (RT 3566)
-rwxr-xr-x | httemplate/browse/tax_rate.cgi | 17 | ||||
-rwxr-xr-x | httemplate/misc/enable_or_disable_tax.html | 97 | ||||
-rwxr-xr-x | httemplate/misc/process/enable_or_disable_tax.html | 105 |
3 files changed, 218 insertions, 1 deletions
diff --git a/httemplate/browse/tax_rate.cgi b/httemplate/browse/tax_rate.cgi index 5d43d5939..71cfb28ac 100755 --- a/httemplate/browse/tax_rate.cgi +++ b/httemplate/browse/tax_rate.cgi @@ -3,6 +3,7 @@ 'name_singular' => 'tax rate', 'menubar' => \@menubar, 'html_init' => $html_init, + 'html_form' => $html_form, 'query' => { 'table' => 'tax_rate', 'hashref' => $hashref, @@ -179,7 +180,6 @@ if ($tax_type || $tax_cat ) { $cgi->delete('tax_type'); $cgi->delete('tax_cat'); - if ( $geocode || $taxclassnum ) { push @menubar, 'View all tax rates' => $p.'browse/tax_rate.cgi'; } @@ -193,6 +193,21 @@ $cgi->param('taxclassnum', $taxclassnum ) if $taxclassnum; $cgi->param('tax_type', $tax_type ) if $tax_type; $cgi->param('tax_cat', $tax_cat ) if $tax_cat; +my $html_form = include('/elements/init_overlib.html'). '<BR><BR>'. + join(' ', + map { + include('/elements/popup_link.html', + { + 'action' => $p. "misc/enable_or_disable_tax.html?action=$_&". + $cgi->query_string, + 'label' => ucfirst($_). ' all these taxes', + 'actionlabel' => ucfirst($_). ' taxes', + }, + ); + } + qw(disable enable) + ); + my $hashref = {}; my $extra_sql = ''; if ( $data_vendor ) { diff --git a/httemplate/misc/enable_or_disable_tax.html b/httemplate/misc/enable_or_disable_tax.html new file mode 100755 index 000000000..0d4c05105 --- /dev/null +++ b/httemplate/misc/enable_or_disable_tax.html @@ -0,0 +1,97 @@ +<% include('/elements/header-popup.html', ucfirst($action). ' Tax Rates') %> +<% include('/elements/error.html') %> + +<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 %>"> + +This will <B><% $action %></B> <% $count %> tax +<% $count == 1 ? 'rate' : 'rates' %>. Are you <B>certain</B> you want to do +this? +<BR><BR><INPUT TYPE="submit" VALUE="Yes"> +</FORM> + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $action = ''; +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 $count_sth = dbh->prepare($count_query) + or die "Error preparing $count_query: ". dbh->errstr; +$count_sth->execute + or die "Error executing $count_query: ". $count_sth->errstr; +my $count = $count_sth->fetchrow_arrayref->[0]; + +</%init> diff --git a/httemplate/misc/process/enable_or_disable_tax.html b/httemplate/misc/process/enable_or_disable_tax.html new file mode 100755 index 000000000..a46a35b61 --- /dev/null +++ b/httemplate/misc/process/enable_or_disable_tax.html @@ -0,0 +1,105 @@ +%if ($error) { +<% $cgi->redirect(popurl(2).'enable_or_disable_tax.html?'.$cgi->query_string) %> +%}else{ + <% include('/elements/header-popup.html', $title) %> + + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + + </BODY> + </HTML> +%} +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $action = ''; +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, + }); + +#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'); + # $tax_rate->manual('Y'); + $error ||= $tax_rate->replace; + last if $error; +} +$cgi->param('error', $error) if $error; + +my $title = scalar(@tax_rate) == 1 ? 'Tax rate ' : 'Tax rates '; +$title .= lc($action). 'd'; + +</%init> |