a821560c6ef10d6ba9effa0ca284eefffcce6d34
[freeside.git] / htdocs / edit / process / cust_main_county-expand.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # process/cust_main_county-expand.cgi: Expand counties (process form)
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 use strict;
18 use CGI::Request;
19 use CGI::Carp qw(fatalsToBrowser);
20 use FS::UID qw(cgisuidsetup datasrc);
21 use FS::Record qw(qsearch qsearchs);
22 use FS::cust_main_county;
23 use FS::CGI qw(eidiot);
24
25 my($req)=new CGI::Request; # create form object
26
27 &cgisuidsetup($req->cgi);
28
29 $req->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
30 my($taxnum)=$1;
31 my($cust_main_county)=qsearchs('cust_main_county',{'taxnum'=>$taxnum})
32   or die ("Unknown taxnum!");
33
34 my(@counties);
35 if ( $req->param('delim') eq 'n' ) {
36   @counties=split(/\n/,$req->param('counties'));
37 } elsif ( $req->param('delim') eq 's' ) {
38   @counties=split(/\s+/,$req->param('counties'));
39 } else {
40   die "Illegal delim!";
41 }
42
43 @counties=map {
44   /^\s*([\w\- ]+)\s*$/ or eidiot("Illegal county");
45   $1;
46 } @counties;
47
48 my($county);
49 foreach ( @counties) {
50   my(%hash)=$cust_main_county->hash;
51   my($new)=create FS::cust_main_county \%hash;
52   $new->setfield('taxnum','');
53   $new->setfield('county',$_);
54   #if (datasrc =~ m/Pg/)
55   #{
56   #    $new->setfield('tax',0.0);
57   #}
58   my($error)=$new->insert;
59   die $error if $error;
60 }
61
62 unless ( qsearch('cust_main',{
63   'state'  => $cust_main_county->getfield('state'),
64   'county' => $cust_main_county->getfield('county'),
65 } ) ) {
66   my($error)=($cust_main_county->delete);
67   die $error if $error;
68 }
69
70 $req->cgi->redirect("../../edit/cust_main_county.cgi");
71