summaryrefslogtreecommitdiff
path: root/httemplate/edit/quick-charge.html
blob: c18b2bc6413e788f56ba772f1f030474ea2fbb33 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<% include("/elements/header-popup.html", 'One-time charge', '',
            ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
          )
%>

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

<SCRIPT TYPE="text/javascript">

function enable_quick_charge () {
  if (    document.QuickChargeForm.amount.value
       && document.QuickChargeForm.pkg.value    ) {
    document.QuickChargeForm.submit.disabled = false;
  } else {
    document.QuickChargeForm.submit.disabled = true;
  }
}

function 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*$/ ;
  var rval = true;

  if ( ! amount_regex.test(amount) ) {
    alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
    return false;
  }
  if ( String(pkg).length < 1 ) {
    rval = false;
  }
  if ( ! pkg_regex.test(pkg) ) {
    rval = false;
  }
  var i=0;
  for (i=0; i < rownum; i++) {
    if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
      rval = false;
      break;
    }
  }
  if (rval == true) {
    return true;
  }

  if ( ! pkg ) {
    alert('Enter a description for the one-time charge');
    return false;
  }

  alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
  return false;
}

</SCRIPT>

<FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">

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

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

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

% if ( $conf->exists('invoice-unitprice') ) {
    <TR>
      <TD ALIGN="right">Quantity </TD>
      <TD>
        <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
      </TD>
    </TR>
% }

<% include('/elements/tr-select-pkg_class.html', 'curr_value' => $cgi->param('classnum') ) %>


<TR>
  <TD ALIGN="right">Tax exempt </TD>
  <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
</TR>

<% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %>

<% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %>

<% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %>

<TR>
  <TD ALIGN="right">Description </TD>
  <TD>
    <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
  </TD>
</TR>

<TR>
  <TD></TD>
  <TD><FONT SIZE="-1">Optional additional description (also printed on invoice): </FONT></TD>
</TR>

% my $row = 0;
%   if ( $cgi->param('error') || $cgi->param('magic') ) {
%     my $param = $cgi->Vars;
%
% for ( $row = 0; exists($param->{"description$row"}); $row++ ) { 

    <TR>
      <TD></TD>
      <TD>
        <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
      </TD>
    </TR>
% } 
% } 


</TABLE>

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

</FORM>


<SCRIPT TYPE="text/javascript">

  var rownum = <% $row %>;

  function possiblyAddRow() {
    if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
      addRow();
    }
  }

  function addRow() {

    var table = document.getElementById('QuickChargeTable');
    var tablebody = table.getElementsByTagName('tbody').item(0);

    var row = document.createElement('TR');

    var empty_cell = document.createElement('TD');
    row.appendChild(empty_cell);

    var description_cell = document.createElement('TD');

      var description_input = document.createElement('INPUT');
      description_input.setAttribute('name', 'description'+rownum);
      description_input.setAttribute('id',   'description'+rownum);
      description_input.setAttribute('size', 60);
      description_input.setAttribute('maxLength', 65);
      description_input.setAttribute('rownum',   rownum);
      description_input.onkeyup = possiblyAddRow;
      description_cell.appendChild(description_input);

    row.appendChild(description_cell);

    tablebody.appendChild(row);

    rownum++;

  }

</SCRIPT>

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

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');

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;
}

my $quantity = 1;
if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
  $quantity = $1;
}

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

</%init>