fix tax class selection in package add/edit too
authorivan <ivan>
Sat, 8 Oct 2005 00:47:20 +0000 (00:47 +0000)
committerivan <ivan>
Sat, 8 Oct 2005 00:47:20 +0000 (00:47 +0000)
httemplate/edit/part_pkg.cgi
httemplate/edit/process/part_pkg.cgi
httemplate/edit/process/quick-charge.cgi
httemplate/elements/select-taxclass.html [new file with mode: 0644]
httemplate/view/cust_main/quick-charge.html

index e6e10e7..2c3808f 100755 (executable)
@@ -1,4 +1,3 @@
-<!-- mason kludge -->
 <%
 
 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
@@ -120,42 +119,31 @@ Tax information
   <TR>
     <TD ALIGN="right">Setup fee tax exempt</TD>
     <TD>
-<%
-
-print '<INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y"';
-print ' CHECKED' if $hashref->{setuptax} eq "Y";
-print '>';
+      <INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <%= $hashref->{setuptax} eq 'Y' ? ' CHECKED' : '' %>>
+    </TD>
+  </TR>
+  <TR>
+    <TD ALIGN="right">Recurring fee tax exempt</TD>
+    <TD>
+      <INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y" <%= $hashref->{recurtax} eq 'Y' ? ' CHECKED' : '' %>>
+    </TD>
+  </TR>
 
-print <<END;
-</TD></TR>
-<TR><TD ALIGN="right">Recurring fee tax exempt</TD><TD>
-END
+<% my $conf = new FS::Conf; %>
+<% if ( $conf->exists('enable_taxclasses') ) { %>
 
-print '<INPUT TYPE="checkbox" NAME="recurtax" VALUE="Y"';
-print ' CHECKED' if $hashref->{recurtax} eq "Y";
-print '>';
+  <TR>
+    <TD align="right">Tax class</TD>
+    <TD>
+      <%= include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
+    </TD>
+  </TR>
 
-print '</TD></TR>';
+<% } else { %>
 
-my $conf = new FS::Conf;
-#false laziness w/ view/cust_main.cgi quick order
-if ( $conf->exists('enable_taxclasses') ) {
-  print '<TR><TD ALIGN="right">Tax class</TD><TD><SELECT NAME="taxclass">';
-  my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
-    or die dbh->errstr;
-  $sth->execute or die $sth->errstr;
-  foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
-    print qq!<OPTION VALUE="$taxclass"!;
-    print ' SELECTED' if $taxclass eq $hashref->{taxclass};
-    print qq!>$taxclass</OPTION>!;
-  }
-  print '</SELECT></TD></TR>';
-} else {
-  print
-    '<INPUT TYPE="hidden" NAME="taxclass" VALUE="'. $hashref->{taxclass}. '">';
-}
+  <%= include('/elements/select-taxclass.html', $hashref->{taxclass} ) %>
 
-%>
+<% } %>
 
 </TABLE>
 
index 1a7f528..0d0a134 100755 (executable)
@@ -29,12 +29,18 @@ my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
 
 my $error;
 my $custnum = '';
-if ( $pkgpart ) {
+if ( $cgi->param('taxclass') eq '(select)' ) {
+
+  $error = 'Must select a tax class';
+
+} elsif ( $pkgpart ) {
+
   $error = $new->replace( $old,
                           pkg_svc     => \%pkg_svc,
                           primary_svc => scalar($cgi->param('pkg_svc_primary')),
                         );
 } else {
+
   $error = $new->insert(  pkg_svc     => \%pkg_svc,
                           primary_svc => scalar($cgi->param('pkg_svc_primary')),
                           cust_pkg    => $cgi->param('pkgnum'),
@@ -42,6 +48,7 @@ if ( $pkgpart ) {
                        );
   $pkgpart = $new->pkgpart;
 }
+
 if ( $error ) {
   $cgi->param('error', $error );
   print $cgi->redirect(popurl(2). "part_pkg.cgi?". $cgi->query_string );
index 9d9aa98..928e3da 100644 (file)
@@ -13,7 +13,7 @@ my( $error, $cust_main);
 if ( $cgi->param('taxclass') eq '(select)' ) {
 
 
- $error = "Must select a tax class";
+ $error = 'Must select a tax class';
 } else {
 
   my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
diff --git a/httemplate/elements/select-taxclass.html b/httemplate/elements/select-taxclass.html
new file mode 100644 (file)
index 0000000..e8889d5
--- /dev/null
@@ -0,0 +1,42 @@
+<%
+  my $conf = new FS::Conf;
+  my $selected_taxclass = scalar(@_) ? shift : '';
+%>
+
+<% if ( $conf->exists('enable_taxclasses') ) { %>
+
+    <SELECT NAME="taxclass">
+
+      <% if ( $conf->exists('require_taxclasses') ) { %>
+
+        <OPTION VALUE="(select)">Select tax class
+
+      <% } else { %>
+
+        <OPTION VALUE="">
+
+      <% } %>
+
+      <%
+        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>
+
+<% } else { %>
+
+  <INPUT TYPE="hidden" NAME="taxclass" VALUE="<%= $selected_taxclass %>">';
+  
+<% } %>
+  
+
index 9e4fb8c..2fe3d5f 100644 (file)
@@ -1,49 +1,18 @@
 <%
   my( $cust_main ) = @_;
-  my $conf = new FS::Conf;
 %>
 
 <FORM ACTION="<%=$p%>edit/process/quick-charge.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $cust_main->custnum %>">
-Description:<INPUT TYPE="text" NAME="pkg">
-Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>
-<% #false laziness w/ edit/part_pkg.cgi %>
-<% if ( $conf->exists('enable_taxclasses') ) { %>
-
-    <SELECT NAME="taxclass">
-
-      <% if ( $conf->exists('require_taxclasses') ) { %>
-
-        <OPTION VALUE="(select)">Select tax class
 
-      <% } else { %>
-
-        <OPTION VALUE="">
-
-      <% } %>
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $cust_main->custnum %>">
 
-      <%
-        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 %>"<%= 0 ? ' SELECTED' : '' %>><%= $taxclass %>
-  
-      <% } %>
+Description:<INPUT TYPE="text" NAME="pkg">
 
-    </SELECT>
+Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>
 
-<% } else { %>
+<%= include('/elements/select-taxclass.html') %>
 
-  <INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
-  
-<% } %>
-  
 <INPUT TYPE="submit" VALUE="One-time charge">
+
 </FORM>