optimize CDR rating after timed rate perf regression, RT#15739
[freeside.git] / httemplate / edit / quick-charge.html
1 <& /elements/header-popup.html, mt('One-time charge'), '',
2             ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
3 &>
4
5 <LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
6 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
7 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
8 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
9
10 <& /elements/error.html &>
11
12 <SCRIPT TYPE="text/javascript">
13
14 function enable_quick_charge () {
15   if (    document.QuickChargeForm.amount.value
16        && document.QuickChargeForm.pkg.value    ) {
17     document.QuickChargeForm.submit.disabled = false;
18   } else {
19     document.QuickChargeForm.submit.disabled = true;
20   }
21 }
22
23 function validate_quick_charge () {
24   var pkg = document.QuickChargeForm.pkg.value;
25   var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
26   var amount = document.QuickChargeForm.amount.value;
27   var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
28   var rval = true;
29
30   if ( ! amount_regex.test(amount) ) {
31     alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
32     return false;
33   }
34   if ( String(pkg).length < 1 ) {
35     rval = false;
36   }
37   if ( ! pkg_regex.test(pkg) ) {
38     rval = false;
39   }
40   var i=0;
41   for (i=0; i < rownum; i++) {
42     if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
43       rval = false;
44       break;
45     }
46   }
47   if (rval == true) {
48     return true;
49   }
50
51   if ( ! pkg ) {
52     alert('Enter a description for the one-time charge');
53     return false;
54   }
55
56   alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
57   return false;
58 }
59
60 function bill_now_changed (what) {
61   var form = what.form;
62   if ( what.checked ) {
63     form.start_date_text.disabled = true;
64     form.start_date.style.backgroundColor = '#dddddd';
65     form.start_date_button.style.display = 'none';
66     form.start_date_button_disabled.style.display = '';
67     form.invoice_terms.disabled = false;
68   } else {
69     form.start_date_text.disabled = false;
70     form.start_date.style.backgroundColor = '#ffffff';
71     form.start_date_button.style.display = '';
72     form.start_date_button_disabled.style.display = 'none';
73     form.invoice_terms.disabled = true;
74   }
75 }
76
77 </SCRIPT>
78
79 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
80
81 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
82
83 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
84
85 <TR>
86   <TD ALIGN="right"><% mt('Amount') |h %> </TD>
87   <TD>
88     <% $money_char %><INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
89   </TD>
90 </TR>
91
92 % if ( $conf->exists('invoice-unitprice') ) {
93     <TR>
94       <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
95       <TD>
96         <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
97       </TD>
98     </TR>
99 % }
100
101 <& /elements/tr-select-pkg_class.html, 'curr_value' => $cgi->param('classnum')  &>
102
103 <TR>
104   <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
105   <TD>
106     <INPUT TYPE  = "checkbox"
107            NAME  = "bill_now"
108            VALUE = "1"
109            <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
110            onChange = "bill_now_changed(this);"
111     >
112     <% mt('with terms') |h %> 
113     <& /elements/select-terms.html,
114                  'curr_value'  => scalar($cgi->param('invoice_terms')),
115                  'empty_value' => $default_terms,
116                  'disabled'    => ( $cgi->param('bill_now') ? 0 : 1 ),
117     &>
118   </TD>
119 </TR>
120
121 %# false laziness w/misc/order_pkg.html
122 <TR>
123   <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
124   <TD>
125     <INPUT TYPE  = "text"
126            NAME  = "start_date"
127            SIZE  = 32
128            ID    = "start_date_text"
129            VALUE = "<% $start_date %>"
130            <% $cgi->param('bill_now') ? 'STYLE = "background-color:#dddddd" DISABLED' : '' %>
131     >
132     <IMG SRC   = "<%$fsurl%>images/calendar.png"
133          ID    = "start_date_button"
134          TITLE = "<% mt('Select date') |h %>"
135          STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
136     >
137     <IMG SRC   = "<%$fsurl%>images/calendar-disabled.png"
138          ID    = "start_date_button_disabled"
139          <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
140     >
141     <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
142   </TD>
143 </TR>
144
145 <SCRIPT TYPE="text/javascript">
146   Calendar.setup({
147     inputField: "start_date_text",
148     ifFormat:   "<% $date_format %>",
149     button:     "start_date_button",
150     align:      "BR"
151   });
152 </SCRIPT>
153
154 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
155 %   my $what = lc(FS::payby->shortname($cust_main->payby));
156     <TR>
157       <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
158       <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
159     </TR>
160 % }
161
162 <TR>
163   <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
164   <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
165 </TR>
166
167 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass')  &>
168
169 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum')  &>
170
171 <& /elements/tr-select-taxoverride.html, 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override')  &>
172
173 <TR>
174   <TD ALIGN="right"><% mt('Description') |h %> </TD>
175   <TD>
176     <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
177   </TD>
178 </TR>
179
180 <TR>
181   <TD></TD>
182   <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
183 </TR>
184
185 % my $row = 0;
186 %   if ( $cgi->param('error') || $cgi->param('magic') ) {
187 %     my $param = $cgi->Vars;
188 %
189 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) { 
190
191     <TR>
192       <TD></TD>
193       <TD>
194         <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
195       </TD>
196     </TR>
197 % } 
198 % } 
199
200
201 </TABLE>
202
203 <BR>
204 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% mt('Add one-time charge') |h %>" <% $cgi->param('error') ? '' :' DISABLED' %>>
205
206 </FORM>
207
208
209 <SCRIPT TYPE="text/javascript">
210
211   var rownum = <% $row %>;
212
213   function possiblyAddRow() {
214     if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
215       addRow();
216     }
217   }
218
219   function addRow() {
220
221     var table = document.getElementById('QuickChargeTable');
222     var tablebody = table.getElementsByTagName('tbody').item(0);
223
224     var row = document.createElement('TR');
225
226     var empty_cell = document.createElement('TD');
227     row.appendChild(empty_cell);
228
229     var description_cell = document.createElement('TD');
230
231       var description_input = document.createElement('INPUT');
232       description_input.setAttribute('name', 'description'+rownum);
233       description_input.setAttribute('id',   'description'+rownum);
234       description_input.setAttribute('size', 60);
235       description_input.setAttribute('maxLength', 65);
236       description_input.setAttribute('rownum',   rownum);
237       description_input.onkeyup = possiblyAddRow;
238       description_cell.appendChild(description_input);
239
240     row.appendChild(description_cell);
241
242     tablebody.appendChild(row);
243
244     rownum++;
245
246   }
247
248 </SCRIPT>
249
250 </BODY>
251 </HTML>
252 <%init>
253
254 die "access denied"
255   unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
256
257 my $conf = new FS::Conf;
258 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
259 my $money_char = $conf->config('money_char') || '$';
260
261 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
262 my $custnum = $1;
263 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); #XXX agent-virt
264
265 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
266 my $start_date = $cust_main->next_bill_date;
267 $start_date = $start_date ? time2str($format, $start_date) : '';
268
269 my $amount = '';
270 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
271   $amount = $1;
272 }
273
274 my $quantity = 1;
275 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
276   $quantity = $1;
277 }
278
279 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ 
280   or die 'illegal description';
281 my $pkg = $1;
282
283 my $default_terms;
284 if ( $cust_main->invoice_terms ) {
285   $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
286 } else {
287   $default_terms = emt("Default ([_1])",
288             ($conf->config('invoice_default_terms') || emt('Payable upon receipt'))
289                       );
290 }
291
292 </%init>