1 <& /elements/header-popup.html, mt('One-time charge'), '',
2 ( $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;
96 <FORM ACTION = "process/quick-charge.cgi"
97 NAME = "QuickChargeForm"
98 ID = "QuickChargeForm"
100 onSubmit = "document.QuickChargeForm.submit.disabled=true; return validate_quick_charge();"
103 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
105 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
109 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
110 <& /elements/tr-fixed.html,
113 value => $money_char . sprintf('%.2f',$part_pkg->option('setup_fee')),
116 % if ( $conf->exists('invoice-unitprice') ) {
117 <& /elements/tr-fixed.html,
120 value => $cust_pkg->quantity
124 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
126 % # crudely estimate whether any agent commission credits might exist
127 % my @events = grep { $_->part_event->action =~ /credit/ }
128 % $cust_pkg->cust_event;
129 % if ( scalar @events ) {
131 <TD><INPUT TYPE="checkbox" NAME="adjust_commission" VALUE="Y" CHECKED>
132 <% emt('Adjust commission credits if necessary') %>
137 % #display the future or past charge date, but don't allow changes
138 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
139 % # there's no compelling need yet
140 % if ( $cust_pkg->setup or $cust_pkg->start_date ) {
141 % my $label = $cust_pkg->setup ? emt('Billed on') : emt('Will be billed');
142 % my $field = $cust_pkg->setup ? 'setup' : 'start_date';
143 <& /elements/tr-fixed-date.html,
145 value => $cust_pkg->get($field)
147 % } # else we don't show anything here
148 % } else { # new one-time charge
151 <TD ALIGN="right"><% mt('Amount') |h %> </TD>
153 <% $money_char %><INPUT TYPE = "text"
156 VALUE = "<% $amount %>"
157 onChange = "return enable_quick_charge(event)"
158 onKeyPress = "return enable_quick_charge(event)"
163 % if ( $conf->exists('invoice-unitprice') ) {
165 <TD ALIGN="right"><% mt('Quantity') |h %> </TD>
170 VALUE = "<% $quantity %>"
171 onKeyPress = "return enable_quick_charge(event)">
176 <& /elements/tr-select-pkg_class.html, 'curr_value' => $classnum &>
179 <TD ALIGN="right"><% mt('Invoice now') |h %></TD>
181 <INPUT TYPE = "checkbox"
184 <% $cgi->param('bill_now') ? 'CHECKED' : '' %>
185 onClick = "bill_now_changed(this);"
186 onChange = "bill_now_changed(this);"
188 <% mt('with terms') |h %>
189 <& /elements/select-terms.html,
190 'curr_value' => scalar($cgi->param('invoice_terms')),
191 'disabled' => ( $cgi->param('bill_now') ? 0 : 1 ),
196 %# false laziness w/misc/order_pkg.html
198 <TD ALIGN="right"><% mt('Charge date') |h %> </TD>
203 ID = "start_date_text"
204 VALUE = "<% $start_date %>"
205 onKeyPress="return enable_quick_charge(event)"
206 <% $cgi->param('bill_now')
207 ? 'STYLE = "background-color:#dddddd" DISABLED'
211 <IMG SRC = "<%$fsurl%>images/calendar.png"
212 ID = "start_date_button"
213 TITLE = "<% mt('Select date') |h %>"
214 STYLE = "cursor:pointer<% $cgi->param('bill_now') ? ';display:none' : '' %>"
216 <IMG SRC = "<%$fsurl%>images/calendar-disabled.png"
217 ID = "start_date_button_disabled"
218 <% $cgi->param('bill_now') ? '' : 'STYLE="display:none"' %>
220 <FONT SIZE=-1>(<% mt('leave blank to charge immediately') |h %>)</FONT>
224 <SCRIPT TYPE="text/javascript">
226 inputField: "start_date_text",
227 ifFormat: "<% $date_format %>",
228 button: "start_date_button",
233 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
234 % my $what = lc(FS::payby->shortname($cust_main->payby));
236 <TD ALIGN="right"><% mt("Disable automatic $what charge") |h %> </TD>
237 <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
242 <TD ALIGN="right"><% mt('Tax exempt') |h %> </TD>
243 <TD><INPUT TYPE="checkbox" NAME="setuptax" VALUE="Y" <% $cgi->param('setuptax') ? 'CHECKED' : '' %>></TD>
246 <& /elements/tr-select-taxclass.html, 'curr_value' => $cgi->param('taxclass') &>
248 <& /elements/tr-select-taxproduct.html, 'label' => emt('Tax product'), 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') &>
250 <& /elements/tr-select-taxoverride.html, 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') &>
255 <TD ALIGN="right"><% mt('Description') |h %> </TD>
262 onChange = "return enable_quick_charge(event)"
263 onKeyPress = "return enable_quick_charge(event)"
270 <TD><FONT SIZE="-1"><% mt('Optional additional description (also printed on invoice):') |h %> </FONT></TD>
274 % foreach (@description) {
279 NAME = "description<% $row %>"
282 VALUE = "<% $_ |h %>"
283 rownum = "<% $row %>"
284 onKeyPress = "return enable_quick_charge(event)"
285 onKeyUp = "return possiblyAddRow(event)"
296 % my $label = $cust_pkg
297 % ? emt('Modify one-time charge')
298 % : emt('Add one-time charge');
299 <INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $label %>" \
300 <% ($cgi->param('error') || $cust_pkg) ? '' :' DISABLED' %>>
305 <SCRIPT TYPE="text/javascript">
307 var rownum = <% $row %>;
309 function possiblyAddRow(e) {
311 if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
315 % if ( $curuser->option('disable_enter_submit_onetimecharge') ) {
319 key = window.event.keyCode; //IE
321 key = e.which; //firefox, others
333 var table = document.getElementById('QuickChargeTable');
334 var tablebody = table.getElementsByTagName('tbody').item(0);
336 var row = document.createElement('TR');
338 var empty_cell = document.createElement('TD');
339 row.appendChild(empty_cell);
341 var description_cell = document.createElement('TD');
343 //var description_input = document.createElement('INPUT');
344 var di = document.createElement('INPUT');
345 di.setAttribute('name', 'description'+rownum);
346 di.setAttribute('id', 'description'+rownum);
347 di.setAttribute('size', 60);
348 di.setAttribute('maxLength', 65);
349 di.setAttribute('rownum', rownum);
350 di.onkeyup = possiblyAddRow;
351 di.onkeypress = enable_quick_charge;
352 description_cell.appendChild(di);
354 row.appendChild(description_cell);
356 tablebody.appendChild(row);
368 my $curuser = $FS::CurrentUser::CurrentUser;
371 unless $curuser->access_right('One-time charge');
373 my $conf = new FS::Conf;
374 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
375 my $money_char = $conf->config('money_char') || '$';
377 my ($cust_main, $cust_pkg);
378 if ( $cgi->param('change_pkgnum') ) {
379 # change an existing one-time charge
381 unless $curuser->access_right('Modify one-time charge');
383 $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
384 $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
385 $cust_main = $cust_pkg->cust_main;
387 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
388 $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
391 my $custnum = $cust_main->custnum;
393 if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
394 die "custnum $custnum not found";
397 my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
398 my $start_date = $cust_main->next_bill_date;
399 $start_date = $start_date ? time2str($format, $start_date) : '';
402 if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
407 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
411 $cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
412 or die 'illegal description';
416 if ( $cust_main->invoice_terms ) {
417 $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
419 $default_terms = emt("Default ([_1])",
420 ($conf->config('invoice_default_terms') || emt('Payable upon receipt'))
425 my %param = $cgi->Vars;
426 for (my $i = 0; exists($param{"description$i"}); $i++) {
427 push @description, $param{"description$i"};
431 if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
437 if ( $cust_pkg ) { # set defaults
438 $part_pkg = $cust_pkg->part_pkg;
439 $pkg ||= $part_pkg->pkg;
440 $classnum ||= $part_pkg->classnum;
442 for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
444 push @description, $part_pkg->option("additional_info$i",1);