enable CardFortress in test database, #71513
[freeside.git] / httemplate / elements / select-taxclass.html
index e5a1abb..6845d23 100644 (file)
@@ -1,42 +1,41 @@
-<%
-  my $conf = new FS::Conf;
-  my $selected_taxclass = scalar(@_) ? shift : '';
-%>
+% if ( $conf->exists('enable_taxclasses') ) { 
 
-<% if ( $conf->exists('enable_taxclasses') ) { %>
+    <SELECT NAME="<% $opt{'element_name'} || $opt{'field'} || 'taxclass' %>">
 
-    <SELECT NAME="taxclass">
+%   if ( $conf->exists('require_taxclasses') ) { 
+        <OPTION VALUE="(select)">Select tax class
+%   } else { 
+        <OPTION VALUE="">
+%   } 
 
-      <% if ( $conf->exists('require_taxclasses') ) { %>
+%   foreach my $taxclass ( @{ $opt{'taxclasses'} } ) { 
+        <OPTION VALUE="<% $taxclass %>"<% $taxclass eq $selected_taxclass ? ' SELECTED' : '' %>><% $taxclass %>
+%   } 
 
-        <OPTION VALUE="(select)">Select tax class
+    </SELECT>
 
-      <% } else { %>
+% } else { 
 
-        <OPTION VALUE="">
+  <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'taxclass' %>" VALUE="<% $selected_taxclass %>">
 
-      <% } %>
-
-      <%
-        my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
-          or die dbh->errstr;
-        $sth->execute or die $sth->errstr;
-        my %taxclasses = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
-        my @taxclasses = grep $_, keys %taxclasses;
-      %>
-  
-      <% foreach my $taxclass ( @taxclasses ) { %>
-  
-          <OPTION VALUE="<%= $taxclass %>"<%= $taxclass eq $selected_taxclass ? ' SELECTED' : '' %>><%= $taxclass %>
-  
-      <% } %>
+% } 
 
-    </SELECT>
+<%init>
+
+my %opt = @_;
+my $selected_taxclass = $opt{'curr_value'}; # || $opt{'value'} necessary?
+
+my $conf = new FS::Conf;
+
+unless ( $opt{'taxclasses'} ) {
 
-<% } else { %>
+  #my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
+  my $sth = dbh->prepare("SELECT taxclass FROM part_pkg_taxclass WHERE disabled IS NULL OR disabled = '' OR taxclass = ?")
+    or die dbh->errstr;
+  $sth->execute($selected_taxclass) or die $sth->errstr;
+  my %taxclasses = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
+  @{ $opt{'taxclasses'} } = grep $_, keys %taxclasses;
 
-  <INPUT TYPE="hidden" NAME="taxclass" VALUE="<%= $selected_taxclass %>">
-  
-<% } %>
-  
+}
 
+</%init>