new tax rate editor
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 <% include('/elements/header-popup.html', 'Addition successful' ) %>
2
3 <SCRIPT TYPE="text/javascript">
4   window.top.location.reload();
5 </SCRIPT>
6
7 </BODY>
8 </HTML>
9 <%init>
10
11 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
12 my $taxnum = $1;
13 my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
14   or die ("Unknown taxnum!");
15
16 my @expansion = split /[\n\r]{1,2}/, $cgi->param('expansion');
17 #warn scalar(@expansion);
18 #warn "$_: $expansion[$_]\n" foreach (0..$#expansion);
19
20 @expansion=map {
21   unless ( /^\s*([\w\- ]+)\s*$/ ) {
22     $cgi->param('error', "Illegal item in expansion: $_");
23     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
24     myexit();
25   }
26   $1;
27 } @expansion;
28
29 foreach ( @expansion) {
30   my(%hash)=$cust_main_county->hash;
31   my($new)=new FS::cust_main_county \%hash;
32   $new->setfield('taxnum','');
33   if ( $cgi->param('taxclass') ) {
34     $new->setfield('taxclass', $_);
35   } elsif ( ! $cust_main_county->state ) {
36     $new->setfield('state',$_);
37   } else {
38     $new->setfield('county',$_);
39   }
40   my $error = $new->insert;
41   die $error if $error;
42 }
43
44 unless ( qsearch( 'cust_main', {
45                                  'state'  => $cust_main_county->state,
46                                  'county' => $cust_main_county->county,
47                                  'country' =>  $cust_main_county->country,
48                                } )
49          || ! @expansion
50 ) {
51   my $error = $cust_main_county->delete;
52   die $error if $error;
53 }
54
55 </%init>