3 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
4 JSAN.errorLevel = "die"; // none, warn, or die
5 JSAN.addRepository('/xul/server/');
7 JSAN.use('util.error'); g.error = new util.error();
8 JSAN.use('util.network'); g.network = new util.network();
10 JSAN.use('util.money');
11 JSAN.use('util.widgets');
12 JSAN.use('patron.util');
13 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
14 g.data.voided_billings = []; g.data.stash('voided_billings');
16 g.error.sdump('D_TRACE','my_init() for bill2.xul');
17 window.bill_event_listeners = new EventListenerList();
19 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
21 g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
23 g.patron_id = xul_param('patron_id');
25 $('circulating_hint').hidden = true;
29 retrieve_mbts_for_list();
33 JSAN.use('util.exec'); var exec = new util.exec(20);
34 exec.on_error = function(E) { alert(E); return true; }
35 exec.timer(g.funcs,100);
37 $('credit_forward').setAttribute('value','???');
41 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));
44 if (g.data.hash.aous['ui.circ.billing.uncheck_bills_and_unfocus_payment_box']) {
47 $('uncheck_all').focus();
61 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
62 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
67 function my_cleanup() {
69 window.bill_event_listeners.removeAll();
70 g.bill_list.cleanup();
73 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
74 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
79 function event_listeners() {
81 window.bill_event_listeners.add($('details'),
87 window.bill_event_listeners.add($('add'),
93 window.bill_event_listeners.add($('voidall'),
99 window.bill_event_listeners.add($('refund'),
105 window.bill_event_listeners.add($('opac'),
111 window.bill_event_listeners.add($('copy_details'),
117 window.bill_event_listeners.add($('payment'),
120 if ($('payment_type').value == 'credit_payment') {
121 JSAN.use('util.money');
122 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
123 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
124 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
125 if (proposed > available) {
126 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
127 ev.target.value = util.money.cents_as_dollars( available );
128 ev.target.setAttribute('value',ev.target.value);
131 distribute_payment();
136 window.bill_event_listeners.add($('payment'),
138 function(ev) { ev.target.select(); },
142 window.bill_event_listeners.add($('payment'),
145 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
146 distribute_payment();
147 $('apply_payment_btn').focus();
152 window.bill_event_listeners.add($('bill_patron_btn'),
155 JSAN.use('util.window'); var win = new util.window();
156 var my_xulG = win.open(
157 urls.XUL_PATRON_BILL_WIZARD,
159 'chrome,resizable,modal',
160 { 'patron_id' : g.patron_id }
162 if (my_xulG.xact_id) {
163 g.funcs.push( gen_list_append_func( my_xulG.xact_id ) );
164 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
170 window.bill_event_listeners.add($('bill_history_btn'),
173 xulG.display_window.g.patron.right_deck.reset_iframe(
174 urls.XUL_PATRON_BILL_HISTORY,
177 'patron_id' : g.patron_id,
178 'refresh' : function() { refresh(); },
179 'new_tab' : xulG.new_tab,
180 'url_prefix' : xulG.url_prefix
187 window.bill_event_listeners.add($('convert_change_to_credit'),
190 if (ev.target.checked) {
191 addCSSClass( $('change_due'), 'change_to_credit' );
193 removeCSSClass( $('change_due'), 'change_to_credit' );
199 window.bill_event_listeners.add($('apply_payment_btn'),
203 $('apply_payment_btn').disabled = true;
206 $('apply_payment_btn').disabled = false;
208 alert('Error in bill2.js, apply_payment_btn: ' + E);
215 alert('Error in bill2.js, event_listeners(): ' + E);
219 function $(id) { return document.getElementById(id); }
221 function default_focus() {
222 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
225 function tally_pending() {
228 JSAN.use('util.money');
229 var tb = $('payment');
230 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
231 var payment_pending = 0;
232 var retrieve_ids = g.bill_list.dump_retrieve_ids();
233 for (var i = 0; i < retrieve_ids.length; i++) {
234 var row_params = g.row_map[retrieve_ids[i]];
235 if (g.check_map[retrieve_ids[i]]) {
236 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
237 payment_pending += value;
238 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
241 var change_pending = payment_tendered - payment_pending;
242 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
243 $('pending_change').value = util.money.cents_as_dollars( change_pending );
244 $('change_due').value = util.money.cents_as_dollars( change_pending );
245 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
247 alert('Error in bill2.js, tally_pending(): ' + E);
251 function tally_selected() {
253 JSAN.use('util.money');
254 var selected_billed = 0;
255 var selected_paid = 0;
256 var selected_balance = 0;
258 for (var i = 0; i < g.bill_list_selection.length; i++) {
259 var bill = g.bill_map[g.bill_list_selection[i]];
261 //$('checked_owed').setAttribute('value', '???');
262 //$('checked_billed').setAttribute('value', '???');
263 //$('checked_paid').setAttribute('value', '???');
266 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
267 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
268 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
269 selected_billed += to;
271 selected_balance += bo;
273 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
274 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
275 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
277 alert('Error in bill2.js, tally_selected(): ' + E);
281 function tally_voided() {
283 JSAN.use('util.money');
284 var voided_total = 0;
286 g.data.stash_retrieve();
288 for (var i = 0; i < g.data.voided_billings.length; i++) {
289 var billing = g.data.voided_billings[i];
290 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
293 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
295 alert('Error in bill2.js, tally_voided(): ' + E);
299 function tally_all() {
301 JSAN.use('util.money');
302 var checked_billed = 0;
303 var checked_paid = 0;
304 var checked_balance = 0;
305 var total_billed = 0;
307 var total_balance = 0;
308 var refunds_owed = 0;
310 var retrieve_ids = g.bill_list.dump_retrieve_ids();
311 for (var i = 0; i < retrieve_ids.length; i++) {
312 var bill = g.bill_map[retrieve_ids[i]];
314 $('checked_owed').value = '???';
315 $('checked_owed2').setAttribute('value', '???');
316 $('checked_billed').value = '???';
317 $('checked_paid').value = '???';
318 $('tb_total_owed').value = '???';
319 $('total_owed2').setAttribute('value', '???');
320 $('total_billed').value = '???';
321 $('tb_total_paid').value = '???';
322 $('refunds_owed').setAttribute('value', '???');
325 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
326 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
327 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
331 if ( bo < 0 ) refunds_owed += bo;
332 if (g.check_map[retrieve_ids[i]]) {
333 checked_billed += to;
335 checked_balance += bo;
338 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
339 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
340 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
341 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
342 $('total_billed').value = util.money.cents_as_dollars( total_billed );
343 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
344 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
345 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
346 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
349 alert('Error in bill2.js, tally_all(): ' + E);
353 function handle_refund() {
354 if(g.bill_list_selection.length > 1) {
355 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
357 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
360 var r = g.error.yns_alert(msg,
361 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
362 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
363 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
364 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
366 for (var i = 0; i < g.bill_list_selection.length; i++) {
367 var bill_id = g.bill_list_selection[i];
368 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
369 g.check_map[bill_id] = true;
370 var row_params = g.row_map[bill_id];
371 row_params.row.my.checked = true;
372 g.bill_list.refresh_row(row_params);
376 distribute_payment();
380 function check_all() {
382 for (var i in g.bill_map) {
383 g.check_map[i] = true;
384 var row_params = g.row_map[i];
385 row_params.row.my.checked = true;
386 g.bill_list.refresh_row(row_params);
389 distribute_payment();
391 alert('Error in bill2.js, check_all(): ' + E);
396 function uncheck_all() {
398 for (var i in g.bill_map) {
399 g.check_map[i] = false;
400 var row_params = g.row_map[i];
401 row_params.row.my.checked = false;
402 g.bill_list.refresh_row(row_params);
405 distribute_payment();
407 alert('Error in bill2.js, check_all(): ' + E);
412 function check_all_refunds() {
414 for (var i in g.bill_map) {
415 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
416 g.check_map[i] = true;
417 var row_params = g.row_map[i];
418 row_params.row.my.checked = true;
419 g.bill_list.refresh_row(row_params);
423 distribute_payment();
425 alert('Error in bill2.js, check_all_refunds(): ' + E);
429 function gen_list_append_func(r) {
431 var default_check_state = g.data.hash.aous[
432 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
434 if (typeof r == 'object') {
435 g.row_map[ r.id() ] = g.bill_list.append( {
436 'retrieve_id' : r.id(),
437 'flesh_immediately' : true,
440 'checked' : default_check_state,
446 g.row_map[r] = g.bill_list.append( {
448 'flesh_immediately' : true,
451 'checked' : default_check_state
459 function retrieve_mbts_for_list() {
460 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
461 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
462 if (g.mbts_ids.ilsevent) {
463 switch(Number(g.mbts_ids.ilsevent)) {
464 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
465 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;
467 } else if (g.mbts_ids == null) {
468 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
471 g.mbts_ids.reverse();
473 for (var i = 0; i < g.mbts_ids.length; i++) {
474 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
475 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
480 function init_lists() {
481 JSAN.use('util.list'); JSAN.use('circ.util');
483 g.bill_list_selection = [];
485 g.bill_list = new util.list('bill_tree');
491 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
492 'render' : function(my) { return String( my.checked ) == 'true'; },
495 patron.util.mbts_columns({
496 'mbts_xact_finish' : { 'hidden' : true }
500 'title' : { 'hidden' : false, 'flex' : '3' }
505 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
506 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
507 'render' : function(my) { return my.payment_pending || '0.00'; },
511 'on_select' : function(ev) {
512 JSAN.use('util.functional');
513 g.bill_list_selection = util.functional.map_list(
514 g.bill_list.retrieve_selection(),
515 function(o) { return o.getAttribute('retrieve_id'); }
518 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
519 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
520 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
521 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
522 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
523 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
525 'on_click' : function(ev) {
526 var row = {}; var col = {}; var nobj = {};
527 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
528 if (row.value == -1) return;
529 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
530 if (treeItem.nodeName != 'treeitem') return;
531 var treeRow = treeItem.firstChild;
532 var treeCell = treeRow.firstChild.nextSibling;
533 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
534 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
535 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
537 distribute_payment();
540 'on_sort' : function() {
543 'on_checkbox_toggle' : function(toggle) {
545 var retrieve_ids = g.bill_list.dump_retrieve_ids();
546 for (var i = 0; i < retrieve_ids.length; i++) {
547 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
548 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
552 alert('error in on_checkbox_toggle(): ' + E);
555 'retrieve_row' : function(params) {
557 var id = params.retrieve_id;
558 var row = params.row;
560 function handle_props(row) {
562 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
563 util.widgets.addProperty(params.treeitem_node.firstChild,'refundable');
564 util.widgets.addProperty(params.treeitem_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
566 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
567 $('circulating_hint').hidden = false;
568 util.widgets.addProperty(params.treeitem_node.firstChild,'circulating');
569 util.widgets.addProperty(params.treeitem_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
572 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
573 alert('Error setting list properties in bill2.js: ' + E);
578 if (typeof row.my == 'undefined') row.my = {};
579 if (typeof row.my.mbts == 'undefined' ) {
580 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
581 var blob = req.getResultObject();
582 row.my.mbts = blob.transaction;
583 row.my.circ = blob.circ;
584 row.my.acp = blob.copy;
585 row.my.mvr = blob.record;
586 if (typeof params.on_retrieve == 'function') {
587 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
588 row.my.checked = false;
591 params.on_retrieve(row);
593 g.bill_map[ id ] = blob;
594 g.check_map[ id ] = row.my.checked;
598 if (typeof params.on_retrieve == 'function') {
600 params.on_retrieve(row);
604 if (typeof params.on_retrieve == 'function') {
605 params.on_retrieve(row);
611 alert('Error in bill2.js, retrieve_row(): ' + E);
616 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
617 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
618 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
619 g.bill_list.set_list_actions();
622 function handle_add() {
623 if(g.bill_list_selection.length > 1) {
624 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
626 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
629 var r = g.error.yns_alert(msg,
630 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
631 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
632 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
633 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
635 JSAN.use('util.window');
636 var win = new util.window();
637 for (var i = 0; i < g.bill_list_selection.length; i++) {
639 urls.XUL_PATRON_BILL_WIZARD,
641 'chrome,resizable,modal',
642 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
646 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
650 function handle_void_all() {
651 if(g.bill_list_selection.length > 1) {
652 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
654 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
657 var r = g.error.yns_alert(msg,
658 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
659 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
660 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
661 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
663 for (var i = 0; i < g.bill_list_selection.length; i++) {
664 void_all_billings( g.bill_list_selection[i] );
667 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
668 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
672 function handle_opac() {
675 for (var i = 0; i < g.bill_list_selection.length; i++) {
676 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
677 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
678 if (typeof my_mvr != 'undefined' && my_mvr != null) {
679 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
682 JSAN.use('cat.util');
683 cat.util.show_in_opac( ids );
685 alert('Error in bill2.js, handle_opac: ' + E);
689 function handle_copy_details() {
692 for (var i = 0; i < g.bill_list_selection.length; i++) {
693 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
694 if (typeof my_acp != 'undefined' && my_acp != null) {
695 ids.push( my_acp.barcode() );
698 JSAN.use('circ.util');
699 circ.util.item_details_new( ids );
701 alert('Error in bill2.js, handle_opac: ' + E);
705 function handle_details() {
706 JSAN.use('util.window'); var win = new util.window();
707 for (var i = 0; i < g.bill_list_selection.length; i++) {
708 var my_xulG = win.open(
709 urls.XUL_PATRON_BILL_DETAILS,
710 'test_billdetails_' + g.bill_list_selection[i],
713 'patron_id' : g.patron_id,
714 'mbts_id' : g.bill_list_selection[i],
715 'refresh' : function() {
717 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
719 'new_tab' : xulG.new_tab,
720 'url_prefix' : xulG.url_prefix
726 function print_bills() {
728 var template = 'bills_current';
729 JSAN.use('patron.util');
730 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
733 , 'printer_context' : 'receipt'
734 , 'template' : template
736 grand_total_owed: $('tb_total_owed').value
737 , grand_total_billed: $('total_billed').value
738 , grand_total_paid: $('tb_total_paid').value
742 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
746 function distribute_payment() {
748 JSAN.use('util.money');
749 var tb = $('payment');
750 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
751 tb.setAttribute('value', tb.value );
752 var total = util.money.dollars_float_to_cents_integer( tb.value );
753 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
754 var retrieve_ids = g.bill_list.dump_retrieve_ids();
755 for (var i = 0; i < retrieve_ids.length; i++) {
756 var row_params = g.row_map[retrieve_ids[i]];
757 if (g.check_map[retrieve_ids[i]]) {
758 var bill = g.bill_map[retrieve_ids[i]].transaction;
759 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
761 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
764 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
768 row_params.row.my.payment_pending = '0.00';
770 g.bill_list.refresh_row(row_params);
774 alert('Error in bill2.js, distribute_payment(): ' + E);
778 function apply_payment() {
780 var payment_blob = {};
781 JSAN.use('util.window');
782 var win = new util.window();
783 switch($('payment_type').value) {
784 case 'credit_card_payment' :
786 g.data.stash('temp');
787 var my_xulG = win.open(
788 urls.XUL_PATRON_BILL_CC_INFO,
790 'chrome,resizable,modal',
791 {'patron_id': g.patron_id}
793 g.data.stash_retrieve();
794 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
796 case 'check_payment' :
798 g.data.stash('temp');
799 var my_xulG = win.open(
800 urls.XUL_PATRON_BILL_CHECK_INFO,
802 'chrome,resizable,modal'
804 g.data.stash_retrieve();
805 payment_blob = JSON2js( g.data.temp );
809 (typeof payment_blob == 'undefined') ||
811 payment_blob.cancelled=='true'
813 alert( $('commonStrings').getString('common.cancelled') );
816 payment_blob.userid = g.patron_id;
817 payment_blob.note = payment_blob.note || '';
818 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
819 payment_blob.payment_type = $('payment_type').value;
820 var tally_blob = tally_pending();
821 payment_blob.payments = tally_blob.payments;
822 // Handle patron credit
823 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
824 if ( $('convert_change_to_credit').checked ) {
825 // No need to convert credit into credit, handled automatically
826 payment_blob.patron_credit = '0.00';
828 // Cashing out extra credit as change
829 payment_blob.patron_credit = 0 - tally_blob.change;
831 } else if ( $('convert_change_to_credit').checked ) {
832 // Saving change from a non-credit payment as patron credit on server
833 payment_blob.patron_credit = tally_blob.change;
835 payment_blob.patron_credit = '0.00';
837 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
838 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
841 if ( pay( payment_blob ) ) {
843 $('payment').value = ''; $('payment').select(); $('payment').focus();
844 refresh({'clear_voided_summary':true});
845 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
846 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
847 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
851 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
852 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
853 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
854 if (no_print_prompting) {
855 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
857 g.data.stash_retrieve();
858 var template = 'bill_payment';
859 JSAN.use('patron.util'); JSAN.use('util.functional');
862 'lib' : g.data.hash.aou[ ses('ws_ou') ],
863 'staff' : ses('staff'),
864 'header' : g.data.print_list_templates[template].header,
865 'line_item' : g.data.print_list_templates[template].line_item,
866 'footer' : g.data.print_list_templates[template].footer,
867 'type' : g.data.print_list_templates[template].type,
868 'list' : util.functional.map_list(
869 payment_blob.payments,
874 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
875 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
876 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
877 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
881 'data' : g.previous_summary,
882 'context' : g.data.print_list_templates[template].context,
884 g.error.sdump('D_DEBUG',js2JSON(params));
885 if ($('printer_prompt').hasAttribute('checked')) {
886 if ($('printer_prompt').getAttribute('checked')) {
887 params.no_prompt = false;
889 params.no_prompt = true;
892 params.no_prompt = true;
894 JSAN.use('util.print'); var print = new util.print('receipt');
895 for (var i = 0; i < $('num_of_receipts').value; i++) {
896 print.tree_list( params );
899 g.error.standard_unexpected_error_alert('bill receipt', E);
903 alert('Error in bill2.js, apply_payment(): ' + E);
907 function pay(payment_blob) {
909 var x = $('annotate_payment');
910 if (x && x.checked && (! payment_blob.note)) {
911 payment_blob.note = window.prompt(
912 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
914 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
917 g.previous_summary = {
918 original_balance : $('tb_total_owed').value,
919 voided_balance : $('currently_voided').value,
920 payment_received : $('payment').value,
921 payment_applied : $('pending_payment').value,
922 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
923 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
924 new_balance : util.money.cents_as_dollars(
925 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
926 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
928 payment_type : $('payment_type').getAttribute('label'),
929 note : payment_blob.note
931 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
935 $('circStrings').getFormattedString(
936 robj && robj.payments
937 ? 'staff.circ.work_log_payment_attempt.success.message'
938 : 'staff.circ.work_log_payment_attempt.failure.message',
940 ses('staff_usrname'), // 1 - Staff Username
941 g.patron.family_name(), // 2 - Patron Family
942 g.patron.card().barcode(), // 3 - Patron Barcode
943 g.previous_summary.original_balance, // 4 - Original Balance
944 g.previous_summary.voided_balance, // 5 - Voided Balance
945 g.previous_summary.payment_received, // 6 - Payment Received
946 g.previous_summary.payment_applied, // 7 - Payment Applied
947 g.previous_summary.change_given, // 8 - Change Given
948 g.previous_summary.credit_given, // 9 - Credit Given
949 g.previous_summary.new_balance, // 10 - New Balance
950 g.previous_summary.payment_type, // 11 - Payment Type
951 g.previous_summary.note, // 12 - Note
952 robj && robj.textcode ? robj.textcode : robj // 13 - API call result
955 'au_id' : g.patron.id(),
956 'au_family_name' : g.patron.family_name(),
957 'au_barcode' : g.patron.card().barcode()
961 alert('Error logging payment in bill2.js: ' + E);
964 if (typeof robj.ilsevent != 'undefined') {
965 switch(robj.textcode) {
966 case 'SUCCESS' : return true; break;
967 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
968 case 'INVALID_USER_XACT_ID' :
969 refresh(); default_focus();
970 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
971 default: throw(robj); break;
976 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
981 function refresh(params) {
983 if (params && params.clear_voided_summary) {
984 g.data.voided_billings = []; g.data.stash('voided_billings');
988 retrieve_mbts_for_list();
990 distribute_payment();
992 alert('Error in bill2.js, refresh(): ' + E);
996 function void_all_billings(mobts_id) {
998 JSAN.use('util.functional');
1000 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
1001 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
1003 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
1005 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
1008 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
1009 sum = util.money.cents_as_dollars( sum );
1011 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
1012 var r = g.error.yns_alert(msg,
1013 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
1014 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
1015 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
1016 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
1018 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
1019 if (robj.ilsevent) {
1020 switch(Number(robj.ilsevent)) {
1021 case 5000 /* PERM_FAILURE */:
1025 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
1031 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
1032 for (var i = 0; i < mb_list.length; i++) {
1033 g.data.voided_billings.push( mb_list[i] );
1035 g.data.stash('voided_billings');
1038 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
1042 function refresh_patron() {
1043 JSAN.use('patron.util'); JSAN.use('util.money');
1044 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
1045 var au_obj = req.getResultObject();
1046 if (typeof au_obj.ilsevent == 'undefined') {
1048 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));