default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / process / cust_main_county-add.cgi
1 <% include('/elements/header-popup.html', 'Addition successful' ) %>
2
3 <SCRIPT TYPE="text/javascript">
4   topreload();
5 </SCRIPT>
6
7 </BODY>
8 </HTML>
9 <%init>
10
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
13
14 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
15 my $taxnum = $1;
16 my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
17   or die ("Unknown taxnum!");
18
19 my @expansion = split /[\n\r]{1,2}/, $cgi->param('expansion');
20
21 @expansion=map {
22   unless ( /^\s*([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)\s*$/ ) {
23     $cgi->param('error', "Illegal item in expansion: $_");
24     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
25     myexit();
26   }
27   $1;
28 } @expansion;
29
30 my $what = $cgi->param('what');
31 foreach my $new_tax_area ( @expansion ) {
32
33   # Clone specific tax columns from original tax row
34   #
35   # UI Note:  Preserving original behavior, of cloning
36   #   tax amounts into new tax record, against better
37   #   judgement.  If the new city/county/state has a
38   #   different tax value than the one being populated
39   #   (rather likely?) now the user must remember to
40   #   revisit each newly created tax row, and correct
41   #   the possibly incorrect tax values that were populated.
42   #   Values would be easier to identify and correct if
43   #   they were initially populated with 0% tax rates
44   # District Note: The 'district' column is NOT cloned
45   #   to the new tax row.   Manually entered taxes
46   #   are not be divided into road maintenance districts
47   #   like Washington state sales taxes
48   my $new = FS::cust_main_county->new({
49     map { $_ => $cust_main_county->getfield($_) }
50     qw/
51       charge_prediscount
52       exempt_amount
53       exempt_amount_currency
54       recurtax
55       setuptax
56       tax
57       taxname
58     /
59   });
60
61   # Clone additional location columns, based on the $what value
62   my %clone_cols_for = (
63     state  => [qw/country /],
64     county => [qw/country state/],
65     city   => [qw/country state county/],
66   );
67
68   die "unknown what: $what"
69     unless grep { $_ eq $what } keys %clone_cols_for;
70
71   $new->setfield( $_ => $cust_main_county->getfield($_) )
72     for @{ $clone_cols_for{ $cgi->param('what') } };
73
74   # In the US, store cities upper case for USPS validation
75   $new_tax_area = uc($new_tax_area)
76     if $what eq 'city'
77     && $new->country eq 'US';
78
79   $new->setfield( $what, $new_tax_area );
80   if ( my $error = $new->insert ) {
81     die $error;
82   }
83 }
84
85 </%init>