allow enabling and disabling if tax_rate rows in groups (RT 3566)
[freeside.git] / httemplate / misc / enable_or_disable_tax.html
1 <% include('/elements/header-popup.html', ucfirst($action). ' Tax Rates') %>
2 <% include('/elements/error.html') %>
3
4 <FORM ACTION="<% popurl(1) %>process/enable_or_disable_tax.html" METHOD=POST>
5 <INPUT TYPE="hidden" NAME="action" VALUE="<% $action %>">
6 <INPUT TYPE="hidden" NAME="data_vendor" VALUE="<% $data_vendor %>">
7 <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $geocode %>">
8 <INPUT TYPE="hidden" NAME="taxclassnum" VALUE="<% $taxclassnum %>">
9 <INPUT TYPE="hidden" NAME="tax_type" VALUE="<% $tax_type %>">
10 <INPUT TYPE="hidden" NAME="tax_cat" VALUE="<% $tax_cat %>">
11
12 This will <B><% $action %></B> <% $count %> tax
13 <% $count == 1 ? 'rate' : 'rates' %>.  Are you <B>certain</B> you want to do
14 this?
15 <BR><BR><INPUT TYPE="submit" VALUE="Yes">
16 </FORM>
17
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
22
23 my $action = '';
24 if ( $cgi->param('action') =~ /^(\w+)$/ ) {
25   $action = $1;
26 }
27
28 my $data_vendor = '';
29 if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
30   $data_vendor = $1;
31 }
32
33 my $geocode = '';
34 if ( $cgi->param('geocode') =~ /^(\w+)$/ ) {
35   $geocode = $1;
36 }
37
38 my $taxclassnum = '';
39 if ( $cgi->param('taxclassnum') =~ /^(\d+)$/ ) {
40   $taxclassnum = $1;
41   my $tax_class = qsearchs('tax_class', {'taxclassnum' => $taxclassnum});
42   $taxclassnum = ''
43     unless ($tax_class);
44 }
45
46 my $tax_type = $1
47   if ( $cgi->param('tax_type') =~ /^(\d+)$/ );
48 my $tax_cat = $1
49   if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
50
51 my @taxclassnum = ();
52 if ($tax_type || $tax_cat ) {
53   my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
54   $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
55   my @tax_class =
56     qsearch({ 'table'     => 'tax_class',
57               'hashref'   => {},
58               'extra_sql' => "WHERE taxclass $compare",
59            });
60   if (@tax_class) {
61     @taxclassnum = map { $_->taxclassnum } @tax_class;
62     $tax_class[0]->description =~ /^(.*):(.*)/;
63   }else{
64     $tax_type = '';
65     $tax_cat = '';
66   }
67 }
68
69 my $extra_sql = '';
70 if ( $data_vendor ) {
71   $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
72 }
73
74 if ( $geocode ) {
75   $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
76                 ' geocode LIKE '. dbh->quote($geocode.'%');
77 }
78
79 if ( $taxclassnum ) {
80   $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
81                 ' taxclassnum  = '. dbh->quote($taxclassnum);
82 }
83
84 if ( @taxclassnum ) {
85   $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
86                 join(' OR ', map { " taxclassnum  = $_ " } @taxclassnum );
87 }
88
89 my $count_query = "SELECT COUNT(*) FROM tax_rate $extra_sql";
90
91 my $count_sth = dbh->prepare($count_query)
92   or die "Error preparing $count_query: ". dbh->errstr;
93 $count_sth->execute
94   or die "Error executing $count_query: ". $count_sth->errstr;
95 my $count = $count_sth->fetchrow_arrayref->[0];
96
97 </%init>