1 % if ( $quotationnum ) {
2 <& /elements/header.html, mt('One-time charge'), '',
3 ( ($quotationnum || $cgi->param('error')) ? '' : 'onload="addRow()"' ),
6 <& /elements/header-cust_main.html, view=>'packages', cust_main=>$cust_main &>
7 <h2>One-time charge</h2>
10 <& /elements/init_calendar.html &>
11 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/xregexp-all.js"></SCRIPT>
13 <& /elements/error.html &>
15 <SCRIPT TYPE="text/javascript">
17 function enable_quick_charge (e) {
19 if ( document.QuickChargeForm.amount.value
20 && document.QuickChargeForm.pkg.value ) {
21 document.QuickChargeForm.submit.disabled = false;
23 document.QuickChargeForm.submit.disabled = true;
26 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
30 key = window.event.keyCode; //IE
33 key = e.which; //firefox, others
43 function validate_quick_charge () {
44 var pkg = document.QuickChargeForm.pkg.value;
45 var pkg_regex = XRegExp('^([\\p{L}\\p{N} \_\!\@\#\$\%\&\(\)\+\;\:\'\"\,\.\?\/\=\\-\\[\\]]*)$');
46 var amount = document.QuickChargeForm.amount.value;
47 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
50 if ( ! amount_regex.test(amount) ) {
51 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
54 if ( String(pkg).length < 1 ) {
57 if ( ! pkg_regex.test(pkg) ) {
61 for (i=0; i < rownum; i++) {
62 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
72 alert('Enter a description for the one-time charge');
76 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
80 function bill_now_changed (what) {
83 form.start_date_text.disabled = true;
84 form.start_date.style.backgroundColor = '#dddddd';
85 form.start_date_button.style.display = 'none';
86 form.start_date_button_disabled.style.display = '';
87 form.invoice_terms.disabled = false;
89 form.start_date_text.disabled = false;
90 form.start_date.style.backgroundColor = '#ffffff';
91 form.start_date_button.style.display = '';
92 form.start_date_button_disabled.style.display = 'none';
93 form.invoice_terms.disabled = true;
100 % if ( $prospect_main ) {
101 <& /elements/small_prospect_view.html, $prospect_main &>
105 <FORM ACTION = "process/quick-charge.cgi"
106 NAME = "QuickChargeForm"
107 ID = "QuickChargeForm"
109 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
112 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
113 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
114 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
116 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
118 % if ( $cust_pkg ) { #modify one-time charge
120 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
121 % my $field = '/elements/tr-input-text.html';
122 % # don't allow changing these after the fact
123 % $field = '/elements/tr-fixed.html' if $billed;
125 label => mt('Amount to charge'),
127 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
129 prefix => $money_char,
132 % if ( $curuser->access_right('Edit package definition costs') ) {
135 field => 'setup_cost',
136 value => sprintf('%.2f',$part_pkg->setup_cost),
138 prefix => $money_char,
142 % if ( $conf->exists('invoice-unitprice') ) {
146 value => $cust_pkg->quantity
150 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
152 % # crudely estimate whether any agent commission credits might exist
153 % my @events = grep { $_->part_event->action =~ /credit/ }
154 % $cust_pkg->cust_event;
155 % if ( scalar @events ) {
157 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
158 <% emt('Adjust commission credits if necessary') %>
163 % #display the future or past charge date, but don't allow changes
164 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
165 % # there's no compelling need yet
167 <& /elements/tr-fixed-date.html,
168 label => emt('Billed on'),
169 value => $cust_pkg->get('setup')
172 <& /elements/tr-input-date-field.html,
174 name => 'start_date',
175 label => emt('Will be billed'),
176 value => $cust_pkg->get('start_date'),
177 format => $date_format,
182 <& /elements/tr-checkbox.html,
183 label => emt('Invoice this charge separately'),
184 field => 'separate_bill',
186 curr_value => $cust_pkg->get('separate_bill'),
189 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
190 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
193 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
195 <& /elements/tr-select-taxproduct.html,
196 'label' => emt('Tax product'),
197 'curr_value' => $part_pkg->get('taxproductnum')
201 % } else { # new one-time charge
204 <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
206 <% $money_char %><INPUT TYPE = "text"
209 VALUE = "<% $amount %>"
210 onChange = "return enable_quick_charge(event)"
211 onKeyPress = "return enable_quick_charge(event)"
216 % if ( $curuser->access_right('Edit package definition costs') ) {
217 <& /elements/tr-input-text.html,
219 field => 'setup_cost',
220 value => $setup_cost,
222 prefix => $money_char,
226 % if ( $conf->exists('invoice-unitprice') ) {
228 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
233 VALUE = "<% $quantity %>"
234 onKeyPress = "return enable_quick_charge(event)">
239 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
241 % unless ( $quotationnum ) {
244 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
246 <INPUT TYPE = "checkbox"
249 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
250 onClick = "bill_now_changed(this);"
251 onChange = "bill_now_changed(this);"
253 <% mt('with terms') |h %>
254 <& /elements/select-terms.html,
255 'curr_value' => scalar($cgi->param('invoice_terms')),
256 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
257 'agentnum' => $cust_or_prospect->agentnum,
262 % # false laziness w/misc/order_pkg.html
264 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
269 ID = "start_date_text"
270 VALUE = "<% $start_date %>"
271 onKeyPress="return enable_quick_charge(event)"
272 <% $cgi->param('bill_now')
273 ? 'STYLE = "background-color:#dddddd" DISABLED'
277 <IMG SRC = "<%$fsurl%>images/calendar.png"
278 ID = "start_date_button"
279 TITLE = "<% mt('Select date') |h %>"
280 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
282 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
283 ID = "start_date_button_disabled"
284 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
286 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
290 <SCRIPT TYPE="text/javascript">
292 inputField: "start_date_text",
293 ifFormat: "<% $date_format %>",
294 button: "start_date_button",
299 <& /elements/tr-checkbox.html,
300 label => emt('Invoice this charge separately'),
301 field => 'separate_bill',
307 % if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
308 % my $what = lc(FS::payby->shortname($cust_main->payby));
310 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
311 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
316 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
317 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
320 <& /elements/tr-select-taxclass.html, 'curr_value' => scalar($cgi->param('taxclass')) &>
322 <& /elements/tr-select-taxproduct.html,
323 'label' => emt('Tax product'),
324 'curr_value' => scalar($cgi->param('taxproductnum')),
327 <& /elements/tr-select-taxoverride.html,
328 'curr_value' => scalar($cgi->param('tax_override')),
334 <TD ALIGN="right"><% mt('Description') |h %> </TD>
341 onChange = "return enable_quick_charge(event)"
342 onKeyPress = "return enable_quick_charge(event)"
348 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
349 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
350 % unless ($quotationnum) {
353 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
356 % foreach (@description) {
361 NAME = "description<% $row %>"
364 VALUE = "<% $_ |h %>"
365 rownum = "<% $row %>"
366 onKeyPress = "return enable_quick_charge(event)"
367 onKeyUp = "return possiblyAddRow(event)"
379 % my $label = $cust_pkg
380 % ? emt('Modify one-time charge')
381 % : emt('Add one-time charge');
382 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
383 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
388 <SCRIPT TYPE="text/javascript">
390 var rownum = <% $row %>;
392 function possiblyAddRow(e) {
394 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
398 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
402 key = window.event.keyCode; //IE
404 key = e.which; //firefox, others
416 var table = document.getElementById('QuickChargeTable');
417 var tablebody = table.getElementsByTagName('tbody').item(0);
419 var row = document.createElement('TR');
421 var empty_cell = document.createElement('TD');
422 row.appendChild(empty_cell);
424 var description_cell = document.createElement('TD');
426 //var description_input = document.createElement('INPUT');
427 var di = document.createElement('INPUT');
428 di.setAttribute('name', 'description'+rownum);
429 di.setAttribute('id', 'description'+rownum);
430 di.setAttribute('size', 60);
431 di.setAttribute('maxLength', 65);
432 di.setAttribute('rownum', rownum);
433 di.onkeyup = possiblyAddRow;
434 di.onkeypress = enable_quick_charge;
435 description_cell.appendChild(di);
437 row.appendChild(description_cell);
439 tablebody.appendChild(row);
451 my $curuser = $FS::CurrentUser::CurrentUser;
454 unless $curuser->access_right('One-time charge');
456 my $conf = new FS::Conf;
457 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
458 my $money_char = $conf->config('money_char') || '$';
460 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
461 if ( $cgi->param('change_pkgnum') ) {
462 # change an existing one-time charge
464 unless $curuser->access_right('Modify one-time charge');
466 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
467 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
468 $cust_main = $cust_pkg->cust_main;
470 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
473 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
474 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
476 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
477 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
479 die "custnum or prospectnum must be specified"
480 unless $cust_main || $prospect_main;
483 my $cust_or_prospect = $cust_main || $prospect_main;
486 my $custnum = $cust_main->custnum;
488 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
489 die "custnum $custnum not found";
491 } elsif ( $prospect_main ) {
492 my $prospectnum = $prospect_main->prospectnum;
494 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
495 die "prospectnum $prospectnum not found";
499 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
500 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
501 $start_date = $start_date ? time2str($format, $start_date) : '';
504 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
509 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
514 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
518 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
519 or die 'illegal description';
523 if ( $cust_main && $cust_main->invoice_terms ) {
524 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
527 emt( "Default ([_1])",
528 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
529 || emt('Payable upon receipt')
535 my %param = $cgi->Vars;
536 for (my $i = 0; exists($param{"description$i"}); $i++) {
537 push @description, $param{"description$i"};
541 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
548 if ( $cust_pkg ) { # set defaults
549 $part_pkg = $cust_pkg->part_pkg;
550 $pkg ||= $part_pkg->pkg;
551 $classnum ||= $part_pkg->classnum;
553 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
555 push @description, $part_pkg->option("additional_info$i",1);
558 $billed = $cust_pkg->get('setup') ? 1 : 0;