1 <& /elements/header-popup.html, mt('One-time charge'), '',
2 ( ($quotationnum || $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>
9 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/xregexp-all.js"></SCRIPT>
11 <& /elements/error.html &>
13 <SCRIPT TYPE="text/javascript">
15 function enable_quick_charge (e) {
17 if ( document.QuickChargeForm.amount.value
18 && document.QuickChargeForm.pkg.value ) {
19 document.QuickChargeForm.submit.disabled = false;
21 document.QuickChargeForm.submit.disabled = true;
24 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
28 key = window.event.keyCode; //IE
31 key = e.which; //firefox, others
41 function validate_quick_charge () {
42 var pkg = document.QuickChargeForm.pkg.value;
43 var pkg_regex = XRegExp('^([\\p{L}\\p{N} \_\!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\\[\\]]*)$');
44 var amount = document.QuickChargeForm.amount.value;
45 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
48 if ( ! amount_regex.test(amount) ) {
49 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
52 if ( String(pkg).length < 1 ) {
55 if ( ! pkg_regex.test(pkg) ) {
59 for (i=0; i < rownum; i++) {
60 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
70 alert('Enter a description for the one-time charge');
74 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
78 function bill_now_changed (what) {
81 form.start_date_text.disabled = true;
82 form.start_date.style.backgroundColor = '#dddddd';
83 form.start_date_button.style.display = 'none';
84 form.start_date_button_disabled.style.display = '';
85 form.invoice_terms.disabled = false;
87 form.start_date_text.disabled = false;
88 form.start_date.style.backgroundColor = '#ffffff';
89 form.start_date_button.style.display = '';
90 form.start_date_button_disabled.style.display = 'none';
91 form.invoice_terms.disabled = true;
97 <FORM ACTION = "process/quick-charge.cgi"
98 NAME = "QuickChargeForm"
99 ID = "QuickChargeForm"
101 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
104 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
105 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
106 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
108 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
110 % if ( $cust_pkg ) { #modify one-time charge
112 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
113 % my $field = '/elements/tr-input-text.html';
114 % # don't allow changing these after the fact
115 % $field = '/elements/tr-fixed.html' if $billed;
117 label => mt('Amount to charge'),
119 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
121 prefix => $money_char,
124 % if ( $curuser->access_right('Edit package definition costs') ) {
127 field => 'setup_cost',
128 value => sprintf('%.2f',$part_pkg->setup_cost),
130 prefix => $money_char,
134 % if ( $conf->exists('invoice-unitprice') ) {
138 value => $cust_pkg->quantity
142 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
144 % # crudely estimate whether any agent commission credits might exist
145 % my @events = grep { $_->part_event->action =~ /credit/ }
146 % $cust_pkg->cust_event;
147 % if ( scalar @events ) {
149 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
150 <% emt('Adjust commission credits if necessary') %>
155 % #display the future or past charge date, but don't allow changes
156 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
157 % # there's no compelling need yet
159 <& /elements/tr-fixed-date.html,
160 label => emt('Billed on'),
161 value => $cust_pkg->get('setup')
164 <& /elements/tr-input-date-field.html,
166 name => 'start_date',
167 label => emt('Will be billed'),
168 value => $cust_pkg->get('start_date'),
169 format => $date_format,
174 <& /elements/tr-checkbox.html,
175 label => emt('Invoice this charge separately'),
176 field => 'separate_bill',
178 curr_value => $cust_pkg->get('separate_bill'),
181 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
182 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
185 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
187 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $part_pkg->get('taxproductnum') &>
190 % } else { # new one-time charge
193 <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
195 <% $money_char %><INPUT TYPE = "text"
198 VALUE = "<% $amount %>"
199 onChange = "return enable_quick_charge(event)"
200 onKeyPress = "return enable_quick_charge(event)"
205 % if ( $curuser->access_right('Edit package definition costs') ) {
206 <& /elements/tr-input-text.html,
208 field => 'setup_cost',
209 value => $setup_cost,
211 prefix => $money_char,
215 % if ( $conf->exists('invoice-unitprice') ) {
217 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
222 VALUE = "<% $quantity %>"
223 onKeyPress = "return enable_quick_charge(event)">
228 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
230 % unless ( $quotationnum ) {
233 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
235 <INPUT TYPE = "checkbox"
238 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
239 onClick = "bill_now_changed(this);"
240 onChange = "bill_now_changed(this);"
242 <% mt('with terms') |h %>
243 <& /elements/select-terms.html,
244 'curr_value' => scalar($cgi->param('invoice_terms')),
245 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
246 'agentnum' => $cust_or_prospect->agentnum,
251 % # false laziness w/misc/order_pkg.html
253 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
258 ID = "start_date_text"
259 VALUE = "<% $start_date %>"
260 onKeyPress="return enable_quick_charge(event)"
261 <% $cgi->param('bill_now')
262 ? 'STYLE = "background-color:#dddddd" DISABLED'
266 <IMG SRC = "<%$fsurl%>images/calendar.png"
267 ID = "start_date_button"
268 TITLE = "<% mt('Select date') |h %>"
269 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
271 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
272 ID = "start_date_button_disabled"
273 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
275 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
279 <SCRIPT TYPE="text/javascript">
281 inputField: "start_date_text",
282 ifFormat: "<% $date_format %>",
283 button: "start_date_button",
288 <& /elements/tr-checkbox.html,
289 label => emt('Invoice this charge separately'),
290 field => 'separate_bill',
296 % if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
297 % my $what = lc(FS::payby->shortname($cust_main->payby));
299 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
300 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
305 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
306 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
309 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass') &>
311 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') &>
313 <& /elements/tr-select-taxoverride.html, 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') &>
318 <TD ALIGN="right"><% mt('Description') |h %> </TD>
325 onChange = "return enable_quick_charge(event)"
326 onKeyPress = "return enable_quick_charge(event)"
332 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
333 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
334 % unless ($quotationnum) {
337 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
340 % foreach (@description) {
345 NAME = "description<% $row %>"
348 VALUE = "<% $_ |h %>"
349 rownum = "<% $row %>"
350 onKeyPress = "return enable_quick_charge(event)"
351 onKeyUp = "return possiblyAddRow(event)"
363 % my $label = $cust_pkg
364 % ? emt('Modify one-time charge')
365 % : emt('Add one-time charge');
366 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
367 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
372 <SCRIPT TYPE="text/javascript">
374 var rownum = <% $row %>;
376 function possiblyAddRow(e) {
378 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
382 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
386 key = window.event.keyCode; //IE
388 key = e.which; //firefox, others
400 var table = document.getElementById('QuickChargeTable');
401 var tablebody = table.getElementsByTagName('tbody').item(0);
403 var row = document.createElement('TR');
405 var empty_cell = document.createElement('TD');
406 row.appendChild(empty_cell);
408 var description_cell = document.createElement('TD');
410 //var description_input = document.createElement('INPUT');
411 var di = document.createElement('INPUT');
412 di.setAttribute('name', 'description'+rownum);
413 di.setAttribute('id', 'description'+rownum);
414 di.setAttribute('size', 60);
415 di.setAttribute('maxLength', 65);
416 di.setAttribute('rownum', rownum);
417 di.onkeyup = possiblyAddRow;
418 di.onkeypress = enable_quick_charge;
419 description_cell.appendChild(di);
421 row.appendChild(description_cell);
423 tablebody.appendChild(row);
435 my $curuser = $FS::CurrentUser::CurrentUser;
438 unless $curuser->access_right('One-time charge');
440 my $conf = new FS::Conf;
441 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
442 my $money_char = $conf->config('money_char') || '$';
444 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
445 if ( $cgi->param('change_pkgnum') ) {
446 # change an existing one-time charge
448 unless $curuser->access_right('Modify one-time charge');
450 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
451 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
452 $cust_main = $cust_pkg->cust_main;
454 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
457 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
458 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
460 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
461 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
463 die "custnum or prospectnum must be specified"
464 unless $cust_main || $prospect_main;
467 my $cust_or_prospect = $cust_main || $prospect_main;
470 my $custnum = $cust_main->custnum;
472 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
473 die "custnum $custnum not found";
475 } elsif ( $prospect_main ) {
476 my $prospectnum = $prospect_main->prospectnum;
478 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
479 die "prospectnum $prospectnum not found";
483 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
484 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
485 $start_date = $start_date ? time2str($format, $start_date) : '';
488 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
493 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
498 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
502 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
503 or die 'illegal description';
507 if ( $cust_main && $cust_main->invoice_terms ) {
508 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
511 emt( "Default ([_1])",
512 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
513 || emt('Payable upon receipt')
519 my %param = $cgi->Vars;
520 for (my $i = 0; exists($param{"description$i"}); $i++) {
521 push @description, $param{"description$i"};
525 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
531 if ( $cust_pkg ) { # set defaults
532 $part_pkg = $cust_pkg->part_pkg;
533 $pkg ||= $part_pkg->pkg;
534 $classnum ||= $part_pkg->classnum;
536 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
538 push @description, $part_pkg->option("additional_info$i",1);
543 my $billed = ($cust_pkg and $cust_pkg->get('setup')) ? 1 : 0;