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