clean up tax rate editing:
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 <%
2 # <!-- $Id: cust_main_county-expand.cgi,v 1.2 2001-08-17 11:05:31 ivan Exp $ -->
3
4 use strict;
5 use vars qw ( $cgi $taxnum $cust_main_county @expansion $expansion );
6 use CGI;
7 use CGI::Carp qw(fatalsToBrowser);
8 use FS::UID qw(cgisuidsetup datasrc);
9 use FS::Record qw(qsearch qsearchs);
10 use FS::CGI qw(popurl);
11 use FS::cust_main_county;
12 use FS::cust_main;
13
14 $cgi = new CGI;
15 &cgisuidsetup($cgi);
16
17 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
18 $taxnum = $1;
19 $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
20   or die ("Unknown taxnum!");
21
22 if ( $cgi->param('delim') eq 'n' ) {
23   @expansion=split(/\n/,$cgi->param('expansion'));
24 } elsif ( $cgi->param('delim') eq 's' ) {
25   @expansion=split(' ',$cgi->param('expansion'));
26 } else {
27   die "Illegal delim!";
28 }
29
30 @expansion=map {
31   unless ( /^\s*([\w\- ]+)\s*$/ ) {
32     $cgi->param('error', "Illegal item in expansion");
33     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
34     exit;
35   }
36   $1;
37 } @expansion;
38
39 foreach ( @expansion) {
40   my(%hash)=$cust_main_county->hash;
41   my($new)=new FS::cust_main_county \%hash;
42   $new->setfield('taxnum','');
43   if ( ! $cust_main_county->state ) {
44     $new->setfield('state',$_);
45   } else {
46     $new->setfield('county',$_);
47   }
48   #if (datasrc =~ m/Pg/)
49   #{
50   #    $new->setfield('tax',0.0);
51   #}
52   my($error)=$new->insert;
53   die $error if $error;
54 }
55
56 unless ( qsearch('cust_main',{
57   'state'  => $cust_main_county->getfield('state'),
58   'county' => $cust_main_county->getfield('county'),
59   'country' =>  $cust_main_county->getfield('country'),
60 } ) ) {
61   my($error)=($cust_main_county->delete);
62   die $error if $error;
63 }
64
65 print $cgi->redirect(popurl(3). "browse/cust_main_county.cgi");
66
67 %>