add require_taxclasses config flag
authorivan <ivan>
Fri, 7 Oct 2005 02:25:41 +0000 (02:25 +0000)
committerivan <ivan>
Fri, 7 Oct 2005 02:25:41 +0000 (02:25 +0000)
FS/FS/Conf.pm
FS/FS/part_pkg.pm
httemplate/edit/process/quick-charge.cgi
httemplate/view/cust_main/quick-charge.html

index 0bf1afe..30aa1e7 100644 (file)
@@ -1258,6 +1258,13 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'require_taxclasses',
+    'section'     => 'billing',
+    'description' => 'Require a taxclass to be entered for every package',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'welcome_email',
     'section'     => '',
     'description' => 'Template file for welcome email.  Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created.  See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code></ul>',
index db31e45..73f3bae 100644 (file)
@@ -441,6 +441,10 @@ sub check {
   return 'Unknown plan '. $self->plan
     unless exists($plans{$self->plan});
 
+  my $conf = new FS::Conf;
+  return 'Taxclass is required'
+    if ! $self->taxclass && $conf->exists('require_taxclasses');
+
   '';
 }
 
index 477f585..9d9aa98 100644 (file)
@@ -9,15 +9,24 @@ $cgi->param('amount') =~ /^\s*(\d+(\.\d{1,2})?)\s*$/
   or die 'illegal amount '. $cgi->param('amount');
 my $amount = $1;
 
-my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
-  or die "unknown custnum $custnum";
-
-my $error = $cust_main->charge(
-  $amount,
-  $cgi->param('pkg'),
-  '$'. sprintf("%.2f",$amount),
-  $cgi->param('taxclass')
-);
+my( $error, $cust_main);
+if ( $cgi->param('taxclass') eq '(select)' ) {
+
+
+ $error = "Must select a tax class";
+} else {
+
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or die "unknown custnum $custnum";
+
+  $error = $cust_main->charge(
+    $amount,
+    $cgi->param('pkg'),
+    '$'. sprintf("%.2f",$amount),
+    $cgi->param('taxclass')
+  );
+
+}
 
 if ($error) {
 %>
index 0b51586..9e4fb8c 100644 (file)
@@ -6,26 +6,43 @@
 <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">
-&nbsp;Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>
-&nbsp;<% 
+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="">
+
+      <% } %>
+
+      <%
+        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;
+      %>
   
-  #false laziness w/ edit/part_pkg.cgi
-  if ( $conf->exists('enable_taxclasses') ) {
-    print '<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>';
-  } else {
-    print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
-  }
+      <% foreach my $taxclass ( @taxclasses ) { %>
+  
+          <OPTION VALUE="<%= $taxclass %>"<%= 0 ? ' SELECTED' : '' %>><%= $taxclass %>
+  
+      <% } %>
 
-%>
+    </SELECT>
+
+<% } else { %>
+
+  <INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
+  
+<% } %>
   
 <INPUT TYPE="submit" VALUE="One-time charge">
 </FORM>