blob: a46a35b61341d58ae508702c85121e7abe7efc9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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>
|