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');
18 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
20 g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
22 g.patron_id = xul_param('patron_id');
24 $('circulating_hint').hidden = true;
28 retrieve_mbts_for_list();
32 JSAN.use('util.exec'); var exec = new util.exec(20);
33 exec.on_error = function(E) { alert(E); return true; }
34 exec.timer(g.funcs,100);
36 $('credit_forward').setAttribute('value','???');
40 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));
43 if (g.data.hash.aous['ui.circ.billing.uncheck_bills_and_unfocus_payment_box']) {
46 $('uncheck_all').focus();
60 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
61 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
66 function event_listeners() {
68 $('details').addEventListener(
74 $('add').addEventListener(
80 $('voidall').addEventListener(
86 $('refund').addEventListener(
92 $('opac').addEventListener(
98 $('copy_details').addEventListener(
104 $('payment').addEventListener(
107 if ($('payment_type').value == 'credit_payment') {
108 JSAN.use('util.money');
109 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
110 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
111 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
112 if (proposed > available) {
113 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
114 ev.target.value = util.money.cents_as_dollars( available );
115 ev.target.setAttribute('value',ev.target.value);
118 distribute_payment();
123 $('payment').addEventListener(
125 function(ev) { ev.target.select(); },
129 $('payment').addEventListener(
132 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
133 distribute_payment();
134 $('apply_payment_btn').focus();
139 $('bill_patron_btn').addEventListener(
142 JSAN.use('util.window'); var win = new util.window();
143 var my_xulG = win.open(
144 urls.XUL_PATRON_BILL_WIZARD,
146 'chrome,resizable,modal',
147 { 'patron_id' : g.patron_id }
149 if (my_xulG.xact_id) {
150 g.funcs.push( gen_list_append_func( my_xulG.xact_id ) );
151 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
157 $('bill_history_btn').addEventListener(
160 xulG.display_window.g.patron.right_deck.reset_iframe(
161 urls.XUL_PATRON_BILL_HISTORY,
164 'patron_id' : g.patron_id,
165 'refresh' : function() { refresh(); },
166 'new_tab' : xulG.new_tab,
167 'url_prefix' : xulG.url_prefix
174 $('convert_change_to_credit').addEventListener(
177 if (ev.target.checked) {
178 addCSSClass( $('change_due'), 'change_to_credit' );
180 removeCSSClass( $('change_due'), 'change_to_credit' );
186 $('apply_payment_btn').addEventListener(
190 $('apply_payment_btn').disabled = true;
193 $('apply_payment_btn').disabled = false;
195 alert('Error in bill2.js, apply_payment_btn: ' + E);
202 alert('Error in bill2.js, event_listeners(): ' + E);
206 function $(id) { return document.getElementById(id); }
208 function default_focus() {
209 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
212 function tally_pending() {
215 JSAN.use('util.money');
216 var tb = $('payment');
217 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
218 var payment_pending = 0;
219 var retrieve_ids = g.bill_list.dump_retrieve_ids();
220 for (var i = 0; i < retrieve_ids.length; i++) {
221 var row_params = g.row_map[retrieve_ids[i]];
222 if (g.check_map[retrieve_ids[i]]) {
223 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
224 payment_pending += value;
225 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
228 var change_pending = payment_tendered - payment_pending;
229 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
230 $('pending_change').value = util.money.cents_as_dollars( change_pending );
231 $('change_due').value = util.money.cents_as_dollars( change_pending );
232 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
234 alert('Error in bill2.js, tally_pending(): ' + E);
238 function tally_selected() {
240 JSAN.use('util.money');
241 var selected_billed = 0;
242 var selected_paid = 0;
243 var selected_balance = 0;
245 for (var i = 0; i < g.bill_list_selection.length; i++) {
246 var bill = g.bill_map[g.bill_list_selection[i]];
248 //$('checked_owed').setAttribute('value', '???');
249 //$('checked_billed').setAttribute('value', '???');
250 //$('checked_paid').setAttribute('value', '???');
253 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
254 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
255 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
256 selected_billed += to;
258 selected_balance += bo;
260 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
261 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
262 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
264 alert('Error in bill2.js, tally_selected(): ' + E);
268 function tally_voided() {
270 JSAN.use('util.money');
271 var voided_total = 0;
273 g.data.stash_retrieve();
275 for (var i = 0; i < g.data.voided_billings.length; i++) {
276 var billing = g.data.voided_billings[i];
277 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
280 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
282 alert('Error in bill2.js, tally_voided(): ' + E);
286 function tally_all() {
288 JSAN.use('util.money');
289 var checked_billed = 0;
290 var checked_paid = 0;
291 var checked_balance = 0;
292 var total_billed = 0;
294 var total_balance = 0;
295 var refunds_owed = 0;
297 var retrieve_ids = g.bill_list.dump_retrieve_ids();
298 for (var i = 0; i < retrieve_ids.length; i++) {
299 var bill = g.bill_map[retrieve_ids[i]];
301 $('checked_owed').value = '???';
302 $('checked_owed2').setAttribute('value', '???');
303 $('checked_billed').value = '???';
304 $('checked_paid').value = '???';
305 $('tb_total_owed').value = '???';
306 $('total_owed2').setAttribute('value', '???');
307 $('total_billed').value = '???';
308 $('tb_total_paid').value = '???';
309 $('refunds_owed').setAttribute('value', '???');
312 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
313 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
314 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
318 if ( bo < 0 ) refunds_owed += bo;
319 if (g.check_map[retrieve_ids[i]]) {
320 checked_billed += to;
322 checked_balance += bo;
325 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
326 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
327 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
328 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
329 $('total_billed').value = util.money.cents_as_dollars( total_billed );
330 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
331 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
332 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
333 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
336 alert('Error in bill2.js, tally_all(): ' + E);
340 function handle_refund() {
341 if(g.bill_list_selection.length > 1) {
342 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
344 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
347 var r = g.error.yns_alert(msg,
348 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
349 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
350 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
351 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
353 for (var i = 0; i < g.bill_list_selection.length; i++) {
354 var bill_id = g.bill_list_selection[i];
355 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
356 g.check_map[bill_id] = true;
357 var row_params = g.row_map[bill_id];
358 row_params.row.my.checked = true;
359 g.bill_list.refresh_row(row_params);
363 distribute_payment();
367 function check_all() {
369 for (var i in g.bill_map) {
370 g.check_map[i] = true;
371 var row_params = g.row_map[i];
372 row_params.row.my.checked = true;
373 g.bill_list.refresh_row(row_params);
376 distribute_payment();
378 alert('Error in bill2.js, check_all(): ' + E);
383 function uncheck_all() {
385 for (var i in g.bill_map) {
386 g.check_map[i] = false;
387 var row_params = g.row_map[i];
388 row_params.row.my.checked = false;
389 g.bill_list.refresh_row(row_params);
392 distribute_payment();
394 alert('Error in bill2.js, check_all(): ' + E);
399 function check_all_refunds() {
401 for (var i in g.bill_map) {
402 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
403 g.check_map[i] = true;
404 var row_params = g.row_map[i];
405 row_params.row.my.checked = true;
406 g.bill_list.refresh_row(row_params);
410 distribute_payment();
412 alert('Error in bill2.js, check_all_refunds(): ' + E);
416 function gen_list_append_func(r) {
418 var default_check_state = g.data.hash.aous[
419 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
421 if (typeof r == 'object') {
422 g.row_map[ r.id() ] = g.bill_list.append( {
423 'retrieve_id' : r.id(),
424 'flesh_immediately' : true,
427 'checked' : default_check_state,
433 g.row_map[r] = g.bill_list.append( {
435 'flesh_immediately' : true,
438 'checked' : default_check_state
446 function retrieve_mbts_for_list() {
447 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
448 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
449 if (g.mbts_ids.ilsevent) {
450 switch(Number(g.mbts_ids.ilsevent)) {
451 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
452 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;
454 } else if (g.mbts_ids == null) {
455 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
458 g.mbts_ids.reverse();
460 for (var i = 0; i < g.mbts_ids.length; i++) {
461 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
462 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
467 function init_lists() {
468 JSAN.use('util.list'); JSAN.use('circ.util');
470 g.bill_list_selection = [];
472 g.bill_list = new util.list('bill_tree');
478 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
479 'render' : function(my) { return String( my.checked ) == 'true'; },
482 patron.util.mbts_columns({
483 'mbts_xact_finish' : { 'hidden' : true }
487 'title' : { 'hidden' : false, 'flex' : '3' }
492 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
493 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
494 'render' : function(my) { return my.payment_pending || '0.00'; },
498 'on_select' : function(ev) {
499 JSAN.use('util.functional');
500 g.bill_list_selection = util.functional.map_list(
501 g.bill_list.retrieve_selection(),
502 function(o) { return o.getAttribute('retrieve_id'); }
505 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
506 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
507 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
508 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
509 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
510 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
512 'on_click' : function(ev) {
513 var row = {}; var col = {}; var nobj = {};
514 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
515 if (row.value == -1) return;
516 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
517 if (treeItem.nodeName != 'treeitem') return;
518 var treeRow = treeItem.firstChild;
519 var treeCell = treeRow.firstChild.nextSibling;
520 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
521 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
522 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
524 distribute_payment();
527 'on_sort' : function() {
530 'on_checkbox_toggle' : function(toggle) {
532 var retrieve_ids = g.bill_list.dump_retrieve_ids();
533 for (var i = 0; i < retrieve_ids.length; i++) {
534 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
535 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
539 alert('error in on_checkbox_toggle(): ' + E);
542 'retrieve_row' : function(params) {
544 var id = params.retrieve_id;
545 var row = params.row;
547 function handle_props(row) {
549 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
550 util.widgets.addProperty(params.treeitem_node.firstChild,'refundable');
551 util.widgets.addProperty(params.treeitem_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
553 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
554 $('circulating_hint').hidden = false;
555 util.widgets.addProperty(params.treeitem_node.firstChild,'circulating');
556 util.widgets.addProperty(params.treeitem_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
559 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
560 alert('Error setting list properties in bill2.js: ' + E);
565 if (typeof row.my == 'undefined') row.my = {};
566 if (typeof row.my.mbts == 'undefined' ) {
567 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
568 var blob = req.getResultObject();
569 row.my.mbts = blob.transaction;
570 row.my.circ = blob.circ;
571 row.my.acp = blob.copy;
572 row.my.mvr = blob.record;
573 if (typeof params.on_retrieve == 'function') {
574 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
575 row.my.checked = false;
578 params.on_retrieve(row);
580 g.bill_map[ id ] = blob;
581 g.check_map[ id ] = row.my.checked;
585 if (typeof params.on_retrieve == 'function') {
587 params.on_retrieve(row);
591 if (typeof params.on_retrieve == 'function') {
592 params.on_retrieve(row);
598 alert('Error in bill2.js, retrieve_row(): ' + E);
603 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
604 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
605 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
606 g.bill_list.set_list_actions();
609 function handle_add() {
610 if(g.bill_list_selection.length > 1) {
611 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
613 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
616 var r = g.error.yns_alert(msg,
617 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
618 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
619 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
620 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
622 JSAN.use('util.window');
623 var win = new util.window();
624 for (var i = 0; i < g.bill_list_selection.length; i++) {
626 urls.XUL_PATRON_BILL_WIZARD,
628 'chrome,resizable,modal',
629 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
633 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
637 function handle_void_all() {
638 if(g.bill_list_selection.length > 1) {
639 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
641 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
644 var r = g.error.yns_alert(msg,
645 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
646 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
647 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
648 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
650 for (var i = 0; i < g.bill_list_selection.length; i++) {
651 void_all_billings( g.bill_list_selection[i] );
654 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
655 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
659 function handle_opac() {
662 for (var i = 0; i < g.bill_list_selection.length; i++) {
663 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
664 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
665 if (typeof my_mvr != 'undefined' && my_mvr != null) {
666 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
669 JSAN.use('cat.util');
670 cat.util.show_in_opac( ids );
672 alert('Error in bill2.js, handle_opac: ' + E);
676 function handle_copy_details() {
679 for (var i = 0; i < g.bill_list_selection.length; i++) {
680 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
681 if (typeof my_acp != 'undefined' && my_acp != null) {
682 ids.push( my_acp.barcode() );
685 JSAN.use('circ.util');
686 circ.util.item_details_new( ids );
688 alert('Error in bill2.js, handle_opac: ' + E);
692 function handle_details() {
693 JSAN.use('util.window'); var win = new util.window();
694 for (var i = 0; i < g.bill_list_selection.length; i++) {
695 var my_xulG = win.open(
696 urls.XUL_PATRON_BILL_DETAILS,
697 'test_billdetails_' + g.bill_list_selection[i],
700 'patron_id' : g.patron_id,
701 'mbts_id' : g.bill_list_selection[i],
702 'refresh' : function() {
704 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
706 'new_tab' : xulG.new_tab,
707 'url_prefix' : xulG.url_prefix
713 function print_bills() {
715 var template = 'bills_current';
716 JSAN.use('patron.util');
717 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
720 , 'printer_context' : 'receipt'
721 , 'template' : template
723 grand_total_owed: $('tb_total_owed').value
724 , grand_total_billed: $('total_billed').value
725 , grand_total_paid: $('tb_total_paid').value
729 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
733 function distribute_payment() {
735 JSAN.use('util.money');
736 var tb = $('payment');
737 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
738 tb.setAttribute('value', tb.value );
739 var total = util.money.dollars_float_to_cents_integer( tb.value );
740 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
741 var retrieve_ids = g.bill_list.dump_retrieve_ids();
742 for (var i = 0; i < retrieve_ids.length; i++) {
743 var row_params = g.row_map[retrieve_ids[i]];
744 if (g.check_map[retrieve_ids[i]]) {
745 var bill = g.bill_map[retrieve_ids[i]].transaction;
746 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
748 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
751 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
755 row_params.row.my.payment_pending = '0.00';
757 g.bill_list.refresh_row(row_params);
761 alert('Error in bill2.js, distribute_payment(): ' + E);
765 function apply_payment() {
767 var payment_blob = {};
768 JSAN.use('util.window');
769 var win = new util.window();
770 switch($('payment_type').value) {
771 case 'credit_card_payment' :
773 g.data.stash('temp');
774 var my_xulG = win.open(
775 urls.XUL_PATRON_BILL_CC_INFO,
777 'chrome,resizable,modal',
778 {'patron_id': g.patron_id}
780 g.data.stash_retrieve();
781 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
783 case 'check_payment' :
785 g.data.stash('temp');
786 var my_xulG = win.open(
787 urls.XUL_PATRON_BILL_CHECK_INFO,
789 'chrome,resizable,modal'
791 g.data.stash_retrieve();
792 payment_blob = JSON2js( g.data.temp );
796 (typeof payment_blob == 'undefined') ||
798 payment_blob.cancelled=='true'
800 alert( $('commonStrings').getString('common.cancelled') );
803 payment_blob.userid = g.patron_id;
804 payment_blob.note = payment_blob.note || '';
805 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
806 payment_blob.payment_type = $('payment_type').value;
807 var tally_blob = tally_pending();
808 payment_blob.payments = tally_blob.payments;
809 // Handle patron credit
810 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
811 if ( $('convert_change_to_credit').checked ) {
812 // No need to convert credit into credit, handled automatically
813 payment_blob.patron_credit = '0.00';
815 // Cashing out extra credit as change
816 payment_blob.patron_credit = 0 - tally_blob.change;
818 } else if ( $('convert_change_to_credit').checked ) {
819 // Saving change from a non-credit payment as patron credit on server
820 payment_blob.patron_credit = tally_blob.change;
822 payment_blob.patron_credit = '0.00';
824 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
825 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
828 if ( pay( payment_blob ) ) {
830 $('payment').value = ''; $('payment').select(); $('payment').focus();
831 refresh({'clear_voided_summary':true});
832 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
833 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
834 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
838 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
839 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
840 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
841 if (no_print_prompting) {
842 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
844 g.data.stash_retrieve();
845 var template = 'bill_payment';
846 JSAN.use('patron.util'); JSAN.use('util.functional');
849 'lib' : g.data.hash.aou[ ses('ws_ou') ],
850 'staff' : ses('staff'),
851 'header' : g.data.print_list_templates[template].header,
852 'line_item' : g.data.print_list_templates[template].line_item,
853 'footer' : g.data.print_list_templates[template].footer,
854 'type' : g.data.print_list_templates[template].type,
855 'list' : util.functional.map_list(
856 payment_blob.payments,
861 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
862 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
863 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
864 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
868 'data' : g.previous_summary,
869 'context' : g.data.print_list_templates[template].context,
871 g.error.sdump('D_DEBUG',js2JSON(params));
872 if ($('printer_prompt').hasAttribute('checked')) {
873 if ($('printer_prompt').getAttribute('checked')) {
874 params.no_prompt = false;
876 params.no_prompt = true;
879 params.no_prompt = true;
881 JSAN.use('util.print'); var print = new util.print('receipt');
882 for (var i = 0; i < $('num_of_receipts').value; i++) {
883 print.tree_list( params );
886 g.error.standard_unexpected_error_alert('bill receipt', E);
890 alert('Error in bill2.js, apply_payment(): ' + E);
894 function pay(payment_blob) {
896 var x = $('annotate_payment');
897 if (x && x.checked && (! payment_blob.note)) {
898 payment_blob.note = window.prompt(
899 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
901 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
904 g.previous_summary = {
905 original_balance : $('tb_total_owed').value,
906 voided_balance : $('currently_voided').value,
907 payment_received : $('payment').value,
908 payment_applied : $('pending_payment').value,
909 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
910 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
911 new_balance : util.money.cents_as_dollars(
912 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
913 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
915 payment_type : $('payment_type').getAttribute('label'),
916 note : payment_blob.note
918 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
922 $('circStrings').getFormattedString(
923 robj && robj.payments
924 ? 'staff.circ.work_log_payment_attempt.success.message'
925 : 'staff.circ.work_log_payment_attempt.failure.message',
927 ses('staff_usrname'), // 1 - Staff Username
928 g.patron.family_name(), // 2 - Patron Family
929 g.patron.card().barcode(), // 3 - Patron Barcode
930 g.previous_summary.original_balance, // 4 - Original Balance
931 g.previous_summary.voided_balance, // 5 - Voided Balance
932 g.previous_summary.payment_received, // 6 - Payment Received
933 g.previous_summary.payment_applied, // 7 - Payment Applied
934 g.previous_summary.change_given, // 8 - Change Given
935 g.previous_summary.credit_given, // 9 - Credit Given
936 g.previous_summary.new_balance, // 10 - New Balance
937 g.previous_summary.payment_type, // 11 - Payment Type
938 g.previous_summary.note, // 12 - Note
939 robj && robj.textcode ? robj.textcode : robj // 13 - API call result
942 'au_id' : g.patron.id(),
943 'au_family_name' : g.patron.family_name(),
944 'au_barcode' : g.patron.card().barcode()
948 alert('Error logging payment in bill2.js: ' + E);
951 if (typeof robj.ilsevent != 'undefined') {
952 switch(robj.textcode) {
953 case 'SUCCESS' : return true; break;
954 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
955 case 'INVALID_USER_XACT_ID' :
956 refresh(); default_focus();
957 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
958 default: throw(robj); break;
963 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
968 function refresh(params) {
970 if (params && params.clear_voided_summary) {
971 g.data.voided_billings = []; g.data.stash('voided_billings');
975 retrieve_mbts_for_list();
977 distribute_payment();
979 alert('Error in bill2.js, refresh(): ' + E);
983 function void_all_billings(mobts_id) {
985 JSAN.use('util.functional');
987 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
988 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
990 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
992 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
995 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
996 sum = util.money.cents_as_dollars( sum );
998 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
999 var r = g.error.yns_alert(msg,
1000 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
1001 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
1002 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
1003 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
1005 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
1006 if (robj.ilsevent) {
1007 switch(Number(robj.ilsevent)) {
1008 case 5000 /* PERM_FAILURE */:
1012 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
1018 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
1019 for (var i = 0; i < mb_list.length; i++) {
1020 g.data.voided_billings.push( mb_list[i] );
1022 g.data.stash('voided_billings');
1025 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
1029 function refresh_patron() {
1030 JSAN.use('patron.util'); JSAN.use('util.money');
1031 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
1032 var au_obj = req.getResultObject();
1033 if (typeof au_obj.ilsevent == 'undefined') {
1035 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));