From a1e23a4ffe9bc5da68f5eb9a40eeed8cd9583afc Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 12 Oct 2008 00:54:19 +0000 Subject: add a quick bulk tax add tool (eating my own dogfood instead of running a one-off SQL query), RT#4117 --- httemplate/edit/process/bulk-cust_main_county.html | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 httemplate/edit/process/bulk-cust_main_county.html (limited to 'httemplate/edit/process') diff --git a/httemplate/edit/process/bulk-cust_main_county.html b/httemplate/edit/process/bulk-cust_main_county.html new file mode 100644 index 000000000..e05192e96 --- /dev/null +++ b/httemplate/edit/process/bulk-cust_main_county.html @@ -0,0 +1,63 @@ +% if ( $error ) { #better to redirect back to +%# <% $cgi->redirect("$url?". $cgi->query_string ) %> + <% include('/elements/header-popup.html', 'Error adding taxes' ) %> + + Error: <% $error |h %> +

+ + + + +% } else { + <% include('/elements/header-popup.html', 'Taxes added') %> + + + + + +% } +<%init> + +$cgi->param('taxnum') =~ /^([\d,]+)$/ + or die 'Guru Meditation #69'; #??? should have been passed in +my @taxnum = split(',', $1); + +my $error = ''; +foreach my $taxnum ( @taxnum ) { + + my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } ) + or die "unknown taxnum: $taxnum"; + + if ( $cust_main_county->tax == 0 ) { #let's replace + + foreach (qw( taxname tax exempt_amount setuptax recurtax )) { + $cust_main_county->set( $_ => scalar($cgi->param($_)) ) + } + + $error = $cust_main_county->replace and last; + + } else { #let's insert a new record + + my $new = + new FS::cust_main_county { + ( map { $_ => scalar($cgi->param($_)) } + qw( taxname tax exempt_amount setuptax recurtax ) + ), + ( map { $_ => $cust_main_county->get($_) } + qw( country state county taxclass ) + ) + }; + + $error = $new->insert and last; + + } + +} + +if ( $error ) { + $cgi->param('error', $error); +} + + -- cgit v1.2.1