summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/bulk-cust_main_county.html
blob: b5a0258b162aa6c69835559b2079b347d167d74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% if ( $error ) { #better to redirect back to 
%# <% $cgi->redirect("$url?". $cgi->query_string ) %>
  <% include('/elements/header-popup.html', "Error ${action}ing taxes" ) %>

  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error |h %></FONT>
  <BR><BR>

  </BODY>
  </HTML>

% } else {
  <% include('/elements/header-popup.html', "Taxes ${action}ed") %>

  <SCRIPT TYPE="text/javascript">
    topreload();
  </SCRIPT>

  </BODY>
  </HTML>
% }
<%init>

$cgi->param('taxnum') =~ /^([\d,]+)$/
  or die 'Guru Meditation #69'; #??? should have been passed in
my @taxnum = split(',', $1);

$cgi->param('action') =~ /^(add|edit)$/ or die "unknown action";
my $action = $1;

my $error = '';
foreach my $taxnum ( @taxnum ) {

  my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum } )
    or die "unknown taxnum: $taxnum";

  if ( $action eq 'edit' || $cust_main_county->tax == 0 ) { #let's replace

    foreach (qw( taxname tax exempt_amount setuptax recurtax )) {
      $cust_main_county->set( $_ => scalar($cgi->param($_)) )
    }

    $error = $cust_main_county->replace and last;

  } else { #let's insert a new record

    my $new =
      new FS::cust_main_county {
        ( map { $_ => scalar($cgi->param($_)) }
              qw( taxname tax exempt_amount setuptax recurtax )
        ),
        ( map { $_ => $cust_main_county->get($_) }
              qw( country state county city district taxclass ) 
        )
      };

    $error = $new->insert and last;
    
  }

}

if ( $error ) {
  $cgi->param('error', $error);
}

</%init>