default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / process / cust_main_county-remove.cgi
1 <% $cgi->redirect(popurl(3). "browse/cust_main_county.cgi?".
2                              "country=". uri_escape($cgi->param('country')).";".
3                              'state='.   uri_escape($cgi->param('state')).  ';'.
4                              'county='.  uri_escape($cgi->param('county'))
5                  )
6 %>
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
11
12 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
13 my $taxnum = $1;
14 my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } )
15   or die "Unknown taxnum $taxnum";
16
17 #really should do this in a .pm & start transaction
18
19 my %search = (
20                'country' => $cust_main_county->country,
21                'state'   => $cust_main_county->state,
22              );
23
24 $search{'county'} = $cust_main_county->county
25   if $cust_main_county->city;
26
27 my $error = $cust_main_county->delete;
28 die $error if $error;
29
30 unless ( qsearch('cust_main_county', \%search) ) {
31
32   #if we're the last, clear our (state?)/county/city and reinsert
33
34   $cust_main_county->taxnum('');
35   if ( $cust_main_county->city ) {
36     $cust_main_county->city('');
37   } elsif ( $cust_main_county->county ) {
38     $cust_main_county->county('');
39   } else {
40     die "can't remove that";
41   }
42
43   my $error = $cust_main_county->insert;
44   die $error if $error;
45
46 }
47
48 </%init>