torrus virtual ports, RT#10574
[freeside.git] / httemplate / edit / process / cust_main_county-collapse.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 foreach my $delete ( qsearch('cust_main_county', \%search) ) {
28 #  unless ( qsearch('cust_main',{
29 #    'state'  => $cust_main_county->getfield('state'),
30 #    'county' => $cust_main_county->getfield('county'),
31 #    'country' =>  $cust_main_county->getfield('country'),
32 #  } ) ) {
33     my $error = $delete->delete;
34     die $error if $error;
35 #  } else {
36     #should really fix the $cust_main record
37 #  }
38
39 }
40
41 $cust_main_county->taxnum('');
42 if ( $cust_main_county->city ) {
43   $cust_main_county->city('');
44 } elsif ( $cust_main_county->county ) {
45   $cust_main_county->county('');
46 } else {
47   die "can't collapse that";
48 }
49
50 my $error = $cust_main_county->insert;
51 die $error if $error;
52
53 </%init>