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