e550e8b4a8182909a41043b849bd8acdecd93578
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 %
2 %
3 %$cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
4 %my $taxnum = $1;
5 %my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
6 %  or die ("Unknown taxnum!");
7 %
8 %my @expansion;
9 %if ( $cgi->param('delim') eq 'n' ) {
10 %  @expansion=split(/\n/,$cgi->param('expansion'));
11 %} elsif ( $cgi->param('delim') eq 's' ) {
12 %  @expansion=split(' ',$cgi->param('expansion'));
13 %} else {
14 %  die "Illegal delim!";
15 %}
16 %
17 %@expansion=map {
18 %  unless ( /^\s*([\w\- ]+)\s*$/ ) {
19 %    $cgi->param('error', "Illegal item in expansion");
20 %    print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
21 %    myexit();
22 %  }
23 %  $1;
24 %} @expansion;
25 %
26 %foreach ( @expansion) {
27 %  my(%hash)=$cust_main_county->hash;
28 %  my($new)=new FS::cust_main_county \%hash;
29 %  $new->setfield('taxnum','');
30 %  if ( $cgi->param('taxclass') ) {
31 %    $new->setfield('taxclass', $_);
32 %  } elsif ( ! $cust_main_county->state ) {
33 %    $new->setfield('state',$_);
34 %  } else {
35 %    $new->setfield('county',$_);
36 %  }
37 %  #if (datasrc =~ m/Pg/)
38 %  #{
39 %  #    $new->setfield('tax',0.0);
40 %  #}
41 %  my($error)=$new->insert;
42 %  die $error if $error;
43 %}
44 %
45 %unless ( qsearch( 'cust_main', {
46 %                                 'state'  => $cust_main_county->state,
47 %                                 'county' => $cust_main_county->county,
48 %                                 'country' =>  $cust_main_county->country,
49 %                               } )
50 %         || ! @expansion
51 %) {
52 %  my($error)=($cust_main_county->delete);
53 %  die $error if $error;
54 %}
55 %
56 %print $cgi->redirect(popurl(3). "browse/cust_main_county.cgi");
57 %
58 %
59