diff options
author | ivan <ivan> | 2008-10-12 00:54:18 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-10-12 00:54:18 +0000 |
commit | 9eded70a59f22d7df3b645ad3636e28e0fd08bee (patch) | |
tree | 866b87cb436a39c83c15f94b94b55eeeaf8ba7b6 /httemplate/edit | |
parent | 5d6b394a5c676e5b87819a205da545f17fde8616 (diff) |
add a quick bulk tax add tool (eating my own dogfood instead of running a one-off SQL query), RT#4117
Diffstat (limited to 'httemplate/edit')
-rw-r--r-- | httemplate/edit/bulk-cust_main_county.html | 130 | ||||
-rw-r--r-- | httemplate/edit/process/bulk-cust_main_county.html | 63 |
2 files changed, 193 insertions, 0 deletions
diff --git a/httemplate/edit/bulk-cust_main_county.html b/httemplate/edit/bulk-cust_main_county.html new file mode 100644 index 000000000..bb57fc5d3 --- /dev/null +++ b/httemplate/edit/bulk-cust_main_county.html @@ -0,0 +1,130 @@ +<% include('/elements/header-popup.html', 'Bulk Tax rate') %> + +<FORM ACTION="<% popurl(1)."process/bulk-cust_main_county.html" %>" METHOD="POST"> + +<INPUT TYPE="hidden" NAME="taxnum" VALUE="<% join(',', @taxnum) %>"> + +<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0> + +<% include('/elements/tr-td-label.html', 'label' => 'Country' ) %> + <TD BGCOLOR="#dddddd"><% $countries %> + </TD> +</TR> + +<% include('/elements/tr-td-label.html', 'label' => 'State' ) %> + <TD BGCOLOR="#dddddd"><% $states %> + </TD> +</TR> + +% if ( $counties ) { + <% include('/elements/tr-td-label.html', 'label' => 'County' ) %> + <TD BGCOLOR="#dddddd"><% $counties %> + </TD> + </TR> +% } + +% if ( $conf->exists('enable_taxclasses') && $taxclasses ) { + <% include('/elements/tr-td-label.html', 'label' => 'Tax Class' ) %> + <TD BGCOLOR="#dddddd"><% $taxclasses %> + </TD> + </TR> +% } + +<% include('/elements/tr-input-text.html', + 'field' => 'taxname', + 'label' => 'Tax name' + ) +%> + +<% include('/elements/tr-input-percentage.html', + 'field' => 'tax', + 'label' => 'Tax rate', + ) +%> + +<% include('/elements/tablebreak-tr-title.html', value=>'Exemptions' ) %> + +<% include('/elements/tr-checkbox.html', + 'field' => 'setuptax', + 'value' => 'Y', + 'label' => 'This tax not applicable to setup fees', + ) +%> + +<% include('/elements/tr-checkbox.html', + 'field' => 'recurtax', + 'value' => 'Y', + 'label' => 'This tax not applicable to recurring fees', + ) +%> + +<% include('/elements/tr-input-money.html', + 'field' => 'exempt_amount', + 'label' => 'Monthly exemption per customer ($25 "Texas tax")', + ) +%> + +</TABLE> + +<BR> + +<INPUT TYPE="submit" VALUE="Bulk add tax"> + +<%init> + +my $conf = new FS::Conf; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my @taxnum; +if ( $cgi->param('error') ) { + $cgi->param('taxnum') =~ /^([\d,]+)$/ + or die "no taxnum, but error: ". $cgi->param('error'); + @taxnum = split(',', $1); +} else { + my($query) = $cgi->keywords; + $query =~ /^([\d,]+)$/ + or die 'Nothing selected'; #XXX better error when nothing selected + @taxnum = split(',', $1); +} + +my @cust_main_county = + map { + qsearchs('cust_main_county', { 'taxnum' => $_ }) + or die "unknown taxnum $1"; + } + @taxnum; + +my %seen_country = {}; +my @countries = map code2country($_)." ($_)", + grep !$seen_country{$_}++, + map $_->country, + @cust_main_county; +my $countries = join(', ', @countries); + +my %seen_state = {}; +my @states = map state_label($_->[0], $_->[1]), + grep !$seen_state{$_->[0]}++, + map [ $_->state, $_->country ], + @cust_main_county; +my $states = join(', ', @states); + +my %seen_county = {}; +my @counties = grep !$seen_county{$_}++, map $_->county, @cust_main_county; +my $counties = join(', ', @counties); + +my %seen_taxclass = {}; +my @taxclasses = grep !$seen_taxclass{$_}++, map $_->taxclass, @cust_main_county; +my $taxclasses = join(', ', @taxclasses); + +#my @fields = ( +# { field=>'country', type=>'fixed-country', }, +# { field=>'state', type=>'fixed-state', }, +# { field=>'county', type=>'fixed', }, +#); + +#push @fields, { field=>'taxclass', type=>'fixed', } +# if $conf->exists('enable_taxclasses'); + +</%init> 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' ) %> + + <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error |h %></FONT> + <BR><BR> + + </BODY> + </HTML> + +% } else { + <% include('/elements/header-popup.html', 'Taxes added') %> + + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + + </BODY> + </HTML> +% } +<%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); +} + +</%init> |