3 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
4 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
5 JSAN.errorLevel = "die"; // none, warn, or die
6 JSAN.addRepository('/xul/server/');
8 JSAN.use('util.error'); g.error = new util.error();
9 JSAN.use('util.network'); g.network = new util.network();
10 JSAN.use('util.date');
11 JSAN.use('util.money');
12 JSAN.use('util.widgets');
13 JSAN.use('patron.util');
14 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
15 g.data.voided_billings = []; g.data.stash('voided_billings');
17 g.error.sdump('D_TRACE','my_init() for bill2.xul');
19 if (xul_param('current')) {
20 $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.current_bills'));
21 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
23 $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.bill_history'));
24 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.bill_history');
27 g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
29 g.patron_id = xul_param('patron_id');
31 $('circulating_hint').hidden = true;
35 retrieve_mbts_for_list();
39 JSAN.use('util.exec'); var exec = new util.exec(20);
40 exec.on_error = function(E) { alert(E); return true; }
41 exec.timer(g.funcs,100);
43 $('credit_forward').setAttribute('value','???');
47 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));
50 if (g.data.hash.aous['ui.circ.billing.uncheck_bills_and_unfocus_payment_box']) {
53 $('uncheck_all').focus();
67 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
68 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
73 function event_listeners() {
75 $('details').addEventListener(
81 $('add').addEventListener(
87 $('voidall').addEventListener(
93 $('refund').addEventListener(
99 $('opac').addEventListener(
105 $('copy_details').addEventListener(
111 $('payment').addEventListener(
114 if ($('payment_type').value == 'credit_payment') {
115 JSAN.use('util.money');
116 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
117 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
118 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
119 if (proposed > available) {
120 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
121 ev.target.value = util.money.cents_as_dollars( available );
122 ev.target.setAttribute('value',ev.target.value);
125 distribute_payment();
130 $('payment').addEventListener(
132 function(ev) { ev.target.select(); },
136 $('payment').addEventListener(
139 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
140 distribute_payment();
141 $('apply_payment_btn').focus();
146 $('bill_patron_btn').addEventListener(
149 JSAN.use('util.window'); var win = new util.window();
150 var my_xulG = win.open(
151 urls.XUL_PATRON_BILL_WIZARD,
153 'chrome,resizable,modal',
154 { 'patron_id' : g.patron_id }
156 if (my_xulG.xact_id) { g.funcs.push( gen_list_append_func( my_xulG.xact_id ) ); /* FIXME: do something to update summary sidebar */ }
161 $('bill_history_btn').addEventListener(
164 xulG.display_window.g.patron.right_deck.reset_iframe(
165 urls.XUL_PATRON_BILL_HISTORY,
168 'patron_id' : g.patron_id,
169 'refresh' : function() { refresh(); },
170 'new_tab' : xulG.new_tab
177 $('convert_change_to_credit').addEventListener(
180 if (ev.target.checked) {
181 addCSSClass( $('change_due'), 'change_to_credit' );
183 removeCSSClass( $('change_due'), 'change_to_credit' );
189 $('apply_payment_btn').addEventListener(
193 $('apply_payment_btn').disabled = true;
196 $('apply_payment_btn').disabled = false;
198 alert('Error in bill2.js, apply_payment_btn: ' + E);
205 alert('Error in bill2.js, event_listeners(): ' + E);
209 function $(id) { return document.getElementById(id); }
211 function default_focus() {
212 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
215 function tally_pending() {
218 JSAN.use('util.money');
219 var tb = $('payment');
220 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
221 var payment_pending = 0;
222 var retrieve_ids = g.bill_list.dump_retrieve_ids();
223 for (var i = 0; i < retrieve_ids.length; i++) {
224 var row_params = g.row_map[retrieve_ids[i]];
225 if (g.check_map[retrieve_ids[i]]) {
226 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
227 payment_pending += value;
228 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
231 var change_pending = payment_tendered - payment_pending;
232 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
233 $('pending_change').value = util.money.cents_as_dollars( change_pending );
234 $('change_due').value = util.money.cents_as_dollars( change_pending );
235 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
237 alert('Error in bill2.js, tally_pending(): ' + E);
241 function tally_selected() {
243 JSAN.use('util.money');
244 var selected_billed = 0;
245 var selected_paid = 0;
246 var selected_balance = 0;
248 for (var i = 0; i < g.bill_list_selection.length; i++) {
249 var bill = g.bill_map[g.bill_list_selection[i]];
251 //$('checked_owed').setAttribute('value', '???');
252 //$('checked_billed').setAttribute('value', '???');
253 //$('checked_paid').setAttribute('value', '???');
256 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
257 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
258 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
259 selected_billed += to;
261 selected_balance += bo;
263 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
264 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
265 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
267 alert('Error in bill2.js, tally_selected(): ' + E);
271 function tally_voided() {
273 JSAN.use('util.money');
274 var voided_total = 0;
276 g.data.stash_retrieve();
278 for (var i = 0; i < g.data.voided_billings.length; i++) {
279 var billing = g.data.voided_billings[i];
280 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
283 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
285 alert('Error in bill2.js, tally_voided(): ' + E);
289 function tally_all() {
291 JSAN.use('util.money');
292 var checked_billed = 0;
293 var checked_paid = 0;
294 var checked_balance = 0;
295 var total_billed = 0;
297 var total_balance = 0;
298 var refunds_owed = 0;
300 var retrieve_ids = g.bill_list.dump_retrieve_ids();
301 for (var i = 0; i < retrieve_ids.length; i++) {
302 var bill = g.bill_map[retrieve_ids[i]];
304 $('checked_owed').value = '???';
305 $('checked_owed2').setAttribute('value', '???');
306 $('checked_billed').value = '???';
307 $('checked_paid').value = '???';
308 $('tb_total_owed').value = '???';
309 $('total_owed2').setAttribute('value', '???');
310 $('total_billed').value = '???';
311 $('tb_total_paid').value = '???';
312 $('refunds_owed').setAttribute('value', '???');
315 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
316 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
317 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
321 if ( bo < 0 ) refunds_owed += bo;
322 if (g.check_map[retrieve_ids[i]]) {
323 checked_billed += to;
325 checked_balance += bo;
328 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
329 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
330 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
331 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
332 $('total_billed').value = util.money.cents_as_dollars( total_billed );
333 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
334 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
335 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
336 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
339 alert('Error in bill2.js, tally_all(): ' + E);
343 function handle_refund() {
344 if(g.bill_list_selection.length > 1) {
345 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
347 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
350 var r = g.error.yns_alert(msg,
351 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
352 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
353 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
354 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
356 for (var i = 0; i < g.bill_list_selection.length; i++) {
357 var bill_id = g.bill_list_selection[i];
358 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
359 g.check_map[bill_id] = true;
360 var row_params = g.row_map[bill_id];
361 row_params.row.my.checked = true;
362 g.bill_list.refresh_row(row_params);
366 distribute_payment();
370 function check_all() {
372 for (var i in g.bill_map) {
373 g.check_map[i] = true;
374 var row_params = g.row_map[i];
375 row_params.row.my.checked = true;
376 g.bill_list.refresh_row(row_params);
379 distribute_payment();
381 alert('Error in bill2.js, check_all(): ' + E);
386 function uncheck_all() {
388 for (var i in g.bill_map) {
389 g.check_map[i] = false;
390 var row_params = g.row_map[i];
391 row_params.row.my.checked = false;
392 g.bill_list.refresh_row(row_params);
395 distribute_payment();
397 alert('Error in bill2.js, check_all(): ' + E);
402 function check_all_refunds() {
404 for (var i in g.bill_map) {
405 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
406 g.check_map[i] = true;
407 var row_params = g.row_map[i];
408 row_params.row.my.checked = true;
409 g.bill_list.refresh_row(row_params);
413 distribute_payment();
415 alert('Error in bill2.js, check_all_refunds(): ' + E);
419 function gen_list_append_func(r) {
421 var default_check_state = g.data.hash.aous[
422 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
424 if (typeof r == 'object') {
425 g.row_map[ r.id() ] = g.bill_list.append( {
426 'retrieve_id' : r.id(),
427 'flesh_immediately' : true,
430 'checked' : default_check_state,
436 g.row_map[r] = g.bill_list.append( {
438 'flesh_immediately' : true,
441 'checked' : default_check_state
449 function retrieve_mbts_for_list() {
450 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
451 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
452 if (g.mbts_ids.ilsevent) {
453 switch(Number(g.mbts_ids.ilsevent)) {
454 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
455 default: g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),g.mbts_ids); break;
457 } else if (g.mbts_ids == null) {
458 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
461 g.mbts_ids.reverse();
463 for (var i = 0; i < g.mbts_ids.length; i++) {
464 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
465 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
470 function init_lists() {
471 JSAN.use('util.list'); JSAN.use('circ.util');
473 g.bill_list_selection = [];
475 g.bill_list = new util.list('bill_tree');
481 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
482 'render' : function(my) { return String( my.checked ) == 'true'; },
485 patron.util.mbts_columns({
486 'mbts_xact_finish' : { 'hidden' : xul_param('current') ? true : false }
490 'title' : { 'hidden' : false, 'flex' : '3' }
495 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
496 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
497 'render' : function(my) { return my.payment_pending || '0.00'; },
501 'map_row_to_columns' : patron.util.std_map_row_to_columns(' '),
502 'on_select' : function(ev) {
503 JSAN.use('util.functional');
504 g.bill_list_selection = util.functional.map_list(
505 g.bill_list.retrieve_selection(),
506 function(o) { return o.getAttribute('retrieve_id'); }
509 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
510 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
511 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
512 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
513 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
514 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
516 'on_click' : function(ev) {
517 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
518 var row = {}; var col = {}; var nobj = {};
519 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
520 if (row.value == -1) return;
521 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
522 if (treeItem.nodeName != 'treeitem') return;
523 var treeRow = treeItem.firstChild;
524 var treeCell = treeRow.firstChild;
525 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
526 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
527 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
529 distribute_payment();
532 'on_sort' : function() {
535 'on_checkbox_toggle' : function(toggle) {
537 var retrieve_ids = g.bill_list.dump_retrieve_ids();
538 for (var i = 0; i < retrieve_ids.length; i++) {
539 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
540 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
544 alert('error in on_checkbox_toggle(): ' + E);
547 'retrieve_row' : function(params) {
549 var id = params.retrieve_id;
550 var row = params.row;
552 function handle_props(row) {
554 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
555 util.widgets.addProperty(params.row_node.firstChild,'refundable');
556 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
558 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
559 $('circulating_hint').hidden = false;
560 util.widgets.addProperty(params.row_node.firstChild,'circulating');
561 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
564 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
565 alert('Error setting list properties in bill2.js: ' + E);
570 if (typeof row.my == 'undefined') row.my = {};
571 if (typeof row.my.mbts == 'undefined' ) {
572 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
573 var blob = req.getResultObject();
574 row.my.mbts = blob.transaction;
575 row.my.circ = blob.circ;
576 row.my.acp = blob.copy;
577 row.my.mvr = blob.record;
578 if (typeof params.on_retrieve == 'function') {
579 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
580 row.my.checked = false;
583 params.on_retrieve(row);
585 g.bill_map[ id ] = blob;
586 g.check_map[ id ] = row.my.checked;
590 if (typeof params.on_retrieve == 'function') {
592 params.on_retrieve(row);
596 if (typeof params.on_retrieve == 'function') {
597 params.on_retrieve(row);
603 alert('Error in bill2.js, retrieve_row(): ' + E);
608 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
609 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
610 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
611 g.bill_list.set_list_actions();
614 function handle_add() {
615 if(g.bill_list_selection.length > 1) {
616 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
618 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
621 var r = g.error.yns_alert(msg,
622 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
623 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
624 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
625 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
627 JSAN.use('util.window');
628 var win = new util.window();
629 for (var i = 0; i < g.bill_list_selection.length; i++) {
631 urls.XUL_PATRON_BILL_WIZARD,
633 'chrome,resizable,modal',
634 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
638 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
642 function handle_void_all() {
643 if(g.bill_list_selection.length > 1) {
644 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
646 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
649 var r = g.error.yns_alert(msg,
650 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
651 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
652 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
653 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
655 for (var i = 0; i < g.bill_list_selection.length; i++) {
656 void_all_billings( g.bill_list_selection[i] );
659 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
660 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
664 function handle_opac() {
667 for (var i = 0; i < g.bill_list_selection.length; i++) {
668 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
669 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
670 if (typeof my_mvr != 'undefined' && my_mvr != null) {
671 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
674 JSAN.use('cat.util');
675 cat.util.show_in_opac( ids );
677 alert('Error in bill2.js, handle_opac: ' + E);
681 function handle_copy_details() {
684 for (var i = 0; i < g.bill_list_selection.length; i++) {
685 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
686 if (typeof my_acp != 'undefined' && my_acp != null) {
687 ids.push( my_acp.barcode() );
690 JSAN.use('circ.util');
691 circ.util.item_details_new( ids );
693 alert('Error in bill2.js, handle_opac: ' + E);
697 function handle_details() {
698 JSAN.use('util.window'); var win = new util.window();
699 for (var i = 0; i < g.bill_list_selection.length; i++) {
700 var my_xulG = win.open(
701 urls.XUL_PATRON_BILL_DETAILS,
702 'test_billdetails_' + g.bill_list_selection[i],
705 'patron_id' : g.patron_id,
706 'mbts_id' : g.bill_list_selection[i],
707 'refresh' : function() {
709 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
711 'new_tab' : xulG.new_tab,
712 'url_prefix' : xulG.url_prefix
718 function print_bills() {
720 var template = 'bills_historical'; if (xul_param('current')) template = 'bills_current';
721 JSAN.use('patron.util');
722 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
725 'printer_context' : 'receipt',
726 'template' : template
728 g.bill_list.print(params);
730 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
734 function distribute_payment() {
736 JSAN.use('util.money');
737 var tb = $('payment');
738 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
739 tb.setAttribute('value', tb.value );
740 var total = util.money.dollars_float_to_cents_integer( tb.value );
741 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
742 var retrieve_ids = g.bill_list.dump_retrieve_ids();
743 for (var i = 0; i < retrieve_ids.length; i++) {
744 var row_params = g.row_map[retrieve_ids[i]];
745 if (g.check_map[retrieve_ids[i]]) {
746 var bill = g.bill_map[retrieve_ids[i]].transaction;
747 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
749 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
752 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
756 row_params.row.my.payment_pending = '0.00';
758 g.bill_list.refresh_row(row_params);
762 alert('Error in bill2.js, distribute_payment(): ' + E);
766 function apply_payment() {
768 var payment_blob = {};
769 JSAN.use('util.window');
770 var win = new util.window();
771 switch($('payment_type').value) {
772 case 'credit_card_payment' :
774 g.data.stash('temp');
775 var my_xulG = win.open(
776 urls.XUL_PATRON_BILL_CC_INFO,
778 'chrome,resizable,modal',
779 {'patron_id': g.patron_id}
781 g.data.stash_retrieve();
782 payment_blob = JSON2js( g.data.temp ); // FIXME - replace with my_xulG and update_modal_xulG, though it looks like we were using that before and moved away from it
784 case 'check_payment' :
786 g.data.stash('temp');
787 var my_xulG = win.open(
788 urls.XUL_PATRON_BILL_CHECK_INFO,
790 'chrome,resizable,modal'
792 g.data.stash_retrieve();
793 payment_blob = JSON2js( g.data.temp );
797 (typeof payment_blob == 'undefined') ||
799 payment_blob.cancelled=='true'
801 alert( $('commonStrings').getString('common.cancelled') );
804 payment_blob.userid = g.patron_id;
805 payment_blob.note = payment_blob.note || '';
806 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
807 payment_blob.payment_type = $('payment_type').value;
808 var tally_blob = tally_pending();
809 payment_blob.payments = tally_blob.payments;
810 // Handle patron credit
811 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
812 if ( $('convert_change_to_credit').checked ) {
813 // No need to convert credit into credit, handled automatically
814 payment_blob.patron_credit = '0.00';
816 // Cashing out extra credit as change
817 payment_blob.patron_credit = 0 - tally_blob.change;
819 } else if ( $('convert_change_to_credit').checked ) {
820 // Saving change from a non-credit payment as patron credit on server
821 payment_blob.patron_credit = tally_blob.change;
823 payment_blob.patron_credit = '0.00';
825 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
826 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
829 if ( pay( payment_blob ) ) {
831 $('payment').value = ''; $('payment').select(); $('payment').focus();
832 refresh({'clear_voided_summary':true});
833 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
834 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
835 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
839 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
840 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
841 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
842 if (no_print_prompting) {
843 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
845 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
846 g.data.stash_retrieve();
847 var template = 'bill_payment';
848 JSAN.use('patron.util'); JSAN.use('util.functional');
851 'lib' : g.data.hash.aou[ ses('ws_ou') ],
852 'staff' : ses('staff'),
853 'header' : g.data.print_list_templates[template].header,
854 'line_item' : g.data.print_list_templates[template].line_item,
855 'footer' : g.data.print_list_templates[template].footer,
856 'type' : g.data.print_list_templates[template].type,
857 'list' : util.functional.map_list(
858 payment_blob.payments,
863 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
864 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
865 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
866 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
870 'data' : g.previous_summary
872 g.error.sdump('D_DEBUG',js2JSON(params));
873 if ($('printer_prompt').hasAttribute('checked')) {
874 if ($('printer_prompt').getAttribute('checked')) {
875 params.no_prompt = false;
877 params.no_prompt = true;
880 params.no_prompt = true;
882 JSAN.use('util.print'); var print = new util.print('receipt');
883 for (var i = 0; i < $('num_of_receipts').value; i++) {
884 print.tree_list( params );
887 g.error.standard_unexpected_error_alert('bill receipt', E);
891 alert('Error in bill2.js, apply_payment(): ' + E);
895 function pay(payment_blob) {
897 var x = $('annotate_payment');
898 if (x && x.checked && (! payment_blob.note)) {
899 payment_blob.note = window.prompt(
900 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
902 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
905 g.previous_summary = {
906 original_balance : $('tb_total_owed').value,
907 voided_balance : $('currently_voided').value,
908 payment_received : $('payment').value,
909 payment_applied : $('pending_payment').value,
910 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
911 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
912 new_balance : util.money.cents_as_dollars(
913 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
914 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
916 payment_type : $('payment_type').getAttribute('label'),
917 note : payment_blob.note
919 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
920 if (typeof robj.ilsevent != 'undefined') {
921 switch(robj.textcode) {
922 case 'SUCCESS' : return true; break;
923 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
924 case 'INVALID_USER_XACT_ID' :
925 refresh(); default_focus();
926 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
927 default: throw(robj); break;
932 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
937 function refresh(params) {
939 if (params && params.clear_voided_summary) {
940 g.data.voided_billings = []; g.data.stash('voided_billings');
944 retrieve_mbts_for_list();
946 distribute_payment();
948 alert('Error in bill2.js, refresh(): ' + E);
952 function void_all_billings(mobts_id) {
954 JSAN.use('util.functional');
956 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
957 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
959 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
961 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
964 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
965 sum = util.money.cents_as_dollars( sum );
967 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
968 var r = g.error.yns_alert(msg,
969 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
970 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
971 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
972 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
974 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
976 switch(Number(robj.ilsevent)) {
977 case 5000 /* PERM_FAILURE */:
981 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
987 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
988 for (var i = 0; i < mb_list.length; i++) {
989 g.data.voided_billings.push( mb_list[i] );
991 g.data.stash('voided_billings');
994 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
998 function refresh_patron() {
999 JSAN.use('patron.util'); JSAN.use('util.money');
1000 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
1001 var au_obj = req.getResultObject();
1002 if (typeof au_obj.ilsevent == 'undefined') {
1004 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));