From: jeff Date: Wed, 18 Jun 2008 18:50:46 +0000 (+0000) Subject: allow enabling and disabling if tax_rate rows in groups (RT 3566) X-Git-Tag: root_of_webpay_support~554 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=8e026f7a5e492cdc9d1d2792453b27f60fc31e03 allow enabling and disabling if tax_rate rows in groups (RT 3566) --- 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'). '

'. + 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') %> + +
+ + + + + + + +This will <% $action %> <% $count %> tax +<% $count == 1 ? 'rate' : 'rates' %>. Are you certain you want to do +this? +

+
+ +<%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]; + + 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) %> + + + + + +%} +<%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'; + +