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