summaryrefslogtreecommitdiff
path: root/httemplate/misc/process
diff options
context:
space:
mode:
authorjeff <jeff>2008-06-18 18:50:46 +0000
committerjeff <jeff>2008-06-18 18:50:46 +0000
commit8e026f7a5e492cdc9d1d2792453b27f60fc31e03 (patch)
tree61f84295d67f0a9240279c712b3b9a6290b493bb /httemplate/misc/process
parent63f34c9c207f3925ce18658b72f4634fecaf9867 (diff)
allow enabling and disabling if tax_rate rows in groups (RT 3566)
Diffstat (limited to 'httemplate/misc/process')
-rwxr-xr-xhttemplate/misc/process/enable_or_disable_tax.html105
1 files changed, 105 insertions, 0 deletions
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 0000000..a46a35b
--- /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>