1 <% include("/elements/header-popup.html", 'One-time charge', '',
2 ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
6 <% include('/elements/error.html') %>
8 <SCRIPT TYPE="text/javascript">
10 function enable_quick_charge () {
11 if ( document.QuickChargeForm.amount.value
12 && document.QuickChargeForm.pkg.value ) {
13 document.QuickChargeForm.submit.disabled = false;
15 document.QuickChargeForm.submit.disabled = true;
19 function validate_quick_charge () {
20 var pkg = document.QuickChargeForm.pkg.value;
21 var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
22 var amount = document.QuickChargeForm.amount.value;
23 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
26 if ( ! amount_regex.test(amount) ) {
27 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
30 if ( String(pkg).length < 1 ) {
33 if ( ! pkg_regex.test(pkg) ) {
37 for (i=0; i < rownum; i++) {
38 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
48 alert('Enter a description for the one-time charge');
52 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
58 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
60 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
62 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
65 <TD ALIGN="right">Amount </TD>
67 $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
71 % if ( $conf->exists('invoice-unitprice') ) {
73 <TD ALIGN="right">Quantity </TD>
75 <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
80 <% include('/elements/tr-select-pkg_class.html', 'curr_value' => $cgi->param('classnum') ) %>
84 <TD ALIGN="right">Tax exempt </TD>
85 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
88 <% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %>
90 <% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %>
92 <% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %>
95 <TD ALIGN="right">Description </TD>
97 <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
103 <TD><FONT SIZE="-1">Optional additional description (also printed on invoice): </FONT></TD>
107 % if ( $cgi->param('error') || $cgi->param('magic') ) {
108 % my $param = $cgi->Vars;
110 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) {
115 <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
125 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add one-time charge" <% $cgi->param('error') ? '' :' DISABLED' %>>
130 <SCRIPT TYPE="text/javascript">
132 var rownum = <% $row %>;
134 function possiblyAddRow() {
135 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
142 var table = document.getElementById('QuickChargeTable');
143 var tablebody = table.getElementsByTagName('tbody').item(0);
145 var row = document.createElement('TR');
147 var empty_cell = document.createElement('TD');
148 row.appendChild(empty_cell);
150 var description_cell = document.createElement('TD');
152 var description_input = document.createElement('INPUT');
153 description_input.setAttribute('name', 'description'+rownum);
154 description_input.setAttribute('id', 'description'+rownum);
155 description_input.setAttribute('size', 60);
156 description_input.setAttribute('maxLength', 65);
157 description_input.setAttribute('rownum', rownum);
158 description_input.onkeyup = possiblyAddRow;
159 description_cell.appendChild(description_input);
161 row.appendChild(description_cell);
163 tablebody.appendChild(row);
176 unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
178 my $conf = new FS::Conf;
180 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
184 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
189 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
193 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
194 or die 'illegal description';