1 % if ( $quotationnum ) {
2 <& /elements/header.html, mt('One-time charge') &>
4 <& /elements/header-cust_main.html,
6 cust_main => $cust_main,
7 etc => $cgi->param('error') ? '' : 'onload="addRow()"',
9 <h2>One-time charge</h2>
12 <& /elements/init_calendar.html &>
13 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/xregexp-all.js"></SCRIPT>
15 <& /elements/error.html &>
17 <SCRIPT TYPE="text/javascript">
19 function enable_quick_charge (e) {
21 if ( document.QuickChargeForm.amount.value
22 && document.QuickChargeForm.pkg.value ) {
23 document.QuickChargeForm.submit.disabled = false;
25 document.QuickChargeForm.submit.disabled = true;
28 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
32 key = window.event.keyCode; //IE
35 key = e.which; //firefox, others
45 function validate_quick_charge () {
46 var pkg = document.QuickChargeForm.pkg.value;
47 var pkg_regex = XRegExp('^([\\p{L}\\p{N} \_\!\@\#\$\%\&\(\)\+\;\:\'\"\,\.\?\/\=\\-\\[\\]]*)$');
48 var amount = document.QuickChargeForm.amount.value;
49 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
52 if ( ! amount_regex.test(amount) ) {
53 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
56 if ( String(pkg).length < 1 ) {
59 if ( ! pkg_regex.test(pkg) ) {
63 for (i=0; i < rownum; i++) {
64 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
74 alert('Enter a description for the one-time charge');
78 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
82 function bill_now_changed (what) {
85 form.start_date_text.disabled = true;
86 form.start_date.style.backgroundColor = '#dddddd';
87 form.start_date_button.style.display = 'none';
88 form.start_date_button_disabled.style.display = '';
89 form.invoice_terms.disabled = false;
91 form.start_date_text.disabled = false;
92 form.start_date.style.backgroundColor = '#ffffff';
93 form.start_date_button.style.display = '';
94 form.start_date_button_disabled.style.display = 'none';
95 form.invoice_terms.disabled = true;
102 % if ( $prospect_main ) {
103 <& /elements/small_prospect_view.html, $prospect_main &>
107 <FORM ACTION = "process/quick-charge.cgi"
108 NAME = "QuickChargeForm"
109 ID = "QuickChargeForm"
111 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
114 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
115 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
116 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
118 <TABLE ID="QuickChargeTable" CLASS="fsinnerbox">
120 % if ( $cust_pkg ) { #modify one-time charge
122 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
123 % my $field = '/elements/tr-input-text.html';
124 % # don't allow changing these after the fact
125 % $field = '/elements/tr-fixed.html' if $billed;
127 label => mt('Amount to charge'),
129 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
131 prefix => $money_char,
134 % if ( $curuser->access_right('Edit package definition costs') ) {
137 field => 'setup_cost',
138 value => sprintf('%.2f',$part_pkg->setup_cost),
140 prefix => $money_char,
144 % if ( $conf->exists('invoice-unitprice') ) {
148 value => $cust_pkg->quantity
152 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
154 % # crudely estimate whether any agent commission credits might exist
155 % my @events = grep { $_->part_event->action =~ /credit/ }
156 % $cust_pkg->cust_event;
157 % if ( scalar @events ) {
159 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
160 <% emt('Adjust commission credits if necessary') %>
165 % #display the future or past charge date, but don't allow changes
166 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
167 % # there's no compelling need yet
169 <& /elements/tr-fixed-date.html,
170 label => emt('Billed on'),
171 value => $cust_pkg->get('setup')
174 <& /elements/tr-input-date-field.html,
176 name => 'start_date',
177 label => emt('Will be billed'),
178 value => $cust_pkg->get('start_date'),
179 format => $date_format,
184 <& /elements/tr-checkbox.html,
185 label => emt('Invoice this charge separately'),
186 field => 'separate_bill',
188 curr_value => $cust_pkg->get('separate_bill'),
191 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
192 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
195 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
197 <& /elements/tr-select-taxproduct.html,
198 'label' => emt('Tax product'),
199 'curr_value' => $part_pkg->get('taxproductnum')
203 % } else { # new one-time charge
206 <TH ALIGN="right"><% mt('Amount to charge') |h %> </TH>
208 <% $money_char %><INPUT TYPE = "text"
211 VALUE = "<% $amount %>"
212 onChange = "return enable_quick_charge(event)"
213 onKeyPress = "return enable_quick_charge(event)"
218 % if ( $curuser->access_right('Edit package definition costs') ) {
219 <& /elements/tr-input-text.html,
221 field => 'setup_cost',
222 value => $setup_cost,
224 prefix => $money_char,
228 % if ( $conf->exists('invoice-unitprice') ) {
230 <TH ALIGN="right"><% mt('Quantity') |h %> </TH>
235 VALUE = "<% $quantity %>"
236 onKeyPress = "return enable_quick_charge(event)">
241 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
243 % unless ( $quotationnum ) {
246 <TH ALIGN="right"><% mt('Invoice now') |h %></TH>
248 <INPUT TYPE = "checkbox"
251 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
252 onClick = "bill_now_changed(this);"
253 onChange = "bill_now_changed(this);"
255 <% mt('with terms') |h %>
256 <& /elements/select-terms.html,
257 'curr_value' => scalar($cgi->param('invoice_terms')),
258 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
259 'agentnum' => $cust_or_prospect->agentnum,
264 % # false laziness w/misc/order_pkg.html
266 <TH ALIGN="right"><% mt('Charge date') |h %> </TH>
271 ID = "start_date_text"
272 VALUE = "<% $start_date %>"
273 onKeyPress="return enable_quick_charge(event)"
274 <% $cgi->param('bill_now')
275 ? 'STYLE = "background-color:#dddddd" DISABLED'
279 <IMG SRC = "<%$fsurl%>images/calendar.png"
280 ID = "start_date_button"
281 TITLE = "<% mt('Select date') |h %>"
282 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
284 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
285 ID = "start_date_button_disabled"
286 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
288 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
292 <SCRIPT TYPE="text/javascript">
294 inputField: "start_date_text",
295 ifFormat: "<% $date_format %>",
296 button: "start_date_button",
301 <& /elements/tr-checkbox.html,
302 label => emt('Invoice this charge separately'),
303 field => 'separate_bill',
309 % if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
310 % my $what = lc(FS::payby->shortname($cust_main->payby));
312 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
313 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
318 <TH ALIGN="right"><% mt('Tax exempt') |h %> </TH>
319 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
322 <& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
324 <& /elements/tr-select-taxproduct.html,
325 'label' => emt('Tax product'),
326 'curr_value' => scalar($cgi->param('taxproductnum')),
329 <& /elements/tr-select-taxoverride.html,
330 'curr_value' => scalar($cgi->param('tax_override')),
336 <TH ALIGN="right"><% mt('Description') |h %> </TH>
343 onChange = "return enable_quick_charge(event)"
344 onKeyPress = "return enable_quick_charge(event)"
350 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
351 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
352 % unless ($quotationnum) {
355 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
358 % foreach (@description) {
363 NAME = "description<% $row %>"
366 VALUE = "<% $_ |h %>"
367 rownum = "<% $row %>"
368 onKeyPress = "return enable_quick_charge(event)"
369 onKeyUp = "return possiblyAddRow(event)"
381 % my $label = $cust_pkg
382 % ? emt('Modify one-time charge')
383 % : emt('Add one-time charge');
384 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
385 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
390 <SCRIPT TYPE="text/javascript">
392 var rownum = <% $row %>;
394 function possiblyAddRow(e) {
396 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
400 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
404 key = window.event.keyCode; //IE
406 key = e.which; //firefox, others
418 var table = document.getElementById('QuickChargeTable');
419 var tablebody = table.getElementsByTagName('tbody').item(0);
421 var row = document.createElement('TR');
423 var empty_cell = document.createElement('TD');
424 row.appendChild(empty_cell);
426 var description_cell = document.createElement('TD');
428 //var description_input = document.createElement('INPUT');
429 var di = document.createElement('INPUT');
430 di.setAttribute('name', 'description'+rownum);
431 di.setAttribute('id', 'description'+rownum);
432 di.setAttribute('size', 60);
433 di.setAttribute('maxLength', 65);
434 di.setAttribute('rownum', rownum);
435 di.onkeyup = possiblyAddRow;
436 di.onkeypress = enable_quick_charge;
437 description_cell.appendChild(di);
439 row.appendChild(description_cell);
441 tablebody.appendChild(row);
449 % if ( $quotationnum ) {
450 <& /elements/footer.html &>
452 <& /elements/footer-cust_main.html &>
456 my $curuser = $FS::CurrentUser::CurrentUser;
459 unless $curuser->access_right('One-time charge');
461 my $conf = new FS::Conf;
462 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
463 my $money_char = $conf->config('money_char') || '$';
465 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
466 if ( $cgi->param('change_pkgnum') ) {
467 # change an existing one-time charge
469 unless $curuser->access_right('Modify one-time charge');
471 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
472 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
473 $cust_main = $cust_pkg->cust_main;
475 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
478 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
479 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
481 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
482 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
484 die "custnum or prospectnum must be specified"
485 unless $cust_main || $prospect_main;
488 my $cust_or_prospect = $cust_main || $prospect_main;
491 my $custnum = $cust_main->custnum;
493 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
494 die "custnum $custnum not found";
496 } elsif ( $prospect_main ) {
497 my $prospectnum = $prospect_main->prospectnum;
499 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
500 die "prospectnum $prospectnum not found";
504 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
505 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
506 $start_date = $start_date ? time2str($format, $start_date) : '';
509 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
514 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
519 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
523 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
524 or die 'illegal description';
528 if ( $cust_main && $cust_main->invoice_terms ) {
529 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
532 emt( "Default ([_1])",
533 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
534 || emt('Payable upon receipt')
540 my %param = $cgi->Vars;
541 for (my $i = 0; exists($param{"description$i"}); $i++) {
542 push @description, $param{"description$i"};
546 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
553 if ( $cust_pkg ) { # set defaults
554 $part_pkg = $cust_pkg->part_pkg;
555 $pkg ||= $part_pkg->pkg;
556 $classnum ||= $part_pkg->classnum;
558 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
560 push @description, $part_pkg->option("additional_info$i",1);
563 $billed = $cust_pkg->get('setup') ? 1 : 0;