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">
109 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
110 % my $field = '/elements/tr-input-text.html';
111 % # don't allow changing these after the fact
112 % $field = '/elements/tr-fixed.html' if $billed;
116 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
118 prefix => $money_char,
121 % if ( $conf->exists('invoice-unitprice') ) {
125 value => $cust_pkg->quantity
129 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
131 % # crudely estimate whether any agent commission credits might exist
132 % my @events = grep { $_->part_event->action =~ /credit/ }
133 % $cust_pkg->cust_event;
134 % if ( scalar @events ) {
136 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
137 <% emt('Adjust commission credits if necessary') %>
142 % #display the future or past charge date, but don't allow changes
143 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
144 % # there's no compelling need yet
146 <& /elements/tr-fixed-date.html,
147 label => emt('Billed on'),
148 value => $cust_pkg->get('setup')
151 <& /elements/tr-input-date-field.html,
153 name => 'start_date',
154 label => emt('Will be billed'),
155 value => $cust_pkg->get('start_date'),
156 format => $date_format,
161 % } else { # new one-time charge
164 <TD ALIGN="right"><% mt('Amount') |h %> </TD>
166 <% $money_char %><INPUT TYPE = "text"
169 VALUE = "<% $amount %>"
170 onChange = "return enable_quick_charge(event)"
171 onKeyPress = "return enable_quick_charge(event)"
176 % if ( $conf->exists('invoice-unitprice') ) {
178 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
183 VALUE = "<% $quantity %>"
184 onKeyPress = "return enable_quick_charge(event)">
189 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
192 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
194 <INPUT TYPE = "checkbox"
197 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
198 onClick = "bill_now_changed(this);"
199 onChange = "bill_now_changed(this);"
201 <% mt('with terms') |h %>
202 <& /elements/select-terms.html,
203 'curr_value' => scalar($cgi->param('invoice_terms')),
204 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
205 'agentnum' => $cust_main->agentnum,
210 %# false laziness w/misc/order_pkg.html
212 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
217 ID = "start_date_text"
218 VALUE = "<% $start_date %>"
219 onKeyPress="return enable_quick_charge(event)"
220 <% $cgi->param('bill_now')
221 ? 'STYLE = "background-color:#dddddd" DISABLED'
225 <IMG SRC = "<%$fsurl%>images/calendar.png"
226 ID = "start_date_button"
227 TITLE = "<% mt('Select date') |h %>"
228 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
230 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
231 ID = "start_date_button_disabled"
232 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
234 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
238 <SCRIPT TYPE="text/javascript">
240 inputField: "start_date_text",
241 ifFormat: "<% $date_format %>",
242 button: "start_date_button",
247 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
248 % my $what = lc(FS::payby->shortname($cust_main->payby));
250 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
251 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
256 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
257 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
260 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass') &>
262 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') &>
264 <& /elements/tr-select-taxoverride.html, 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') &>
269 <TD ALIGN="right"><% mt('Description') |h %> </TD>
276 onChange = "return enable_quick_charge(event)"
277 onKeyPress = "return enable_quick_charge(event)"
284 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
288 % foreach (@description) {
293 NAME = "description<% $row %>"
296 VALUE = "<% $_ |h %>"
297 rownum = "<% $row %>"
298 onKeyPress = "return enable_quick_charge(event)"
299 onKeyUp = "return possiblyAddRow(event)"
310 % my $label = $cust_pkg
311 % ? emt('Modify one-time charge')
312 % : emt('Add one-time charge');
313 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
314 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
319 <SCRIPT TYPE="text/javascript">
321 var rownum = <% $row %>;
323 function possiblyAddRow(e) {
325 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
329 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
333 key = window.event.keyCode; //IE
335 key = e.which; //firefox, others
347 var table = document.getElementById('QuickChargeTable');
348 var tablebody = table.getElementsByTagName('tbody').item(0);
350 var row = document.createElement('TR');
352 var empty_cell = document.createElement('TD');
353 row.appendChild(empty_cell);
355 var description_cell = document.createElement('TD');
357 //var description_input = document.createElement('INPUT');
358 var di = document.createElement('INPUT');
359 di.setAttribute('name', 'description'+rownum);
360 di.setAttribute('id', 'description'+rownum);
361 di.setAttribute('size', 60);
362 di.setAttribute('maxLength', 65);
363 di.setAttribute('rownum', rownum);
364 di.onkeyup = possiblyAddRow;
365 di.onkeypress = enable_quick_charge;
366 description_cell.appendChild(di);
368 row.appendChild(description_cell);
370 tablebody.appendChild(row);
382 my $curuser = $FS::CurrentUser::CurrentUser;
385 unless $curuser->access_right('One-time charge');
387 my $conf = new FS::Conf;
388 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
389 my $money_char = $conf->config('money_char') || '$';
391 my ($cust_main, $cust_pkg);
392 if ( $cgi->param('change_pkgnum') ) {
393 # change an existing one-time charge
395 unless $curuser->access_right('Modify one-time charge');
397 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
398 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
399 $cust_main = $cust_pkg->cust_main;
401 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
402 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
405 my $custnum = $cust_main->custnum;
407 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
408 die "custnum $custnum not found";
411 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
412 my $start_date = $cust_main->next_bill_date;
413 $start_date = $start_date ? time2str($format, $start_date) : '';
416 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
421 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
425 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
426 or die 'illegal description';
430 if ( $cust_main->invoice_terms ) {
431 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
434 emt( "Default ([_1])",
435 ( $conf->config('invoice_default_terms', $cust_main->agentnum)
436 || emt('Payable upon receipt')
442 my %param = $cgi->Vars;
443 for (my $i = 0; exists($param{"description$i"}); $i++) {
444 push @description, $param{"description$i"};
448 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
454 if ( $cust_pkg ) { # set defaults
455 $part_pkg = $cust_pkg->part_pkg;
456 $pkg ||= $part_pkg->pkg;
457 $classnum ||= $part_pkg->classnum;
459 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
461 push @description, $part_pkg->option("additional_info$i",1);
466 my $billed = ($cust_pkg and $cust_pkg->get('setup')) ? 1 : 0;