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