for mod_perl: no more top-level my() variables; use vars instead
[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.5 1999-01-19 05:13:51 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.5  1999-01-19 05:13:51  ivan
19 # for mod_perl: no more top-level my() variables; use vars instead
20 # also the last s/create/new/;
21 #
22 # Revision 1.4  1999/01/18 22:47:52  ivan
23 # s/create/new/g; and use fields('table_name')
24 #
25 # Revision 1.3  1998/12/17 08:40:20  ivan
26 # s/CGI::Request/CGI.pm/; etc
27 #
28 # Revision 1.2  1998/11/18 09:01:40  ivan
29 # i18n! i18n!
30 #
31
32 use strict;
33 use vars qw ( $cgi $taxnum $cust_main_county @expansion $expansion );
34 use CGI;
35 use CGI::Carp qw(fatalsToBrowser);
36 use FS::UID qw(cgisuidsetup datasrc);
37 use FS::Record qw(qsearch qsearchs);
38 use FS::CGI qw(eidiot popurl);
39 use FS::cust_main_county;
40 use FS::cust_main;
41
42 $cgi = new CGI;
43
44 &cgisuidsetup($cgi);
45
46 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
47 $taxnum = $1;
48 $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
49   or die ("Unknown taxnum!");
50
51 if ( $cgi->param('delim') eq 'n' ) {
52   @expansion=split(/\n/,$cgi->param('expansion'));
53 } elsif ( $cgi->param('delim') eq 's' ) {
54   @expansion=split(/\s+/,$cgi->param('expansion'));
55 } else {
56   die "Illegal delim!";
57 }
58
59 @expansion=map {
60   /^\s*([\w\- ]+)\s*$/ or eidiot("Illegal expansion");
61   $1;
62 } @expansion;
63
64 foreach ( @expansion) {
65   my(%hash)=$cust_main_county->hash;
66   my($new)=new FS::cust_main_county \%hash;
67   $new->setfield('taxnum','');
68   if ( ! $cust_main_county->state ) {
69     $new->setfield('state',$_);
70   } else {
71     $new->setfield('county',$_);
72   }
73   #if (datasrc =~ m/Pg/)
74   #{
75   #    $new->setfield('tax',0.0);
76   #}
77   my($error)=$new->insert;
78   die $error if $error;
79 }
80
81 unless ( qsearch('cust_main',{
82   'state'  => $cust_main_county->getfield('state'),
83   'county' => $cust_main_county->getfield('county'),
84   'country' =>  $cust_main_county->getfield('country'),
85 } ) ) {
86   my($error)=($cust_main_county->delete);
87   die $error if $error;
88 }
89
90 print $cgi->redirect(popurl(3). "edit/cust_main_county.cgi");
91