summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_tax_adjustment.html
blob: 9d4afbc6042e5e3492f0a016db2693374f1311cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<% include('/elements/header-popup.html', 'Tax adjustment' ) %>

<% include('/elements/error.html') %>

<SCRIPT TYPE="text/javascript">

function enable_tax_adjustment () {
  if (    document.TaxAdjustmentForm.amount.value
       && document.TaxAdjustmentForm.taxname.selectedIndex > 0  ) {
    document.TaxAdjustmentForm.submit.disabled = false;
  } else {
    document.TaxAdjustmentForm.submit.disabled = true;
  }
}

function validate_tax_adjustment () {
  var comment = document.TaxAdjustmentForm.comment.value;
  var comment_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
  var amount = document.TaxAdjustmentForm.amount.value;
  var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
  var rval = true;

  if ( ! amount_regex.test(amount) ) {
    alert('Illegal amount - enter the amount of the tax adjustment, for example, "5" or "43" or "21.46".');
    return false;
  }
  if ( ! comment_regex.test(comment) ) {
    alert('Illegal comment - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
    return false;
  }

  return true;
}

</SCRIPT>

<FORM ACTION="process/cust_tax_adjustment.html" NAME="TaxAdjustmentForm" ID="TaxAdjustmentForm" METHOD="POST" onsubmit="document.TaxAdjustmentForm.submit.disabled=true;return validate_tax_adjustment();">

<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">

<TABLE ID="TaxAdjustmentTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">

<TR>
  <TD ALIGN="right">Tax </TD>
  <TD>
    <SELECT NAME="taxname" ID="taxname" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
      <OPTION VALUE=""></OPTION>
%     foreach my $taxname (@taxname) {
        <OPTION VALUE="<% $taxname %>"><% $taxname %></OPTION>
%     }
    </SELECT>
  </TD>
</TR>

<TR>
  <TD ALIGN="right">Amount </TD>
  <TD>
    $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
  </TD>
</TR>

<TR>
  <TD ALIGN="right">Comment </TD>
  <TD>
    <INPUT TYPE="text" NAME="comment" SIZE="50" MAXLENGTH="50" VALUE="<% $comment %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
  </TD>
</TR>

</TABLE>

<BR>
<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add tax adjustment" <% $cgi->param('error') ? '' :' DISABLED' %>>

</FORM>

</BODY>
</HTML>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Add customer tax adjustment');

my $sql = 'SELECT DISTINCT(taxname) FROM cust_main_county';
my $sth = dbh->prepare($sql) or die dbh->errstr;
$sth->execute() or die $sth->errstr;
my @taxname = map { $_->[0] || 'Tax' } @{ $sth->fetchall_arrayref([]) };

my $conf = new FS::Conf;

$cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
my $custnum = $1;

my $amount = '';
if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
  $amount = $1;
}

$cgi->param('comment') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ 
  or die 'illegal description';
my $comment = $1;

</%init>