soft-limit package names to 50 chars to avoid problems with typeset invoices, RT...
[freeside.git] / httemplate / edit / quick-charge.html
1 <% include("/elements/header-popup.html", 'One-time charge entry', '',
2             ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
3           )
4 %>
5
6 <% include('/elements/error.html') %>
7
8 <SCRIPT TYPE="text/javascript">
9
10 function enable_quick_charge () {
11   if (    document.QuickChargeForm.amount.value
12        && document.QuickChargeForm.pkg.value    ) {
13     document.QuickChargeForm.submit.disabled = false;
14   } else {
15     document.QuickChargeForm.submit.disabled = true;
16   }
17 }
18
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*$/ ;
24   var rval = true;
25
26   if ( ! amount_regex.test(amount) ) {
27     alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
28     return false;
29   }
30   if ( String(pkg).length < 1 ) {
31     rval = false;
32   }
33   if ( ! pkg_regex.test(pkg) ) {
34     rval = false;
35   }
36   var i=0;
37   for (i=0; i < rownum; i++) {
38     if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
39       rval = false;
40       break;
41     }
42   }
43   if (rval == true) {
44     return true;
45   }
46
47   if ( ! pkg ) {
48     alert('Enter a description for the one-time charge');
49     return false;
50   }
51
52   alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
53   return false;
54 }
55
56 </SCRIPT>
57
58 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
59
60 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
61
62 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
63
64 <TR>
65   <TD ALIGN="right">Amount: </TD>
66   <TD>
67     $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
68   </TD>
69 </TR>
70
71 % if ( $conf->exists('invoice-unitprice') ) {
72     <TR>
73       <TD ALIGN="right">Quantity: </TD>
74       <TD>
75         <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
76       </TD>
77     </TR>
78 % }
79
80 <% include('/elements/tr-select-pkg_class.html', 'curr_value' => $cgi->param('classnum') ) %>
81
82 <% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %>
83
84 <% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %>
85
86 <% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %>
87
88 <TR>
89   <TD>Description:</TD>
90   <TD>
91     <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
92   </TD>
93 </TR>
94
95 <TR>
96   <TD></TD>
97   <TD><FONT SIZE="-1">Optional additional description (also printed on invoice): </FONT></TD>
98 </TR>
99
100 % my $row = 0;
101 %   if ( $cgi->param('error') || $cgi->param('magic') ) {
102 %     my $param = $cgi->Vars;
103 %
104 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) { 
105
106     <TR>
107       <TD></TD>
108       <TD>
109         <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
110       </TD>
111     </TR>
112 % } 
113 % } 
114
115
116 </TABLE>
117
118 <BR>
119 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add one-time charge" <% $cgi->param('error') ? '' :' DISABLED' %>>
120
121 </FORM>
122
123
124 <SCRIPT TYPE="text/javascript">
125
126   var rownum = <% $row %>;
127
128   function possiblyAddRow() {
129     if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
130       addRow();
131     }
132   }
133
134   function addRow() {
135
136     var table = document.getElementById('QuickChargeTable');
137     var tablebody = table.getElementsByTagName('tbody').item(0);
138
139     var row = document.createElement('TR');
140
141     var empty_cell = document.createElement('TD');
142     row.appendChild(empty_cell);
143
144     var description_cell = document.createElement('TD');
145
146       var description_input = document.createElement('INPUT');
147       description_input.setAttribute('name', 'description'+rownum);
148       description_input.setAttribute('id',   'description'+rownum);
149       description_input.setAttribute('size', 60);
150       description_input.setAttribute('maxLength', 65);
151       description_input.setAttribute('rownum',   rownum);
152       description_input.onkeyup = possiblyAddRow;
153       description_cell.appendChild(description_input);
154
155     row.appendChild(description_cell);
156
157     tablebody.appendChild(row);
158
159     rownum++;
160
161   }
162
163 </SCRIPT>
164
165 </BODY>
166 </HTML>
167 <%init>
168
169 die "access denied"
170   unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
171
172 my $conf = new FS::Conf;
173
174 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
175 my $custnum = $1;
176
177 my $amount = '';
178 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
179   $amount = $1;
180 }
181
182 my $quantity = 1;
183 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
184   $quantity = $1;
185 }
186
187 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ 
188   or die 'illegal description';
189 my $pkg = $1;
190
191 </%init>