import torrus 1.0.9
[freeside.git] / httemplate / edit / process / cust_main_county-collapse.cgi
1 <% $cgi->redirect(popurl(3). "browse/cust_main_county.cgi") %>
2 <%init>
3
4 die "access denied"
5   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
6
7 my($query) = $cgi->keywords;
8 $query =~ /^(\d+)$/ or die "Illegal taxnum!";
9 my $taxnum = $1;
10 my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } )
11   or die "Unknown taxnum $taxnum";
12
13 #really should do this in a .pm & start transaction
14
15 my %search = (
16                'country' => $cust_main_county->country,
17                'state'   => $cust_main_county->state,
18              );
19
20 $search{'county'} = $cust_main_county->county
21   if $cust_main_county->city;
22
23 foreach my $delete ( qsearch('cust_main_county', \%search) ) {
24 #  unless ( qsearch('cust_main',{
25 #    'state'  => $cust_main_county->getfield('state'),
26 #    'county' => $cust_main_county->getfield('county'),
27 #    'country' =>  $cust_main_county->getfield('country'),
28 #  } ) ) {
29     my $error = $delete->delete;
30     die $error if $error;
31 #  } else {
32     #should really fix the $cust_main record
33 #  }
34
35 }
36
37 $cust_main_county->taxnum('');
38 if ( $cust_main_county->city ) {
39   $cust_main_county->city('');
40 } else {
41   $cust_main_county->county('');
42 }
43 my $error = $cust_main_county->insert;
44 die $error if $error;
45
46 </%init>