s/CGI::Request/CGI.pm/; etc
[freeside.git] / htdocs / edit / process / cust_main_county-expand.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_main_county-expand.cgi,v 1.3 1998-12-17 08:40:20 ivan Exp $
4 #
5 # ivan@sisd.com 97-dec-16
6 #
7 # Changes to allow page to work at a relative position in server
8 # Added import of datasrc from UID.pm for Pg6.3
9 # Default tax to 0.0 if using Pg6.3
10 #       bmccane@maxbaud.net     98-apr-3
11 #
12 # lose background, FS::CGI
13 # undo default tax to 0.0 if using Pg6.3: comes from pre-expanded record
14 # for that state
15 # ivan@sisd.com 98-sep-2
16 #
17 # $Log: cust_main_county-expand.cgi,v $
18 # Revision 1.3  1998-12-17 08:40:20  ivan
19 # s/CGI::Request/CGI.pm/; etc
20 #
21 # Revision 1.2  1998/11/18 09:01:40  ivan
22 # i18n! i18n!
23 #
24
25 use strict;
26 use CGI;
27 use CGI::Carp qw(fatalsToBrowser);
28 use FS::UID qw(cgisuidsetup datasrc);
29 use FS::Record qw(qsearch qsearchs);
30 use FS::CGI qw(eidiot popurl);
31 use FS::cust_main_county;
32 use FS::cust_main;
33
34 my($cgi)=new CGI;
35
36 &cgisuidsetup($cgi);
37
38 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
39 my($taxnum)=$1;
40 my($cust_main_county)=qsearchs('cust_main_county',{'taxnum'=>$taxnum})
41   or die ("Unknown taxnum!");
42
43 my(@expansion);
44 if ( $cgi->param('delim') eq 'n' ) {
45   @expansion=split(/\n/,$cgi->param('expansion'));
46 } elsif ( $cgi->param('delim') eq 's' ) {
47   @expansion=split(/\s+/,$cgi->param('expansion'));
48 } else {
49   die "Illegal delim!";
50 }
51
52 @expansion=map {
53   /^\s*([\w\- ]+)\s*$/ or eidiot("Illegal expansion");
54   $1;
55 } @expansion;
56
57 my($expansion);
58 foreach ( @expansion) {
59   my(%hash)=$cust_main_county->hash;
60   my($new)=create FS::cust_main_county \%hash;
61   $new->setfield('taxnum','');
62   if ( ! $cust_main_county->state ) {
63     $new->setfield('state',$_);
64   } else {
65     $new->setfield('county',$_);
66   }
67   #if (datasrc =~ m/Pg/)
68   #{
69   #    $new->setfield('tax',0.0);
70   #}
71   my($error)=$new->insert;
72   die $error if $error;
73 }
74
75 unless ( qsearch('cust_main',{
76   'state'  => $cust_main_county->getfield('state'),
77   'county' => $cust_main_county->getfield('county'),
78   'country' =>  $cust_main_county->getfield('country'),
79 } ) ) {
80   my($error)=($cust_main_county->delete);
81   die $error if $error;
82 }
83
84 print $cgi->redirect(popurl(3). "edit/cust_main_county.cgi");
85