1 <& /elements/header-popup.html, mt('One-time charge'), '',
2 ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
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>
10 <& /elements/error.html &>
12 <SCRIPT TYPE="text/javascript">
14 function enable_quick_charge (e) {
16 if ( document.QuickChargeForm.amount.value
17 && document.QuickChargeForm.pkg.value ) {
18 document.QuickChargeForm.submit.disabled = false;
20 document.QuickChargeForm.submit.disabled = true;
23 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
27 key = window.event.keyCode; //IE
30 key = e.which; //firefox, others
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*$/ ;
47 if ( ! amount_regex.test(amount) ) {
48 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
51 if ( String(pkg).length < 1 ) {
54 if ( ! pkg_regex.test(pkg) ) {
58 for (i=0; i < rownum; i++) {
59 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
69 alert('Enter a description for the one-time charge');
73 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
77 function bill_now_changed (what) {
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;
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;
96 <FORM ACTION = "process/quick-charge.cgi"
97 NAME = "QuickChargeForm"
98 ID = "QuickChargeForm"
100 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
103 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
105 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
108 <TD ALIGN="right"><% mt('Amount') |h %> </TD>
110 <% $money_char %><INPUT TYPE = "text"
113 VALUE = "<% $amount %>"
114 onChange = "return enable_quick_charge(event)"
115 onKeyPress = "return enable_quick_charge(event)"
120 % if ( $conf->exists('invoice-unitprice') ) {
122 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
127 VALUE = "<% $quantity %>"
128 onKeyPress = "return enable_quick_charge(event)">
133 <& /elements/tr-select-pkg_class.html, 'curr_value' => $cgi->param('classnum') &>
136 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
138 <INPUT TYPE = "checkbox"
141 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
142 onClick = "bill_now_changed(this);"
143 onChange = "bill_now_changed(this);"
145 <% mt('with terms') |h %>
146 <& /elements/select-terms.html,
147 'curr_value' => scalar($cgi->param('invoice_terms')),
148 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
153 %# false laziness w/misc/order_pkg.html
155 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
160 ID = "start_date_text"
161 VALUE = "<% $start_date %>"
162 onKeyPress="return enable_quick_charge(event)"
163 <% $cgi->param('bill_now')
164 ? 'STYLE = "background-color:#dddddd" DISABLED'
168 <IMG SRC = "<%$fsurl%>images/calendar.png"
169 ID = "start_date_button"
170 TITLE = "<% mt('Select date') |h %>"
171 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
173 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
174 ID = "start_date_button_disabled"
175 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
177 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
181 <SCRIPT TYPE="text/javascript">
183 inputField: "start_date_text",
184 ifFormat: "<% $date_format %>",
185 button: "start_date_button",
190 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
191 % my $what = lc(FS::payby->shortname($cust_main->payby));
193 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
194 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
199 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
200 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
203 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass') &>
205 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') &>
207 <& /elements/tr-select-taxoverride.html, 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') &>
210 <TD ALIGN="right"><% mt('Description') |h %> </TD>
217 onChange = "return enable_quick_charge(event)"
218 onKeyPress = "return enable_quick_charge(event)"
225 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
229 % if ( $cgi->param('error') || $cgi->param('magic') ) {
230 % my $param = $cgi->Vars;
232 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) {
238 NAME = "description<% $row %>"
241 VALUE = "<% $param->{"description$row"} |h %>"
242 rownum = "<% $row %>"
243 onKeyPress = "return enable_quick_charge(event)"
244 onKeyUp = "return possiblyAddRow(event)"
255 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% mt('Add one-time charge') |h %>" <% $cgi->param('error') ? '' :' DISABLED' %>>
260 <SCRIPT TYPE="text/javascript">
262 var rownum = <% $row %>;
264 function possiblyAddRow(e) {
266 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
270 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
274 key = window.event.keyCode; //IE
276 key = e.which; //firefox, others
288 var table = document.getElementById('QuickChargeTable');
289 var tablebody = table.getElementsByTagName('tbody').item(0);
291 var row = document.createElement('TR');
293 var empty_cell = document.createElement('TD');
294 row.appendChild(empty_cell);
296 var description_cell = document.createElement('TD');
298 //var description_input = document.createElement('INPUT');
299 var di = document.createElement('INPUT');
300 di.setAttribute('name', 'description'+rownum);
301 di.setAttribute('id', 'description'+rownum);
302 di.setAttribute('size', 60);
303 di.setAttribute('maxLength', 65);
304 di.setAttribute('rownum', rownum);
305 di.onkeyup = possiblyAddRow;
306 di.onkeypress = enable_quick_charge;
307 description_cell.appendChild(di);
309 row.appendChild(description_cell);
311 tablebody.appendChild(row);
323 my $curuser = $FS::CurrentUser::CurrentUser;
326 unless $curuser->access_right('One-time charge');
328 my $conf = new FS::Conf;
329 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
330 my $money_char = $conf->config('money_char') || '$';
332 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
334 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); #XXX agent-virt
336 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
337 my $start_date = $cust_main->next_bill_date;
338 $start_date = $start_date ? time2str($format, $start_date) : '';
341 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
346 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
350 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
351 or die 'illegal description';
355 if ( $cust_main->invoice_terms ) {
356 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
358 $default_terms = emt("Default ([_1])",
359 ($conf->config('invoice_default_terms') || emt('Payable upon receipt'))