add a quick bulk tax add tool (eating my own dogfood instead of running a one-off...
[freeside.git] / httemplate / edit / process / bulk-cust_main_county.html
1 % if ( $error ) { #better to redirect back to 
2 %# <% $cgi->redirect("$url?". $cgi->query_string ) %>
3   <% include('/elements/header-popup.html', 'Error adding taxes' ) %>
4
5   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error |h %></FONT>
6   <BR><BR>
7
8   </BODY>
9   </HTML>
10
11 % } else {
12   <% include('/elements/header-popup.html', 'Taxes added') %>
13
14   <SCRIPT TYPE="text/javascript">
15     window.top.location.reload();
16   </SCRIPT>
17
18   </BODY>
19   </HTML>
20 % }
21 <%init>
22
23 $cgi->param('taxnum') =~ /^([\d,]+)$/
24   or die 'Guru Meditation #69'; #??? should have been passed in
25 my @taxnum = split(',', $1);
26
27 my $error = '';
28 foreach my $taxnum ( @taxnum ) {
29
30   my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } )
31     or die "unknown taxnum: $taxnum";
32
33   if ( $cust_main_county->tax == 0 ) { #let's replace
34
35     foreach (qw( taxname tax exempt_amount setuptax recurtax )) {
36       $cust_main_county->set( $_ => scalar($cgi->param($_)) )
37     }
38
39     $error = $cust_main_county->replace and last;
40
41   } else { #let's insert a new record
42
43     my $new =
44       new FS::cust_main_county {
45         ( map { $_ => scalar($cgi->param($_)) }
46               qw( taxname tax exempt_amount setuptax recurtax )
47         ),
48         ( map { $_ => $cust_main_county->get($_) }
49               qw( country state county taxclass ) 
50         )
51       };
52
53     $error = $new->insert and last;
54     
55   }
56
57 }
58
59 if ( $error ) {
60   $cgi->param('error', $error);
61 }
62
63 </%init>