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['circ.disable_patron_credit']) {
45 var nodes = document.getElementsByClassName('hide_patron_credit');
46 for (var i = 0; i < nodes.length; i++)
47 nodes[i].setAttribute('hidden', true);
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 my_cleanup() {
75 window.bill_event_listeners.removeAll();
76 g.bill_list.cleanup();
79 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
80 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
85 function event_listeners() {
87 window.bill_event_listeners.add($('details'),
93 window.bill_event_listeners.add($('add'),
99 window.bill_event_listeners.add($('voidall'),
105 window.bill_event_listeners.add($('refund'),
111 window.bill_event_listeners.add($('opac'),
117 window.bill_event_listeners.add($('copy_details'),
123 window.bill_event_listeners.add($('payment'),
126 if ($('payment_type').value == 'credit_payment') {
127 JSAN.use('util.money');
128 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
129 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
130 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
131 if (proposed > available) {
132 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
133 ev.target.value = util.money.cents_as_dollars( available );
134 ev.target.setAttribute('value',ev.target.value);
137 distribute_payment();
142 window.bill_event_listeners.add($('payment'),
144 function(ev) { ev.target.select(); },
148 window.bill_event_listeners.add($('payment'),
151 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
152 distribute_payment();
153 $('apply_payment_btn').focus();
158 window.bill_event_listeners.add($('bill_patron_btn'),
161 JSAN.use('util.window'); var win = new util.window();
162 var my_xulG = win.open(
163 urls.XUL_PATRON_BILL_WIZARD,
165 'chrome,resizable,modal',
166 { 'patron_id' : g.patron_id }
168 if (my_xulG.xact_id) {
169 g.funcs.push( gen_list_append_func( my_xulG.xact_id ) );
170 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
176 window.bill_event_listeners.add($('bill_history_btn'),
179 xulG.display_window.g.patron.right_deck.reset_iframe(
180 urls.XUL_PATRON_BILL_HISTORY,
183 'patron_id' : g.patron_id,
184 'refresh' : function() { refresh(); },
185 'new_tab' : xulG.new_tab,
186 'url_prefix' : xulG.url_prefix
193 window.bill_event_listeners.add($('convert_change_to_credit'),
196 if (ev.target.checked) {
197 addCSSClass( $('change_due'), 'change_to_credit' );
199 removeCSSClass( $('change_due'), 'change_to_credit' );
205 window.bill_event_listeners.add($('apply_payment_btn'),
209 $('apply_payment_btn').disabled = true;
212 $('apply_payment_btn').disabled = false;
214 alert('Error in bill2.js, apply_payment_btn: ' + E);
221 alert('Error in bill2.js, event_listeners(): ' + E);
225 function $(id) { return document.getElementById(id); }
227 function default_focus() {
228 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
231 function tally_pending() {
234 JSAN.use('util.money');
235 var tb = $('payment');
236 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
237 var payment_pending = 0;
238 var retrieve_ids = g.bill_list.dump_retrieve_ids();
239 for (var i = 0; i < retrieve_ids.length; i++) {
240 var row_params = g.row_map[retrieve_ids[i]];
241 if (g.check_map[retrieve_ids[i]]) {
242 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
243 payment_pending += value;
244 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
247 var change_pending = payment_tendered - payment_pending;
248 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
249 $('pending_change').value = util.money.cents_as_dollars( change_pending );
250 $('change_due').value = util.money.cents_as_dollars( change_pending );
251 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
253 alert('Error in bill2.js, tally_pending(): ' + E);
257 function tally_selected() {
259 JSAN.use('util.money');
260 var selected_billed = 0;
261 var selected_paid = 0;
262 var selected_balance = 0;
264 for (var i = 0; i < g.bill_list_selection.length; i++) {
265 var bill = g.bill_map[g.bill_list_selection[i]];
267 //$('checked_owed').setAttribute('value', '???');
268 //$('checked_billed').setAttribute('value', '???');
269 //$('checked_paid').setAttribute('value', '???');
272 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
273 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
274 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
275 selected_billed += to;
277 selected_balance += bo;
279 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
280 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
281 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
283 alert('Error in bill2.js, tally_selected(): ' + E);
287 function tally_voided() {
289 JSAN.use('util.money');
290 var voided_total = 0;
292 g.data.stash_retrieve();
294 for (var i = 0; i < g.data.voided_billings.length; i++) {
295 var billing = g.data.voided_billings[i];
296 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
299 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
301 alert('Error in bill2.js, tally_voided(): ' + E);
305 function tally_all() {
307 JSAN.use('util.money');
308 var checked_billed = 0;
309 var checked_paid = 0;
310 var checked_balance = 0;
311 var total_billed = 0;
313 var total_balance = 0;
314 var refunds_owed = 0;
316 var retrieve_ids = g.bill_list.dump_retrieve_ids();
317 for (var i = 0; i < retrieve_ids.length; i++) {
318 var bill = g.bill_map[retrieve_ids[i]];
320 $('checked_owed').value = '???';
321 $('checked_owed2').setAttribute('value', '???');
322 $('checked_billed').value = '???';
323 $('checked_paid').value = '???';
324 $('tb_total_owed').value = '???';
325 $('total_owed2').setAttribute('value', '???');
326 $('total_billed').value = '???';
327 $('tb_total_paid').value = '???';
328 $('refunds_owed').setAttribute('value', '???');
331 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
332 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
333 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
337 if ( bo < 0 ) refunds_owed += bo;
338 if (g.check_map[retrieve_ids[i]]) {
339 checked_billed += to;
341 checked_balance += bo;
344 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
345 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
346 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
347 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
348 $('total_billed').value = util.money.cents_as_dollars( total_billed );
349 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
350 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
351 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
352 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
355 alert('Error in bill2.js, tally_all(): ' + E);
359 function handle_refund() {
360 if(g.bill_list_selection.length > 1) {
361 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
363 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
366 var r = g.error.yns_alert(msg,
367 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
368 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
369 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
370 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
372 for (var i = 0; i < g.bill_list_selection.length; i++) {
373 var bill_id = g.bill_list_selection[i];
374 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
375 g.check_map[bill_id] = true;
376 var row_params = g.row_map[bill_id];
377 row_params.row.my.checked = true;
378 g.bill_list.refresh_row(row_params);
382 distribute_payment();
386 function check_all() {
388 for (var i in g.bill_map) {
389 g.check_map[i] = true;
390 var row_params = g.row_map[i];
391 row_params.row.my.checked = true;
392 g.bill_list.refresh_row(row_params);
395 distribute_payment();
397 alert('Error in bill2.js, check_all(): ' + E);
402 function uncheck_all() {
404 for (var i in g.bill_map) {
405 g.check_map[i] = false;
406 var row_params = g.row_map[i];
407 row_params.row.my.checked = false;
408 g.bill_list.refresh_row(row_params);
411 distribute_payment();
413 alert('Error in bill2.js, check_all(): ' + E);
418 function check_all_refunds() {
420 for (var i in g.bill_map) {
421 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
422 g.check_map[i] = true;
423 var row_params = g.row_map[i];
424 row_params.row.my.checked = true;
425 g.bill_list.refresh_row(row_params);
429 distribute_payment();
431 alert('Error in bill2.js, check_all_refunds(): ' + E);
435 function gen_list_append_func(r) {
437 var default_check_state = g.data.hash.aous[
438 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
440 if (typeof r == 'object') {
441 g.row_map[ r.id() ] = g.bill_list.append( {
442 'retrieve_id' : r.id(),
443 'flesh_immediately' : true,
446 'checked' : default_check_state,
452 g.row_map[r] = g.bill_list.append( {
454 'flesh_immediately' : true,
457 'checked' : default_check_state
465 function retrieve_mbts_for_list() {
466 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
467 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
468 if (g.mbts_ids.ilsevent) {
469 switch(Number(g.mbts_ids.ilsevent)) {
470 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
471 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;
473 } else if (g.mbts_ids == null) {
474 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
477 g.mbts_ids.reverse();
479 for (var i = 0; i < g.mbts_ids.length; i++) {
480 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
481 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
486 function init_lists() {
487 JSAN.use('util.list'); JSAN.use('circ.util');
489 g.bill_list_selection = [];
491 g.bill_list = new util.list('bill_tree');
497 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
498 'render' : function(my) { return String( my.checked ) == 'true'; },
501 patron.util.mbts_columns({
502 'mbts_xact_finish' : { 'hidden' : true }
506 'title' : { 'hidden' : false, 'flex' : '3' }
511 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
512 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
513 'render' : function(my) { return my.payment_pending || '0.00'; },
517 'on_select' : function(ev) {
518 JSAN.use('util.functional');
519 g.bill_list_selection = util.functional.map_list(
520 g.bill_list.retrieve_selection(),
521 function(o) { return o.getAttribute('retrieve_id'); }
524 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
525 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
526 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
527 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
528 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
529 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
531 'on_click' : function(ev) {
532 var row = {}; var col = {}; var nobj = {};
533 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
534 if (row.value == -1) return;
535 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
536 if (treeItem.nodeName != 'treeitem') return;
537 var treeRow = treeItem.firstChild;
538 var treeCell = treeRow.firstChild.nextSibling;
539 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
540 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
541 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
543 distribute_payment();
546 'on_sort' : function() {
549 'on_checkbox_toggle' : function(toggle) {
551 var retrieve_ids = g.bill_list.dump_retrieve_ids();
552 for (var i = 0; i < retrieve_ids.length; i++) {
553 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
554 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
558 alert('error in on_checkbox_toggle(): ' + E);
561 'retrieve_row' : function(params) {
563 var id = params.retrieve_id;
564 var row = params.row;
566 function handle_props(row) {
568 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
569 util.widgets.addProperty(params.treeitem_node.firstChild,'refundable');
570 util.widgets.addProperty(params.treeitem_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
572 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
573 var style_type = 'circulating';
574 var stop_fines = row.my.circ.stop_fines() || '';
576 // we have custom syling for these stop-fines reasons
577 if (stop_fines.match(/LOST|LONGOVERDUE/))
578 style_type = stop_fines.toLowerCase();
580 $(style_type + '_hint').hidden = false;
582 // style every cell in the row
583 for (var n in params.treeitem_node.firstChild.childNodes) {
585 util.widgets.addProperty(
586 params.treeitem_node.firstChild.childNodes[n],
593 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
594 alert('Error setting list properties in bill2.js: ' + E);
599 if (typeof row.my == 'undefined') row.my = {};
600 if (typeof row.my.mbts == 'undefined' ) {
601 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
602 var blob = req.getResultObject();
603 row.my.mbts = blob.transaction;
604 row.my.circ = blob.circ;
605 row.my.acp = blob.copy;
606 row.my.mvr = blob.record;
607 if (typeof params.on_retrieve == 'function') {
608 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
609 row.my.checked = false;
612 params.on_retrieve(row);
614 g.bill_map[ id ] = blob;
615 g.check_map[ id ] = row.my.checked;
619 if (typeof params.on_retrieve == 'function') {
621 params.on_retrieve(row);
625 if (typeof params.on_retrieve == 'function') {
626 params.on_retrieve(row);
632 alert('Error in bill2.js, retrieve_row(): ' + E);
637 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
638 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
639 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
640 g.bill_list.set_list_actions();
643 function handle_add() {
644 if(g.bill_list_selection.length > 1) {
645 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
647 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
650 var r = g.error.yns_alert(msg,
651 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
652 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
653 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
654 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
656 JSAN.use('util.window');
657 var win = new util.window();
658 for (var i = 0; i < g.bill_list_selection.length; i++) {
660 urls.XUL_PATRON_BILL_WIZARD,
662 'chrome,resizable,modal',
663 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
667 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
671 function handle_void_all() {
672 if(g.bill_list_selection.length > 1) {
673 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
675 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
678 var r = g.error.yns_alert(msg,
679 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
680 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
681 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
682 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
684 for (var i = 0; i < g.bill_list_selection.length; i++) {
685 void_all_billings( g.bill_list_selection[i] );
688 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
689 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
693 function handle_opac() {
696 for (var i = 0; i < g.bill_list_selection.length; i++) {
697 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
698 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
699 if (typeof my_mvr != 'undefined' && my_mvr != null) {
700 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
703 JSAN.use('cat.util');
704 cat.util.show_in_opac( ids );
706 alert('Error in bill2.js, handle_opac: ' + E);
710 function handle_copy_details() {
713 for (var i = 0; i < g.bill_list_selection.length; i++) {
714 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
715 if (typeof my_acp != 'undefined' && my_acp != null) {
716 ids.push( my_acp.barcode() );
719 JSAN.use('circ.util');
720 circ.util.item_details_new( ids );
722 alert('Error in bill2.js, handle_opac: ' + E);
726 function handle_details() {
727 JSAN.use('util.window'); var win = new util.window();
728 for (var i = 0; i < g.bill_list_selection.length; i++) {
729 var my_xulG = win.open(
730 urls.XUL_PATRON_BILL_DETAILS,
731 'test_billdetails_' + g.bill_list_selection[i],
734 'patron_id' : g.patron_id,
735 'mbts_id' : g.bill_list_selection[i],
736 'refresh' : function() {
738 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
740 'new_tab' : xulG.new_tab,
741 'url_prefix' : xulG.url_prefix
747 function print_bills() {
749 var template = 'bills_current';
750 JSAN.use('patron.util');
751 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
754 , 'printer_context' : 'receipt'
755 , 'template' : template
757 grand_total_owed: $('tb_total_owed').value
758 , grand_total_billed: $('total_billed').value
759 , grand_total_paid: $('tb_total_paid').value
763 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
767 function distribute_payment() {
769 JSAN.use('util.money');
770 var tb = $('payment');
771 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
772 tb.setAttribute('value', tb.value );
773 var total = util.money.dollars_float_to_cents_integer( tb.value );
774 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
775 var retrieve_ids = g.bill_list.dump_retrieve_ids();
776 for (var i = 0; i < retrieve_ids.length; i++) {
777 var row_params = g.row_map[retrieve_ids[i]];
778 if (g.check_map[retrieve_ids[i]]) {
779 var bill = g.bill_map[retrieve_ids[i]].transaction;
780 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
782 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
785 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
789 row_params.row.my.payment_pending = '0.00';
791 g.bill_list.refresh_row(row_params);
795 alert('Error in bill2.js, distribute_payment(): ' + E);
799 function apply_payment() {
801 var payment_blob = {};
802 JSAN.use('util.window');
803 var win = new util.window();
804 switch($('payment_type').value) {
805 case 'credit_card_payment' :
807 g.data.stash('temp');
808 var my_xulG = win.open(
809 urls.XUL_PATRON_BILL_CC_INFO,
811 'chrome,resizable,modal',
812 {'patron_id': g.patron_id}
814 g.data.stash_retrieve();
815 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
817 case 'check_payment' :
819 g.data.stash('temp');
820 var my_xulG = win.open(
821 urls.XUL_PATRON_BILL_CHECK_INFO,
823 'chrome,resizable,modal'
825 g.data.stash_retrieve();
826 payment_blob = JSON2js( g.data.temp );
830 (typeof payment_blob == 'undefined') ||
832 payment_blob.cancelled=='true'
834 alert( $('commonStrings').getString('common.cancelled') );
837 payment_blob.userid = g.patron_id;
838 payment_blob.note = payment_blob.note || '';
839 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
840 payment_blob.payment_type = $('payment_type').value;
841 var tally_blob = tally_pending();
842 payment_blob.payments = tally_blob.payments;
843 // Handle patron credit
844 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
845 if ( $('convert_change_to_credit').checked ) {
846 // No need to convert credit into credit, handled automatically
847 payment_blob.patron_credit = '0.00';
849 // Cashing out extra credit as change
850 payment_blob.patron_credit = 0 - tally_blob.change;
852 } else if ( $('convert_change_to_credit').checked ) {
853 // Saving change from a non-credit payment as patron credit on server
854 payment_blob.patron_credit = tally_blob.change;
856 payment_blob.patron_credit = '0.00';
858 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
859 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
862 if ( pay( payment_blob ) ) {
864 $('payment').value = ''; $('payment').select(); $('payment').focus();
865 refresh({'clear_voided_summary':true});
866 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
867 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
868 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
872 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
873 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
874 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
875 if (no_print_prompting) {
876 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
878 g.data.stash_retrieve();
879 var template = 'bill_payment';
880 JSAN.use('patron.util'); JSAN.use('util.functional');
883 'lib' : g.data.hash.aou[ ses('ws_ou') ],
884 'staff' : ses('staff'),
885 'header' : g.data.print_list_templates[template].header,
886 'line_item' : g.data.print_list_templates[template].line_item,
887 'footer' : g.data.print_list_templates[template].footer,
888 'type' : g.data.print_list_templates[template].type,
889 'list' : util.functional.map_list(
890 payment_blob.payments,
895 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
896 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
897 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
898 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
902 'data' : g.previous_summary,
903 'context' : g.data.print_list_templates[template].context,
905 g.error.sdump('D_DEBUG',js2JSON(params));
906 if ($('printer_prompt').hasAttribute('checked')) {
907 if ($('printer_prompt').getAttribute('checked')) {
908 params.no_prompt = false;
910 params.no_prompt = true;
913 params.no_prompt = true;
915 JSAN.use('util.print'); var print = new util.print('receipt');
916 for (var i = 0; i < $('num_of_receipts').value; i++) {
917 print.tree_list( params );
920 g.error.standard_unexpected_error_alert('bill receipt', E);
924 alert('Error in bill2.js, apply_payment(): ' + E);
928 function pay(payment_blob) {
930 var x = $('annotate_payment');
931 if (x && x.checked && (! payment_blob.note)) {
932 payment_blob.note = window.prompt(
933 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
935 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
938 g.previous_summary = {
939 original_balance : $('tb_total_owed').value,
940 voided_balance : $('currently_voided').value,
941 payment_received : $('payment').value,
942 payment_applied : $('pending_payment').value,
943 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
944 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
945 new_balance : util.money.cents_as_dollars(
946 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
947 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
949 payment_type : $('payment_type').getAttribute('label'),
950 note : payment_blob.note
952 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
956 $('circStrings').getFormattedString(
957 robj && robj.payments
958 ? 'staff.circ.work_log_payment_attempt.success.message'
959 : 'staff.circ.work_log_payment_attempt.failure.message',
961 ses('staff_usrname'), // 1 - Staff Username
962 g.patron.family_name(), // 2 - Patron Family
963 g.patron.card().barcode(), // 3 - Patron Barcode
964 g.previous_summary.original_balance, // 4 - Original Balance
965 g.previous_summary.voided_balance, // 5 - Voided Balance
966 g.previous_summary.payment_received, // 6 - Payment Received
967 g.previous_summary.payment_applied, // 7 - Payment Applied
968 g.previous_summary.change_given, // 8 - Change Given
969 g.previous_summary.credit_given, // 9 - Credit Given
970 g.previous_summary.new_balance, // 10 - New Balance
971 g.previous_summary.payment_type, // 11 - Payment Type
972 g.previous_summary.note, // 12 - Note
973 robj && robj.textcode ? robj.textcode : robj // 13 - API call result
976 'au_id' : g.patron.id(),
977 'au_family_name' : g.patron.family_name(),
978 'au_barcode' : g.patron.card().barcode()
982 alert('Error logging payment in bill2.js: ' + E);
985 if (typeof robj.ilsevent != 'undefined') {
986 switch(robj.textcode) {
987 case 'SUCCESS' : return true; break;
988 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
989 case 'INVALID_USER_XACT_ID' :
990 refresh(); default_focus();
991 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
992 case 'PATRON_CREDIT_DISABLED' :
999 default: throw(robj); break;
1004 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
1009 function refresh(params) {
1011 if (params && params.clear_voided_summary) {
1012 g.data.voided_billings = []; g.data.stash('voided_billings');
1015 g.bill_list.clear();
1016 retrieve_mbts_for_list();
1018 distribute_payment();
1020 alert('Error in bill2.js, refresh(): ' + E);
1024 function void_all_billings(mobts_id) {
1026 JSAN.use('util.functional');
1028 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
1029 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
1031 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
1033 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
1036 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
1037 sum = util.money.cents_as_dollars( sum );
1039 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
1040 var r = g.error.yns_alert(msg,
1041 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
1042 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
1043 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
1044 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
1046 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
1047 if (robj.ilsevent) {
1048 switch(Number(robj.ilsevent)) {
1049 case 5000 /* PERM_FAILURE */:
1053 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
1059 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
1060 for (var i = 0; i < mb_list.length; i++) {
1061 g.data.voided_billings.push( mb_list[i] );
1063 g.data.stash('voided_billings');
1066 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
1070 function refresh_patron() {
1071 JSAN.use('patron.util'); JSAN.use('util.money');
1072 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
1073 var au_obj = req.getResultObject();
1074 if (typeof au_obj.ilsevent == 'undefined') {
1076 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));