1 <& /elements/header.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>
10 <& /elements/error.html &>
12 <SCRIPT TYPE="text/javascript">
14 function enable_quick_charge (e) {
16 if ( document.QuickChargeForm.amount.value
17 && document.QuickChargeForm.pkg.value ) {
18 document.QuickChargeForm.submit.disabled = false;
20 document.QuickChargeForm.submit.disabled = true;
23 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
27 key = window.event.keyCode; //IE
30 key = e.which; //firefox, others
40 function validate_quick_charge () {
41 var pkg = document.QuickChargeForm.pkg.value;
42 var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
43 var amount = document.QuickChargeForm.amount.value;
44 var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
47 if ( ! amount_regex.test(amount) ) {
48 alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
51 if ( String(pkg).length < 1 ) {
54 if ( ! pkg_regex.test(pkg) ) {
58 for (i=0; i < rownum; i++) {
59 if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
69 alert('Enter a description for the one-time charge');
73 alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
77 function bill_now_changed (what) {
80 form.start_date_text.disabled = true;
81 form.start_date.style.backgroundColor = '#dddddd';
82 form.start_date_button.style.display = 'none';
83 form.start_date_button_disabled.style.display = '';
84 form.invoice_terms.disabled = false;
86 form.start_date_text.disabled = false;
87 form.start_date.style.backgroundColor = '#ffffff';
88 form.start_date_button.style.display = '';
89 form.start_date_button_disabled.style.display = 'none';
90 form.invoice_terms.disabled = true;
98 <& /elements/small_custview.html,
100 scalar($conf->config('countrydefault')),
104 <& /elements/small_prospect_view.html, $prospect_main &>
108 <FORM ACTION = "process/quick-charge.cgi"
109 NAME = "QuickChargeForm"
110 ID = "QuickChargeForm"
112 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
115 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main ? $cust_main->custnum : '' %>">
116 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospect_main ? $prospect_main->prospectnum : '' %>">
117 <INPUT TYPE="hidden" NAME="quotationnum" VALUE="<% $quotationnum %>">
119 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
121 % if ( $cust_pkg ) { #modify one-time charge
123 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
124 % my $field = '/elements/tr-input-text.html';
125 % # don't allow changing these after the fact
126 % $field = '/elements/tr-fixed.html' if $billed;
128 label => mt('Amount to charge'),
130 value => sprintf('%.2f',$part_pkg->option('setup_fee')),
132 prefix => $money_char,
135 % if ( $curuser->access_right('Edit package definition costs') ) {
138 field => 'setup_cost',
139 value => sprintf('%.2f',$part_pkg->setup_cost),
141 prefix => $money_char,
145 % if ( $conf->exists('invoice-unitprice') ) {
149 value => $cust_pkg->quantity
153 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
155 % # crudely estimate whether any agent commission credits might exist
156 % my @events = grep { $_->part_event->action =~ /credit/ }
157 % $cust_pkg->cust_event;
158 % if ( scalar @events ) {
160 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
161 <% emt('Adjust commission credits if necessary') %>
166 % #display the future or past charge date, but don't allow changes
167 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
168 % # there's no compelling need yet
170 <& /elements/tr-fixed-date.html,
171 label => emt('Billed on'),
172 value => $cust_pkg->get('setup')
175 <& /elements/tr-input-date-field.html,
177 name => 'start_date',
178 label => emt('Will be billed'),
179 value => $cust_pkg->get('start_date'),
180 format => $date_format,
185 <& /elements/tr-checkbox.html,
186 label => emt('Invoice this charge separately'),
187 field => 'separate_bill',
189 curr_value => $cust_pkg->get('separate_bill'),
192 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
193 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
196 <& /elements/tr-select-taxclass.html, 'curr_value' => $part_pkg->get('taxclass') &>
198 <& /elements/tr-select-taxproduct.html,
199 'label' => emt('Tax product'),
200 'curr_value' => $part_pkg->get('taxproductnum')
204 % } else { # new one-time charge
207 <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
209 <% $money_char %><INPUT TYPE = "text"
212 VALUE = "<% $amount %>"
213 onChange = "return enable_quick_charge(event)"
214 onKeyPress = "return enable_quick_charge(event)"
219 % if ( $curuser->access_right('Edit package definition costs') ) {
220 <& /elements/tr-input-text.html,
222 field => 'setup_cost',
223 value => $setup_cost,
225 prefix => $money_char,
229 % if ( $conf->exists('invoice-unitprice') ) {
231 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
236 VALUE = "<% $quantity %>"
237 onKeyPress = "return enable_quick_charge(event)">
242 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
244 % unless ( $quotationnum ) {
247 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
249 <INPUT TYPE = "checkbox"
252 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
253 onClick = "bill_now_changed(this);"
254 onChange = "bill_now_changed(this);"
256 <% mt('with terms') |h %>
257 <& /elements/select-terms.html,
258 'curr_value' => scalar($cgi->param('invoice_terms')),
259 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
260 'agentnum' => $cust_or_prospect->agentnum,
265 % # false laziness w/misc/order_pkg.html
267 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
272 ID = "start_date_text"
273 VALUE = "<% $start_date %>"
274 onKeyPress="return enable_quick_charge(event)"
275 <% $cgi->param('bill_now')
276 ? 'STYLE = "background-color:#dddddd" DISABLED'
280 <IMG SRC = "<%$fsurl%>images/calendar.png"
281 ID = "start_date_button"
282 TITLE = "<% mt('Select date') |h %>"
283 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
285 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
286 ID = "start_date_button_disabled"
287 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
289 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
293 <SCRIPT TYPE="text/javascript">
295 inputField: "start_date_text",
296 ifFormat: "<% $date_format %>",
297 button: "start_date_button",
302 <& /elements/tr-checkbox.html,
303 label => emt('Invoice this charge separately'),
304 field => 'separate_bill',
310 % if ( ! $quotationnum && $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
311 % my $what = lc(FS::payby->shortname($cust_main->payby));
313 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
314 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
319 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
320 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
323 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass') &>
325 <& /elements/tr-select-taxproduct.html,
326 'label' => emt('Tax product'),
327 'curr_value' => $cgi->param('taxproductnum')
330 <& /elements/tr-select-taxoverride.html,
331 'curr_value' => $cgi->param('tax_override')
337 <TD ALIGN="right"><% mt('Description') |h %> </TD>
344 onChange = "return enable_quick_charge(event)"
345 onKeyPress = "return enable_quick_charge(event)"
351 % # quotation details are handled by quotation_pkg_detail records, added via link from view/quotation.html
352 % # the details below get attached to the part_pkg record, and there's no way to edit that from quotations
353 % unless ($quotationnum) {
356 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
359 % foreach (@description) {
364 NAME = "description<% $row %>"
367 VALUE = "<% $_ |h %>"
368 rownum = "<% $row %>"
369 onKeyPress = "return enable_quick_charge(event)"
370 onKeyUp = "return possiblyAddRow(event)"
382 % my $label = $cust_pkg
383 % ? emt('Modify one-time charge')
384 % : emt('Add one-time charge');
385 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
386 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
391 <SCRIPT TYPE="text/javascript">
393 var rownum = <% $row %>;
395 function possiblyAddRow(e) {
397 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
401 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
405 key = window.event.keyCode; //IE
407 key = e.which; //firefox, others
419 var table = document.getElementById('QuickChargeTable');
420 var tablebody = table.getElementsByTagName('tbody').item(0);
422 var row = document.createElement('TR');
424 var empty_cell = document.createElement('TD');
425 row.appendChild(empty_cell);
427 var description_cell = document.createElement('TD');
429 //var description_input = document.createElement('INPUT');
430 var di = document.createElement('INPUT');
431 di.setAttribute('name', 'description'+rownum);
432 di.setAttribute('id', 'description'+rownum);
433 di.setAttribute('size', 60);
434 di.setAttribute('maxLength', 65);
435 di.setAttribute('rownum', rownum);
436 di.onkeyup = possiblyAddRow;
437 di.onkeypress = enable_quick_charge;
438 description_cell.appendChild(di);
440 row.appendChild(description_cell);
442 tablebody.appendChild(row);
454 my $curuser = $FS::CurrentUser::CurrentUser;
457 unless $curuser->access_right('One-time charge');
459 my $conf = new FS::Conf;
460 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
461 my $money_char = $conf->config('money_char') || '$';
463 my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
464 if ( $cgi->param('change_pkgnum') ) {
465 # change an existing one-time charge
467 unless $curuser->access_right('Modify one-time charge');
469 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
470 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
471 $cust_main = $cust_pkg->cust_main;
473 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
476 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
477 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
479 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
480 $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
482 die "custnum or prospectnum must be specified"
483 unless $cust_main || $prospect_main;
486 my $cust_or_prospect = $cust_main || $prospect_main;
489 my $custnum = $cust_main->custnum;
491 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
492 die "custnum $custnum not found";
494 } elsif ( $prospect_main ) {
495 my $prospectnum = $prospect_main->prospectnum;
497 if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
498 die "prospectnum $prospectnum not found";
502 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
503 my $start_date = $cust_main ? $cust_main->next_bill_date : '';
504 $start_date = $start_date ? time2str($format, $start_date) : '';
507 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
512 if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
517 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
521 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
522 or die 'illegal description';
526 if ( $cust_main && $cust_main->invoice_terms ) {
527 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
530 emt( "Default ([_1])",
531 ( $conf->config('invoice_default_terms', $cust_or_prospect->agentnum)
532 || emt('Payable upon receipt')
538 my %param = $cgi->Vars;
539 for (my $i = 0; exists($param{"description$i"}); $i++) {
540 push @description, $param{"description$i"};
544 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
551 if ( $cust_pkg ) { # set defaults
552 $part_pkg = $cust_pkg->part_pkg;
553 $pkg ||= $part_pkg->pkg;
554 $classnum ||= $part_pkg->classnum;
556 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
558 push @description, $part_pkg->option("additional_info$i",1);
561 $billed = $cust_pkg->get('setup') ? 1 : 0;