default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 ${action}ing 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 ${action}ed") %>
13
14   <SCRIPT TYPE="text/javascript">
15     topreload();
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 $cgi->param('action') =~ /^(add|edit)$/ or die "unknown action";
28 my $action = $1;
29
30 my $rate_only = $cgi->param('rate_only') if $cgi->param('rate_only');
31
32 my $error = '';
33 foreach my $taxnum ( @taxnum ) {
34
35   my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } )
36     or die "unknown taxnum: $taxnum";
37
38   if ( $action eq 'edit' || $cust_main_county->tax == 0 ) { #let's replace
39
40     if ($rate_only) {
41       $cust_main_county->set( tax => scalar($cgi->param('tax')) );
42     }
43     else {
44       foreach (qw( taxname tax exempt_amount setuptax recurtax )) {
45         $cust_main_county->set( $_ => scalar($cgi->param($_)) )
46       }
47     }
48
49     $error = $cust_main_county->replace and last;
50
51   } else { #let's insert a new record
52
53     my $new =
54       new FS::cust_main_county {
55         ( map { $_ => scalar($cgi->param($_)) }
56               qw( taxname tax exempt_amount setuptax recurtax )
57         ),
58         ( map { $_ => $cust_main_county->get($_) }
59               qw( country state county city district taxclass ) 
60         )
61       };
62
63     $error = $new->insert and last;
64     
65   }
66
67 }
68
69 if ( $error ) {
70   $cgi->param('error', $error);
71 }
72
73 </%init>