Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / edit / cust_tax_adjustment.html
1 <% include('/elements/header-popup.html', 'Tax adjustment' ) %>
2
3 <% include('/elements/error.html') %>
4
5 <SCRIPT TYPE="text/javascript">
6
7 function enable_tax_adjustment () {
8   if (    document.TaxAdjustmentForm.amount.value
9        && document.TaxAdjustmentForm.taxname.selectedIndex > 0  ) {
10     document.TaxAdjustmentForm.submit.disabled = false;
11   } else {
12     document.TaxAdjustmentForm.submit.disabled = true;
13   }
14 }
15
16 function validate_tax_adjustment () {
17   var comment = document.TaxAdjustmentForm.comment.value;
18   var comment_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
19   var amount = document.TaxAdjustmentForm.amount.value;
20   var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
21   var rval = true;
22
23   if ( ! amount_regex.test(amount) ) {
24     alert('Illegal amount - enter the amount of the tax adjustment, for example, "5" or "43" or "21.46".');
25     return false;
26   }
27   if ( ! comment_regex.test(comment) ) {
28     alert('Illegal comment - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
29     return false;
30   }
31
32   return true;
33 }
34
35 </SCRIPT>
36
37 <FORM ACTION="process/cust_tax_adjustment.html" NAME="TaxAdjustmentForm" ID="TaxAdjustmentForm" METHOD="POST" onsubmit="document.TaxAdjustmentForm.submit.disabled=true;return validate_tax_adjustment();">
38
39 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
40
41 <TABLE ID="TaxAdjustmentTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
42
43 <TR>
44   <TD ALIGN="right">Tax </TD>
45   <TD>
46     <SELECT NAME="taxname" ID="taxname" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
47       <OPTION VALUE=""></OPTION>
48 %     foreach my $taxname (@taxname) {
49         <OPTION VALUE="<% $taxname %>"><% $taxname %></OPTION>
50 %     }
51     </SELECT>
52   </TD>
53 </TR>
54
55 <TR>
56   <TD ALIGN="right">Amount </TD>
57   <TD>
58     $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
59   </TD>
60 </TR>
61
62 <TR>
63   <TD ALIGN="right">Comment </TD>
64   <TD>
65     <INPUT TYPE="text" NAME="comment" SIZE="50" MAXLENGTH="50" VALUE="<% $comment %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
66   </TD>
67 </TR>
68
69 </TABLE>
70
71 <BR>
72 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add tax adjustment" <% $cgi->param('error') ? '' :' DISABLED' %>>
73
74 </FORM>
75
76 </BODY>
77 </HTML>
78 <%init>
79
80 die "access denied"
81   unless $FS::CurrentUser::CurrentUser->access_right('Add customer tax adjustment');
82
83 my $sql = 'SELECT DISTINCT(taxname) FROM cust_main_county';
84 my $sth = dbh->prepare($sql) or die dbh->errstr;
85 $sth->execute() or die $sth->errstr;
86 my @taxname = map { $_->[0] || 'Tax' } @{ $sth->fetchall_arrayref([]) };
87
88 my $conf = new FS::Conf;
89
90 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
91 my $custnum = $1;
92
93 my $amount = '';
94 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
95   $amount = $1;
96 }
97
98 $cgi->param('comment') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ 
99   or die 'illegal description';
100 my $comment = $1;
101
102 </%init>