3 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
4 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
5 JSAN.errorLevel = "die"; // none, warn, or die
6 JSAN.addRepository('/xul/server/');
8 JSAN.use('util.error'); g.error = new util.error();
9 JSAN.use('util.network'); g.network = new util.network();
10 JSAN.use('util.date');
11 JSAN.use('util.money');
12 JSAN.use('util.widgets');
13 JSAN.use('patron.util');
14 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
15 g.data.voided_billings = []; g.data.stash('voided_billings');
17 g.error.sdump('D_TRACE','my_init() for bill2.xul');
19 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 event_listeners() {
69 $('details').addEventListener(
75 $('add').addEventListener(
81 $('voidall').addEventListener(
87 $('refund').addEventListener(
93 $('opac').addEventListener(
99 $('copy_details').addEventListener(
105 $('payment').addEventListener(
108 if ($('payment_type').value == 'credit_payment') {
109 JSAN.use('util.money');
110 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
111 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
112 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
113 if (proposed > available) {
114 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
115 ev.target.value = util.money.cents_as_dollars( available );
116 ev.target.setAttribute('value',ev.target.value);
119 distribute_payment();
124 $('payment').addEventListener(
126 function(ev) { ev.target.select(); },
130 $('payment').addEventListener(
133 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
134 distribute_payment();
135 $('apply_payment_btn').focus();
140 $('bill_patron_btn').addEventListener(
143 JSAN.use('util.window'); var win = new util.window();
144 var my_xulG = win.open(
145 urls.XUL_PATRON_BILL_WIZARD,
147 'chrome,resizable,modal',
148 { 'patron_id' : g.patron_id }
150 if (my_xulG.xact_id) { g.funcs.push( gen_list_append_func( my_xulG.xact_id ) ); /* FIXME: do something to update summary sidebar */ }
155 $('bill_history_btn').addEventListener(
158 xulG.display_window.g.patron.right_deck.reset_iframe(
159 urls.XUL_PATRON_BILL_HISTORY,
162 'patron_id' : g.patron_id,
163 'refresh' : function() { refresh(); },
164 'new_tab' : xulG.new_tab,
165 'url_prefix' : xulG.url_prefix
172 $('convert_change_to_credit').addEventListener(
175 if (ev.target.checked) {
176 addCSSClass( $('change_due'), 'change_to_credit' );
178 removeCSSClass( $('change_due'), 'change_to_credit' );
184 $('apply_payment_btn').addEventListener(
188 $('apply_payment_btn').disabled = true;
191 $('apply_payment_btn').disabled = false;
193 alert('Error in bill2.js, apply_payment_btn: ' + E);
200 alert('Error in bill2.js, event_listeners(): ' + E);
204 function $(id) { return document.getElementById(id); }
206 function default_focus() {
207 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
210 function tally_pending() {
213 JSAN.use('util.money');
214 var tb = $('payment');
215 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
216 var payment_pending = 0;
217 var retrieve_ids = g.bill_list.dump_retrieve_ids();
218 for (var i = 0; i < retrieve_ids.length; i++) {
219 var row_params = g.row_map[retrieve_ids[i]];
220 if (g.check_map[retrieve_ids[i]]) {
221 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
222 payment_pending += value;
223 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
226 var change_pending = payment_tendered - payment_pending;
227 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
228 $('pending_change').value = util.money.cents_as_dollars( change_pending );
229 $('change_due').value = util.money.cents_as_dollars( change_pending );
230 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
232 alert('Error in bill2.js, tally_pending(): ' + E);
236 function tally_selected() {
238 JSAN.use('util.money');
239 var selected_billed = 0;
240 var selected_paid = 0;
241 var selected_balance = 0;
243 for (var i = 0; i < g.bill_list_selection.length; i++) {
244 var bill = g.bill_map[g.bill_list_selection[i]];
246 //$('checked_owed').setAttribute('value', '???');
247 //$('checked_billed').setAttribute('value', '???');
248 //$('checked_paid').setAttribute('value', '???');
251 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
252 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
253 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
254 selected_billed += to;
256 selected_balance += bo;
258 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
259 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
260 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
262 alert('Error in bill2.js, tally_selected(): ' + E);
266 function tally_voided() {
268 JSAN.use('util.money');
269 var voided_total = 0;
271 g.data.stash_retrieve();
273 for (var i = 0; i < g.data.voided_billings.length; i++) {
274 var billing = g.data.voided_billings[i];
275 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
278 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
280 alert('Error in bill2.js, tally_voided(): ' + E);
284 function tally_all() {
286 JSAN.use('util.money');
287 var checked_billed = 0;
288 var checked_paid = 0;
289 var checked_balance = 0;
290 var total_billed = 0;
292 var total_balance = 0;
293 var refunds_owed = 0;
295 var retrieve_ids = g.bill_list.dump_retrieve_ids();
296 for (var i = 0; i < retrieve_ids.length; i++) {
297 var bill = g.bill_map[retrieve_ids[i]];
299 $('checked_owed').value = '???';
300 $('checked_owed2').setAttribute('value', '???');
301 $('checked_billed').value = '???';
302 $('checked_paid').value = '???';
303 $('tb_total_owed').value = '???';
304 $('total_owed2').setAttribute('value', '???');
305 $('total_billed').value = '???';
306 $('tb_total_paid').value = '???';
307 $('refunds_owed').setAttribute('value', '???');
310 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
311 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
312 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
316 if ( bo < 0 ) refunds_owed += bo;
317 if (g.check_map[retrieve_ids[i]]) {
318 checked_billed += to;
320 checked_balance += bo;
323 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
324 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
325 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
326 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
327 $('total_billed').value = util.money.cents_as_dollars( total_billed );
328 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
329 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
330 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
331 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
334 alert('Error in bill2.js, tally_all(): ' + E);
338 function handle_refund() {
339 if(g.bill_list_selection.length > 1) {
340 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
342 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
345 var r = g.error.yns_alert(msg,
346 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
347 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
348 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
349 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
351 for (var i = 0; i < g.bill_list_selection.length; i++) {
352 var bill_id = g.bill_list_selection[i];
353 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
354 g.check_map[bill_id] = true;
355 var row_params = g.row_map[bill_id];
356 row_params.row.my.checked = true;
357 g.bill_list.refresh_row(row_params);
361 distribute_payment();
365 function check_all() {
367 for (var i in g.bill_map) {
368 g.check_map[i] = true;
369 var row_params = g.row_map[i];
370 row_params.row.my.checked = true;
371 g.bill_list.refresh_row(row_params);
374 distribute_payment();
376 alert('Error in bill2.js, check_all(): ' + E);
381 function uncheck_all() {
383 for (var i in g.bill_map) {
384 g.check_map[i] = false;
385 var row_params = g.row_map[i];
386 row_params.row.my.checked = false;
387 g.bill_list.refresh_row(row_params);
390 distribute_payment();
392 alert('Error in bill2.js, check_all(): ' + E);
397 function check_all_refunds() {
399 for (var i in g.bill_map) {
400 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
401 g.check_map[i] = true;
402 var row_params = g.row_map[i];
403 row_params.row.my.checked = true;
404 g.bill_list.refresh_row(row_params);
408 distribute_payment();
410 alert('Error in bill2.js, check_all_refunds(): ' + E);
414 function gen_list_append_func(r) {
416 var default_check_state = g.data.hash.aous[
417 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
419 if (typeof r == 'object') {
420 g.row_map[ r.id() ] = g.bill_list.append( {
421 'retrieve_id' : r.id(),
422 'flesh_immediately' : true,
425 'checked' : default_check_state,
431 g.row_map[r] = g.bill_list.append( {
433 'flesh_immediately' : true,
436 'checked' : default_check_state
444 function retrieve_mbts_for_list() {
445 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
446 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
447 if (g.mbts_ids.ilsevent) {
448 switch(Number(g.mbts_ids.ilsevent)) {
449 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
450 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;
452 } else if (g.mbts_ids == null) {
453 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
456 g.mbts_ids.reverse();
458 for (var i = 0; i < g.mbts_ids.length; i++) {
459 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
460 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
465 function init_lists() {
466 JSAN.use('util.list'); JSAN.use('circ.util');
468 g.bill_list_selection = [];
470 g.bill_list = new util.list('bill_tree');
476 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
477 'render' : function(my) { return String( my.checked ) == 'true'; },
480 patron.util.mbts_columns({
481 'mbts_xact_finish' : { 'hidden' : true }
485 'title' : { 'hidden' : false, 'flex' : '3' }
490 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
491 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
492 'render' : function(my) { return my.payment_pending || '0.00'; },
496 'map_row_to_columns' : patron.util.std_map_row_to_columns(' '),
497 'on_select' : function(ev) {
498 JSAN.use('util.functional');
499 g.bill_list_selection = util.functional.map_list(
500 g.bill_list.retrieve_selection(),
501 function(o) { return o.getAttribute('retrieve_id'); }
504 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
505 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
506 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
507 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
508 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
509 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
511 'on_click' : function(ev) {
512 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
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 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
845 g.data.stash_retrieve();
846 var template = 'bill_payment';
847 JSAN.use('patron.util'); JSAN.use('util.functional');
850 'lib' : g.data.hash.aou[ ses('ws_ou') ],
851 'staff' : ses('staff'),
852 'header' : g.data.print_list_templates[template].header,
853 'line_item' : g.data.print_list_templates[template].line_item,
854 'footer' : g.data.print_list_templates[template].footer,
855 'type' : g.data.print_list_templates[template].type,
856 'list' : util.functional.map_list(
857 payment_blob.payments,
862 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
863 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
864 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
865 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
869 'data' : g.previous_summary,
870 'context' : g.data.print_list_templates[template].context,
872 g.error.sdump('D_DEBUG',js2JSON(params));
873 if ($('printer_prompt').hasAttribute('checked')) {
874 if ($('printer_prompt').getAttribute('checked')) {
875 params.no_prompt = false;
877 params.no_prompt = true;
880 params.no_prompt = true;
882 JSAN.use('util.print'); var print = new util.print('receipt');
883 for (var i = 0; i < $('num_of_receipts').value; i++) {
884 print.tree_list( params );
887 g.error.standard_unexpected_error_alert('bill receipt', E);
891 alert('Error in bill2.js, apply_payment(): ' + E);
895 function pay(payment_blob) {
897 var x = $('annotate_payment');
898 if (x && x.checked && (! payment_blob.note)) {
899 payment_blob.note = window.prompt(
900 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
902 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
905 g.previous_summary = {
906 original_balance : $('tb_total_owed').value,
907 voided_balance : $('currently_voided').value,
908 payment_received : $('payment').value,
909 payment_applied : $('pending_payment').value,
910 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
911 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
912 new_balance : util.money.cents_as_dollars(
913 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
914 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
916 payment_type : $('payment_type').getAttribute('label'),
917 note : payment_blob.note
919 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
920 if (typeof robj.ilsevent != 'undefined') {
921 switch(robj.textcode) {
922 case 'SUCCESS' : return true; break;
923 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
924 case 'INVALID_USER_XACT_ID' :
925 refresh(); default_focus();
926 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
927 default: throw(robj); break;
932 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
937 function refresh(params) {
939 if (params && params.clear_voided_summary) {
940 g.data.voided_billings = []; g.data.stash('voided_billings');
944 retrieve_mbts_for_list();
946 distribute_payment();
948 alert('Error in bill2.js, refresh(): ' + E);
952 function void_all_billings(mobts_id) {
954 JSAN.use('util.functional');
956 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
957 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
959 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
961 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
964 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
965 sum = util.money.cents_as_dollars( sum );
967 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
968 var r = g.error.yns_alert(msg,
969 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
970 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
971 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
972 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
974 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
976 switch(Number(robj.ilsevent)) {
977 case 5000 /* PERM_FAILURE */:
981 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
987 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
988 for (var i = 0; i < mb_list.length; i++) {
989 g.data.voided_billings.push( mb_list[i] );
991 g.data.stash('voided_billings');
994 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
998 function refresh_patron() {
999 JSAN.use('patron.util'); JSAN.use('util.money');
1000 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
1001 var au_obj = req.getResultObject();
1002 if (typeof au_obj.ilsevent == 'undefined') {
1004 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));