new tax rate editor
[freeside.git] / httemplate / edit / cust_main_county-expand.cgi
1 <% include('/elements/header-popup.html', "Enter $title") %>
2
3 <% include('/elements/error.html') %>
4
5 <FORM ACTION="<% $p1 %>process/cust_main_county-expand.cgi" METHOD=POST>
6
7 <INPUT TYPE="hidden" NAME="taxnum" VALUE="<% $taxnum %>">
8 <INPUT TYPE="hidden" NAME="taxclass" VALUE="<% $taxclass |h %>">
9
10 <TEXTAREA NAME="expansion" COLS="50" ROWS="16"><% $expansion |h %></TEXTAREA>
11
12 <BR>
13 <INPUT TYPE="submit" VALUE="Add <% $title %>">
14
15 </FORM>
16 </BODY>
17 </HTML>
18
19 <%init>
20
21 my($taxnum, $expansion, $taxclass);
22 my($query) = $cgi->keywords;
23 if ( $cgi->param('error') ) {
24   $taxnum = $cgi->param('taxnum');
25   $expansion = $cgi->param('expansion');
26   $taxclass = $cgi->param('taxclass');
27 } else {
28   $query =~ /^(taxclass)?(\d+)$/
29     or die "Illegal taxnum (query $query)";
30   $taxclass = $1 ? 'taxclass' : '';
31   $taxnum = $2;
32   $expansion = '';
33 }
34
35 my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
36   or die "cust_main_county.taxnum $taxnum not found";
37
38 my $title;
39 if ( $taxclass ) {
40   die "Can't expand entry!" if $cust_main_county->taxclass;
41
42   $title = 'Tax Classes';
43
44   # prepopuplate with other tax classes... which should really have a primary
45   #  key of their own... also this could be more efficient in the error case...
46   my $sth = dbh->prepare("SELECT DISTINCT taxclass FROM cust_main_county")
47     or die dbh->errstr;
48   $sth->execute or die $sth->errstr;
49   my %taxclasses = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
50   $expansion ||= join("\n", grep $_, keys %taxclasses );
51   
52 } else {
53   die "Can't expand entry!" if $cust_main_county->county;
54
55   if ( $cust_main_county->state ) {
56     $title = 'Counties';
57   } else {
58     $title = 'States/Provinces';
59   }
60
61 }
62
63 my $p1 = popurl(1);
64
65 </%init>