1 % if ( $quotationnum && ! $cust_main ) {
2 <& /elements/header.html, mt('Quotation #[_1]: add one-time charge', $quotationnum) &>
4 <& /elements/header-cust_main.html,
5 view => $quotationnum ? 'quotations' : 'packages',
6 cust_main => $cust_main,
7 etc => $cgi->param('error') ? '' : 'onload="addRow()"',
10 ? emt('Quotation #[_1]: add one-time charge', $quotationnum)
11 : mt('One-time charge')
15 <& /elements/init_calendar.html &>
16 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/xregexp-all.js"></SCRIPT>
18 <& /elements/error.html &>
20 <SCRIPT TYPE="text/javascript">
22 function enable_quick_charge (e) {
24 if ( document.QuickChargeForm.amount.value
25 && document.QuickChargeForm.pkg.value ) {
26 document.QuickChargeForm.submit.disabled = false;
28 document.QuickChargeForm.submit.disabled = true;
31 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
35 key = window.event.keyCode; //IE
38 key = e.which; //firefox, others
48 function validate_quick_charge () {
49 var pkg = document.QuickChargeForm.pkg.value;
50 var pkg_regex = XRegExp('^([\\p{L}\\p{N} \_\!\@\#\$\%\&\(\)\+\;\:\'\"\,\.\?\/\=\\-\\[\\]]*)$');
51 var amount = document.QuickChargeForm.amount.value;
52 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
55 if ( ! amount_regex.test(amount) ) {
56 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
59 if ( String(pkg).length < 1 ) {
62 if ( ! pkg_regex.test(pkg) ) {
66 for (i=0; i < rownum; i++) {
67 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
77 alert('Enter a description for the one-time charge');
81 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
85 function bill_now_changed (what) {
88 form.start_date_text.disabled = true;
89 form.start_date.style.backgroundColor = '#dddddd';
90 form.start_date_button.style.display = 'none';
91 form.start_date_button_disabled.style.display = '';
92 form.invoice_terms.disabled = false;
94 form.start_date_text.disabled = false;
95 form.start_date.style.backgroundColor = '#ffffff';
96 form.start_date_button.style.display = '';
97 form.start_date_button_disabled.style.display = 'none';
98 form.invoice_terms.disabled = true;
105 % if ( $prospect_main ) {
106 <& /elements/small_prospect_view.html, $prospect_main &>
110 <FORM ACTION = "process/quick-charge.cgi"
111 NAME = "QuickChargeForm"
112 ID = "QuickChargeForm"
114 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
117 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
118 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
119 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
123 <FONT CLASS="fsinnerbox-title"><% mt('Charge') |h %>
124 <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
126 % if ( $cust_pkg ) { #modify one-time charge
128 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
129 % my $field = '/elements/tr-input-text.html';
130 % # don't allow changing these after the fact
131 % $field = '/elements/tr-fixed.html' if $billed;
133 label => mt('Amount to charge'),
135 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
137 prefix => $money_char,
140 % if ( $curuser->access_right('Edit package definition costs') ) {
143 field => 'setup_cost',
144 value => sprintf('%.2f',$part_pkg->setup_cost),
146 prefix => $money_char,
150 % if ( $conf->exists('invoice-unitprice') ) {
154 value => $cust_pkg->quantity
158 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
160 % # crudely estimate whether any agent commission credits might exist
161 % my @events = grep { $_->part_event->action =~ /credit/ }
162 % $cust_pkg->cust_event;
163 % if ( scalar @events ) {
165 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
166 <% emt('Adjust commission credits if necessary') %>
171 % #display the future or past charge date, but don't allow changes
172 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
173 % # there's no compelling need yet
175 <& /elements/tr-fixed-date.html,
176 label => emt('Billed on'),
177 value => $cust_pkg->get('setup')
180 <& /elements/tr-input-date-field.html,
182 name => 'start_date',
183 label => emt('Will be billed'),
184 value => $cust_pkg->get('start_date'),
185 format => $date_format,
190 <& /elements/tr-checkbox.html,
191 label => emt('Invoice this charge separately'),
192 field => 'separate_bill',
194 curr_value => $cust_pkg->get('separate_bill'),
197 <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
198 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
201 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
203 <& /elements/tr-select-taxproduct.html,
204 'label' => emt('Tax product'),
205 'curr_value' => $part_pkg->get('taxproductnum')
212 % } else { # new one-time charge
215 <TH ALIGN="right"><% mt('Amount to charge') |h %> </TH>
217 <% $money_char %><INPUT TYPE = "text"
220 VALUE = "<% $amount %>"
221 onChange = "return enable_quick_charge(event)"
222 onKeyPress = "return enable_quick_charge(event)"
227 % if ( $conf->exists('invoice-unitprice') ) {
229 <TH ALIGN="right"><% mt('Quantity') |h %> </TH>
234 VALUE = "<% $quantity %>"
235 onKeyPress = "return enable_quick_charge(event)">
240 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
243 <TH ALIGN="right"><% mt('Description') |h %> </TH>
250 onChange = "return enable_quick_charge(event)"
251 onKeyPress = "return enable_quick_charge(event)"
257 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
258 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
259 % unless ($quotationnum) {
262 <TH ALIGN="left"><% mt('Optional additional description (also printed on invoice):') |h %></TH>
265 % foreach (@description) {
270 NAME = "description<% $row %>"
273 VALUE = "<% $_ |h %>"
274 rownum = "<% $row %>"
275 onKeyPress = "return enable_quick_charge(event)"
276 onKeyUp = "return possiblyAddRow(event)"
289 <SCRIPT TYPE="text/javascript">
291 var rownum = <% $row %>;
293 function possiblyAddRow(e) {
295 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
299 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
303 key = window.event.keyCode; //IE
305 key = e.which; //firefox, others
317 var table = document.getElementById('QuickChargeTable');
318 var tablebody = table.getElementsByTagName('tbody').item(0);
320 var row = document.createElement('TR');
322 var empty_cell = document.createElement('TD');
323 row.appendChild(empty_cell);
325 var description_cell = document.createElement('TD');
327 //var description_input = document.createElement('INPUT');
328 var di = document.createElement('INPUT');
329 di.setAttribute('name', 'description'+rownum);
330 di.setAttribute('id', 'description'+rownum);
331 di.setAttribute('size', 60);
332 di.setAttribute('maxLength', 65);
333 di.setAttribute('rownum', rownum);
334 di.onkeyup = possiblyAddRow;
335 di.onkeypress = enable_quick_charge;
336 description_cell.appendChild(di);
338 row.appendChild(description_cell);
340 tablebody.appendChild(row);
351 <FONT CLASS="fsinnerbox-title">Taxation</FONT>
352 <TABLE CLASS="fsinnerbox">
355 <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
356 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
359 <& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
361 <& /elements/tr-select-taxproduct.html,
362 'label' => emt('Tax product'),
363 'curr_value' => scalar($cgi->param('taxproductnum')),
366 <& /elements/tr-select-taxoverride.html,
367 'curr_value' => scalar($cgi->param('tax_override')),
372 % if ( $curuser->access_right('Edit package definition costs') ) {
375 <FONT CLASS="fsinnerbox-title"><% mt('Cost Accounting') |h %>
376 <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
378 <& /elements/tr-input-text.html,
380 field => 'setup_cost',
381 value => $setup_cost,
383 prefix => $money_char,
396 % if ( $curuser->access_right('Discount customer package') ) {
398 <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
399 <TABLE CLASS="fsinnerbox">
400 <& /elements/tr-select-pkg-discount.html,
401 'setup_label' => emt('Discount'),
402 'disable_recur' => 1,
403 'disable_waive_setup' => 1,
409 % unless ( $quotationnum ) {
412 <FONT CLASS="fsinnerbox-title"><% mt('Invoicing') |h %></FONT>
413 <TABLE CLASS="fsinnerbox">
416 <TH ALIGN="right"><% mt('Invoice now') |h %></TH>
418 <INPUT TYPE = "checkbox"
421 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
422 onClick = "bill_now_changed(this);"
423 onChange = "bill_now_changed(this);"
425 <FONT SIZE=-1><% mt('with terms') |h %></FONT>
426 <& /elements/select-terms.html,
427 'curr_value' => scalar($cgi->param('invoice_terms')),
428 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
429 'agentnum' => $cust_or_prospect->agentnum,
434 % # false laziness w/misc/order_pkg.html
436 <TH ALIGN="right"><% mt('Charge date') |h %> </TH>
441 ID = "start_date_text"
442 VALUE = "<% $start_date %>"
443 onKeyPress="return enable_quick_charge(event)"
444 <% $cgi->param('bill_now')
445 ? 'STYLE = "background-color:#dddddd" DISABLED'
449 <IMG SRC = "<%$fsurl%>images/calendar.png"
450 ID = "start_date_button"
451 TITLE = "<% mt('Select date') |h %>"
452 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
454 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
455 ID = "start_date_button_disabled"
456 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
458 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
462 <SCRIPT TYPE="text/javascript">
464 inputField: "start_date_text",
465 ifFormat: "<% $date_format %>",
466 button: "start_date_button",
471 <& /elements/tr-checkbox.html,
472 label => emt('Invoice this charge separately'),
473 field => 'separate_bill',
477 % if ( $cust_main->has_cust_payby_auto ) {
478 % my $what = lc(FS::payby->shortname($cust_main->payby));
480 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
481 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
492 % my $label = $cust_pkg
493 % ? emt('Modify one-time charge')
494 % : emt('Add one-time charge');
495 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
496 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
501 % formvalidation => {
502 % QuickChargeForm => {
503 % validate_fields => {
504 % quantity => 'digits: true, min: 1, required: true',
509 % if ( $quotationnum ) {
510 <& /elements/footer.html, %footer_args &>
512 <& /elements/footer-cust_main.html, %footer_args &>
516 my $curuser = $FS::CurrentUser::CurrentUser;
519 unless $curuser->access_right('One-time charge');
521 my $conf = new FS::Conf;
522 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
523 my $money_char = $conf->config('money_char') || '$';
525 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
526 if ( $cgi->param('change_pkgnum') ) {
527 # change an existing one-time charge
529 unless $curuser->access_right('Modify one-time charge');
531 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
532 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
533 $cust_main = $cust_pkg->cust_main;
535 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
538 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
539 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
541 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
542 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
544 die "custnum or prospectnum must be specified"
545 unless $cust_main || $prospect_main;
548 my $cust_or_prospect = $cust_main || $prospect_main;
551 my $custnum = $cust_main->custnum;
553 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
554 die "custnum $custnum not found";
556 } elsif ( $prospect_main ) {
557 my $prospectnum = $prospect_main->prospectnum;
559 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
560 die "prospectnum $prospectnum not found";
564 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
565 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
566 $start_date = $start_date ? time2str($format, $start_date) : '';
569 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
574 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
579 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
583 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
584 or die 'illegal description';
588 if ( $cust_main && $cust_main->invoice_terms ) {
589 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
592 emt( "Default ([_1])",
593 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
594 || emt('Payable upon receipt')
600 my %param = $cgi->Vars;
601 for (my $i = 0; exists($param{"description$i"}); $i++) {
602 push @description, $param{"description$i"};
606 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
613 if ( $cust_pkg ) { # set defaults
614 $part_pkg = $cust_pkg->part_pkg;
615 $pkg ||= $part_pkg->pkg;
616 $classnum ||= $part_pkg->classnum;
618 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
620 push @description, $part_pkg->option("additional_info$i",1);
623 $billed = $cust_pkg->get('setup') ? 1 : 0;