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