1 <% include("/elements/header-popup.html", 'One-time charge', '',
2 ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
6 <LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
7 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
8 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
9 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
11 <% include('/elements/error.html') %>
13 <SCRIPT TYPE="text/javascript">
15 function enable_quick_charge () {
16 if ( document.QuickChargeForm.amount.value
17 && document.QuickChargeForm.pkg.value ) {
18 document.QuickChargeForm.submit.disabled = false;
20 document.QuickChargeForm.submit.disabled = true;
24 function validate_quick_charge () {
25 var pkg = document.QuickChargeForm.pkg.value;
26 var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
27 var amount = document.QuickChargeForm.amount.value;
28 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
31 if ( ! amount_regex.test(amount) ) {
32 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
35 if ( String(pkg).length < 1 ) {
38 if ( ! pkg_regex.test(pkg) ) {
42 for (i=0; i < rownum; i++) {
43 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
53 alert('Enter a description for the one-time charge');
57 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
61 function bill_now_changed (what) {
64 form.start_date_text.disabled = true;
65 form.start_date.style.backgroundColor = '#dddddd';
66 form.start_date_button.style.display = 'none';
67 form.start_date_button_disabled.style.display = '';
68 form.invoice_terms.disabled = false;
70 form.start_date_text.disabled = false;
71 form.start_date.style.backgroundColor = '#ffffff';
72 form.start_date_button.style.display = '';
73 form.start_date_button_disabled.style.display = 'none';
74 form.invoice_terms.disabled = true;
80 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
82 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
84 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
87 <TD ALIGN="right">Amount </TD>
89 $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
93 % if ( $conf->exists('invoice-unitprice') ) {
95 <TD ALIGN="right">Quantity </TD>
97 <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
102 <% include('/elements/tr-select-pkg_class.html', 'curr_value' => $cgi->param('classnum') ) %>
105 <TD ALIGN="right">Invoice now</TD>
107 <INPUT TYPE = "checkbox"
110 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
111 onChange = "bill_now_changed(this);"
114 <% include('/elements/select-terms.html',
115 'curr_value' => scalar($cgi->param('invoice_terms')),
116 'empty_value' => $default_terms,
117 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
123 %# false laziness w/misc/order_pkg.html
125 <TD ALIGN="right">Charge date </TD>
130 ID = "start_date_text"
131 VALUE = "<% $start_date %>"
132 <% $cgi->param('bill_now') ? 'STYLE = "background-color:#dddddd" DISABLED' : '' %>
134 <IMG SRC = "<%$fsurl%>images/calendar.png"
135 ID = "start_date_button"
136 TITLE = "Select date"
137 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
139 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
140 ID = "start_date_button_disabled"
141 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
143 <FONT SIZE=-1>(leave blank to charge immediately)</FONT>
147 <SCRIPT TYPE="text/javascript">
149 inputField: "start_date_text",
150 ifFormat: "%m/%d/%Y",
151 button: "start_date_button",
158 <TD ALIGN="right">Tax exempt </TD>
159 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
162 <% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %>
164 <% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %>
166 <% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %>
169 <TD ALIGN="right">Description </TD>
171 <INPUT TYPE="text" NAME="pkg" SIZE="50" MAXLENGTH="50" VALUE="<% $pkg %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge()">
177 <TD><FONT SIZE="-1">Optional additional description (also printed on invoice): </FONT></TD>
181 % if ( $cgi->param('error') || $cgi->param('magic') ) {
182 % my $param = $cgi->Vars;
184 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) {
189 <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} |h %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
199 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add one-time charge" <% $cgi->param('error') ? '' :' DISABLED' %>>
204 <SCRIPT TYPE="text/javascript">
206 var rownum = <% $row %>;
208 function possiblyAddRow() {
209 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
216 var table = document.getElementById('QuickChargeTable');
217 var tablebody = table.getElementsByTagName('tbody').item(0);
219 var row = document.createElement('TR');
221 var empty_cell = document.createElement('TD');
222 row.appendChild(empty_cell);
224 var description_cell = document.createElement('TD');
226 var description_input = document.createElement('INPUT');
227 description_input.setAttribute('name', 'description'+rownum);
228 description_input.setAttribute('id', 'description'+rownum);
229 description_input.setAttribute('size', 60);
230 description_input.setAttribute('maxLength', 65);
231 description_input.setAttribute('rownum', rownum);
232 description_input.onkeyup = possiblyAddRow;
233 description_cell.appendChild(description_input);
235 row.appendChild(description_cell);
237 tablebody.appendChild(row);
250 unless $FS::CurrentUser::CurrentUser->access_right('One-time charge');
252 my $conf = new FS::Conf;
254 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
256 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); #XXX agent-virt
258 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
259 my $start_date = $cust_main->next_bill_date;
260 $start_date = $start_date ? time2str($format, $start_date) : '';
263 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
268 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
272 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
273 or die 'illegal description';
277 if ( $cust_main->invoice_terms ) {
278 $default_terms = 'Customer default ('. $cust_main->invoice_terms. ')';
282 ($conf->config('invoice_default_terms') || 'Payable upon receipt').