-<%
- my( $cust_main ) = @_;
- my $conf = new FS::Conf;
-%>
+<SCRIPT TYPE="text/javascript">
-<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') ) { %>
+function enable_quick_charge () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.amount.value
+ && document.QuickChargeForm.pkg.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
- <SELECT NAME="taxclass">
+function enable_quick_charge_desc () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.amount.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
- <% if ( $conf->exists('require_taxclasses') ) { %>
+function enable_quick_charge_amount () {
+ //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+ if ( document.QuickChargeForm.pkg.value ) {
+ document.QuickChargeForm.submit.disabled = false;
+ } else {
+ document.QuickChargeForm.submit.disabled = true;
+ }
+}
- <OPTION VALUE="(select)">Select tax class
+function validate_quick_charge () {
+ //alert('validate_quick_charge');
+ var pkg = document.QuickChargeForm.pkg.value;
+ var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/ ;
+ var amount = document.QuickChargeForm.amount.value;
+ var amount_regex = /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ;
- <% } else { %>
+ if ( amount_regex.test(amount) && pkg_regex.test(pkg) ) {
+ return true;
+ } else if ( amount_regex.test(amount) ) {
+ if ( pkg ) {
+ alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
+ } else {
+ alert('Enter a description for the one-time charge');
+ }
+ return false;
+ } else {
+ alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
+ return false;
+ }
+}
- <OPTION VALUE="">
+</SCRIPT>
- <% } %>
+<FORM NAME="QuickChargeForm" ACTION="<%$p%>edit/process/quick-charge.cgi" METHOD="POST" onSubmit="return validate_quick_charge()">
- <%
- 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 %>
-
- <% } %>
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
- </SELECT>
+Description:<INPUT TYPE="text" NAME="pkg" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_desc()">
-<% } else { %>
+Amount:<INPUT TYPE="text" NAME="amount" SIZE=6 onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_amount()">
+
+<% include('/elements/select-taxclass.html') %>
+
+<INPUT NAME="submit" TYPE="submit" VALUE="One-time charge" DISABLED>
- <INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
-
-<% } %>
-
-<INPUT TYPE="submit" VALUE="One-time charge">
</FORM>
+<%init>
+
+my( $cust_main ) = @_;
+
+</%init>