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 %>">
121 <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
123 % if ( $cust_pkg ) { #modify one-time charge
125 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
126 % my $field = '/elements/tr-input-text.html';
127 % # don't allow changing these after the fact
128 % $field = '/elements/tr-fixed.html' if $billed;
130 label => mt('Amount to charge'),
132 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
134 prefix => $money_char,
137 % if ( $curuser->access_right('Edit package definition costs') ) {
140 field => 'setup_cost',
141 value => sprintf('%.2f',$part_pkg->setup_cost),
143 prefix => $money_char,
147 % if ( $conf->exists('invoice-unitprice') ) {
151 value => $cust_pkg->quantity
155 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
157 % # crudely estimate whether any agent commission credits might exist
158 % my @events = grep { $_->part_event->action =~ /credit/ }
159 % $cust_pkg->cust_event;
160 % if ( scalar @events ) {
162 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
163 <% emt('Adjust commission credits if necessary') %>
168 % #display the future or past charge date, but don't allow changes
169 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
170 % # there's no compelling need yet
172 <& /elements/tr-fixed-date.html,
173 label => emt('Billed on'),
174 value => $cust_pkg->get('setup')
177 <& /elements/tr-input-date-field.html,
179 name => 'start_date',
180 label => emt('Will be billed'),
181 value => $cust_pkg->get('start_date'),
182 format => $date_format,
187 <& /elements/tr-checkbox.html,
188 label => emt('Invoice this charge separately'),
189 field => 'separate_bill',
191 curr_value => $cust_pkg->get('separate_bill'),
194 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
195 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
198 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
200 <& /elements/tr-select-taxproduct.html,
201 'label' => emt('Tax product'),
202 'curr_value' => $part_pkg->get('taxproductnum')
206 % } else { # new one-time charge
209 <TH ALIGN="right"><% mt('Amount to charge') |h %> </TH>
211 <% $money_char %><INPUT TYPE = "text"
214 VALUE = "<% $amount %>"
215 onChange = "return enable_quick_charge(event)"
216 onKeyPress = "return enable_quick_charge(event)"
221 % if ( $curuser->access_right('Edit package definition costs') ) {
222 <& /elements/tr-input-text.html,
224 field => 'setup_cost',
225 value => $setup_cost,
227 prefix => $money_char,
231 % if ( $conf->exists('invoice-unitprice') ) {
233 <TH ALIGN="right"><% mt('Quantity') |h %> </TH>
238 VALUE = "<% $quantity %>"
239 onKeyPress = "return enable_quick_charge(event)">
244 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
246 % unless ( $quotationnum ) {
249 <TH ALIGN="right"><% mt('Invoice now') |h %></TH>
251 <INPUT TYPE = "checkbox"
254 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
255 onClick = "bill_now_changed(this);"
256 onChange = "bill_now_changed(this);"
258 <% mt('with terms') |h %>
259 <& /elements/select-terms.html,
260 'curr_value' => scalar($cgi->param('invoice_terms')),
261 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
262 'agentnum' => $cust_or_prospect->agentnum,
267 % # false laziness w/misc/order_pkg.html
269 <TH ALIGN="right"><% mt('Charge date') |h %> </TH>
274 ID = "start_date_text"
275 VALUE = "<% $start_date %>"
276 onKeyPress="return enable_quick_charge(event)"
277 <% $cgi->param('bill_now')
278 ? 'STYLE = "background-color:#dddddd" DISABLED'
282 <IMG SRC = "<%$fsurl%>images/calendar.png"
283 ID = "start_date_button"
284 TITLE = "<% mt('Select date') |h %>"
285 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
287 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
288 ID = "start_date_button_disabled"
289 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
291 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
295 <SCRIPT TYPE="text/javascript">
297 inputField: "start_date_text",
298 ifFormat: "<% $date_format %>",
299 button: "start_date_button",
304 <& /elements/tr-checkbox.html,
305 label => emt('Invoice this charge separately'),
306 field => 'separate_bill',
312 % if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
313 % my $what = lc(FS::payby->shortname($cust_main->payby));
315 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
316 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
321 <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
322 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
325 <& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
327 <& /elements/tr-select-taxproduct.html,
328 'label' => emt('Tax product'),
329 'curr_value' => scalar($cgi->param('taxproductnum')),
332 <& /elements/tr-select-taxoverride.html,
333 'curr_value' => scalar($cgi->param('tax_override')),
339 <TH ALIGN="right"><% mt('Description') |h %> </TH>
346 onChange = "return enable_quick_charge(event)"
347 onKeyPress = "return enable_quick_charge(event)"
353 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
354 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
355 % unless ($quotationnum) {
358 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
361 % foreach (@description) {
366 NAME = "description<% $row %>"
369 VALUE = "<% $_ |h %>"
370 rownum = "<% $row %>"
371 onKeyPress = "return enable_quick_charge(event)"
372 onKeyUp = "return possiblyAddRow(event)"
384 % my $label = $cust_pkg
385 % ? emt('Modify one-time charge')
386 % : emt('Add one-time charge');
387 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
388 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
393 <SCRIPT TYPE="text/javascript">
395 var rownum = <% $row %>;
397 function possiblyAddRow(e) {
399 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
403 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
407 key = window.event.keyCode; //IE
409 key = e.which; //firefox, others
421 var table = document.getElementById('QuickChargeTable');
422 var tablebody = table.getElementsByTagName('tbody').item(0);
424 var row = document.createElement('TR');
426 var empty_cell = document.createElement('TD');
427 row.appendChild(empty_cell);
429 var description_cell = document.createElement('TD');
431 //var description_input = document.createElement('INPUT');
432 var di = document.createElement('INPUT');
433 di.setAttribute('name', 'description'+rownum);
434 di.setAttribute('id', 'description'+rownum);
435 di.setAttribute('size', 60);
436 di.setAttribute('maxLength', 65);
437 di.setAttribute('rownum', rownum);
438 di.onkeyup = possiblyAddRow;
439 di.onkeypress = enable_quick_charge;
440 description_cell.appendChild(di);
442 row.appendChild(description_cell);
444 tablebody.appendChild(row);
452 % if ( $quotationnum ) {
453 <& /elements/footer.html &>
455 <& /elements/footer-cust_main.html &>
459 my $curuser = $FS::CurrentUser::CurrentUser;
462 unless $curuser->access_right('One-time charge');
464 my $conf = new FS::Conf;
465 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
466 my $money_char = $conf->config('money_char') || '$';
468 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
469 if ( $cgi->param('change_pkgnum') ) {
470 # change an existing one-time charge
472 unless $curuser->access_right('Modify one-time charge');
474 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
475 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
476 $cust_main = $cust_pkg->cust_main;
478 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
481 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
482 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
484 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
485 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
487 die "custnum or prospectnum must be specified"
488 unless $cust_main || $prospect_main;
491 my $cust_or_prospect = $cust_main || $prospect_main;
494 my $custnum = $cust_main->custnum;
496 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
497 die "custnum $custnum not found";
499 } elsif ( $prospect_main ) {
500 my $prospectnum = $prospect_main->prospectnum;
502 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
503 die "prospectnum $prospectnum not found";
507 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
508 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
509 $start_date = $start_date ? time2str($format, $start_date) : '';
512 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
517 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
522 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
526 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
527 or die 'illegal description';
531 if ( $cust_main && $cust_main->invoice_terms ) {
532 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
535 emt( "Default ([_1])",
536 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
537 || emt('Payable upon receipt')
543 my %param = $cgi->Vars;
544 for (my $i = 0; exists($param{"description$i"}); $i++) {
545 push @description, $param{"description$i"};
549 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
556 if ( $cust_pkg ) { # set defaults
557 $part_pkg = $cust_pkg->part_pkg;
558 $pkg ||= $part_pkg->pkg;
559 $classnum ||= $part_pkg->classnum;
561 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
563 push @description, $part_pkg->option("additional_info$i",1);
566 $billed = $cust_pkg->get('setup') ? 1 : 0;