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
171 $('convert_change_to_credit').addEventListener(
174 if (ev.target.checked) {
175 addCSSClass( $('change_due'), 'change_to_credit' );
177 removeCSSClass( $('change_due'), 'change_to_credit' );
183 $('apply_payment_btn').addEventListener(
187 $('apply_payment_btn').disabled = true;
190 $('apply_payment_btn').disabled = false;
192 alert('Error in bill2.js, apply_payment_btn: ' + E);
199 alert('Error in bill2.js, event_listeners(): ' + E);
203 function $(id) { return document.getElementById(id); }
205 function default_focus() {
206 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
209 function tally_pending() {
212 JSAN.use('util.money');
213 var tb = $('payment');
214 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
215 var payment_pending = 0;
216 var retrieve_ids = g.bill_list.dump_retrieve_ids();
217 for (var i = 0; i < retrieve_ids.length; i++) {
218 var row_params = g.row_map[retrieve_ids[i]];
219 if (g.check_map[retrieve_ids[i]]) {
220 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
221 payment_pending += value;
222 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
225 var change_pending = payment_tendered - payment_pending;
226 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
227 $('pending_change').value = util.money.cents_as_dollars( change_pending );
228 $('change_due').value = util.money.cents_as_dollars( change_pending );
229 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
231 alert('Error in bill2.js, tally_pending(): ' + E);
235 function tally_selected() {
237 JSAN.use('util.money');
238 var selected_billed = 0;
239 var selected_paid = 0;
240 var selected_balance = 0;
242 for (var i = 0; i < g.bill_list_selection.length; i++) {
243 var bill = g.bill_map[g.bill_list_selection[i]];
245 //$('checked_owed').setAttribute('value', '???');
246 //$('checked_billed').setAttribute('value', '???');
247 //$('checked_paid').setAttribute('value', '???');
250 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
251 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
252 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
253 selected_billed += to;
255 selected_balance += bo;
257 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
258 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
259 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
261 alert('Error in bill2.js, tally_selected(): ' + E);
265 function tally_voided() {
267 JSAN.use('util.money');
268 var voided_total = 0;
270 g.data.stash_retrieve();
272 for (var i = 0; i < g.data.voided_billings.length; i++) {
273 var billing = g.data.voided_billings[i];
274 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
277 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
279 alert('Error in bill2.js, tally_voided(): ' + E);
283 function tally_all() {
285 JSAN.use('util.money');
286 var checked_billed = 0;
287 var checked_paid = 0;
288 var checked_balance = 0;
289 var total_billed = 0;
291 var total_balance = 0;
292 var refunds_owed = 0;
294 var retrieve_ids = g.bill_list.dump_retrieve_ids();
295 for (var i = 0; i < retrieve_ids.length; i++) {
296 var bill = g.bill_map[retrieve_ids[i]];
298 $('checked_owed').value = '???';
299 $('checked_owed2').setAttribute('value', '???');
300 $('checked_billed').value = '???';
301 $('checked_paid').value = '???';
302 $('tb_total_owed').value = '???';
303 $('total_owed2').setAttribute('value', '???');
304 $('total_billed').value = '???';
305 $('tb_total_paid').value = '???';
306 $('refunds_owed').setAttribute('value', '???');
309 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
310 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
311 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
315 if ( bo < 0 ) refunds_owed += bo;
316 if (g.check_map[retrieve_ids[i]]) {
317 checked_billed += to;
319 checked_balance += bo;
322 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
323 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
324 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
325 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
326 $('total_billed').value = util.money.cents_as_dollars( total_billed );
327 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
328 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
329 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
330 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
333 alert('Error in bill2.js, tally_all(): ' + E);
337 function handle_refund() {
338 if(g.bill_list_selection.length > 1) {
339 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
341 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
344 var r = g.error.yns_alert(msg,
345 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
346 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
347 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
348 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
350 for (var i = 0; i < g.bill_list_selection.length; i++) {
351 var bill_id = g.bill_list_selection[i];
352 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
353 g.check_map[bill_id] = true;
354 var row_params = g.row_map[bill_id];
355 row_params.row.my.checked = true;
356 g.bill_list.refresh_row(row_params);
360 distribute_payment();
364 function check_all() {
366 for (var i in g.bill_map) {
367 g.check_map[i] = true;
368 var row_params = g.row_map[i];
369 row_params.row.my.checked = true;
370 g.bill_list.refresh_row(row_params);
373 distribute_payment();
375 alert('Error in bill2.js, check_all(): ' + E);
380 function uncheck_all() {
382 for (var i in g.bill_map) {
383 g.check_map[i] = false;
384 var row_params = g.row_map[i];
385 row_params.row.my.checked = false;
386 g.bill_list.refresh_row(row_params);
389 distribute_payment();
391 alert('Error in bill2.js, check_all(): ' + E);
396 function check_all_refunds() {
398 for (var i in g.bill_map) {
399 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
400 g.check_map[i] = true;
401 var row_params = g.row_map[i];
402 row_params.row.my.checked = true;
403 g.bill_list.refresh_row(row_params);
407 distribute_payment();
409 alert('Error in bill2.js, check_all_refunds(): ' + E);
413 function gen_list_append_func(r) {
415 var default_check_state = g.data.hash.aous[
416 'ui.circ.billing.uncheck_bills_and_unfocus_payment_box'
418 if (typeof r == 'object') {
419 g.row_map[ r.id() ] = g.bill_list.append( {
420 'retrieve_id' : r.id(),
421 'flesh_immediately' : true,
424 'checked' : default_check_state,
430 g.row_map[r] = g.bill_list.append( {
432 'flesh_immediately' : true,
435 'checked' : default_check_state
443 function retrieve_mbts_for_list() {
444 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
445 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
446 if (g.mbts_ids.ilsevent) {
447 switch(Number(g.mbts_ids.ilsevent)) {
448 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
449 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;
451 } else if (g.mbts_ids == null) {
452 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
455 g.mbts_ids.reverse();
457 for (var i = 0; i < g.mbts_ids.length; i++) {
458 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
459 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
464 function init_lists() {
465 JSAN.use('util.list'); JSAN.use('circ.util');
467 g.bill_list_selection = [];
469 g.bill_list = new util.list('bill_tree');
475 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
476 'render' : function(my) { return String( my.checked ) == 'true'; },
479 patron.util.mbts_columns({
480 'mbts_xact_finish' : { 'hidden' : true }
484 'title' : { 'hidden' : false, 'flex' : '3' }
489 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
490 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
491 'render' : function(my) { return my.payment_pending || '0.00'; },
495 'map_row_to_columns' : patron.util.std_map_row_to_columns(' '),
496 'on_select' : function(ev) {
497 JSAN.use('util.functional');
498 g.bill_list_selection = util.functional.map_list(
499 g.bill_list.retrieve_selection(),
500 function(o) { return o.getAttribute('retrieve_id'); }
503 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
504 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
505 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
506 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
507 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
508 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
510 'on_click' : function(ev) {
511 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
512 var row = {}; var col = {}; var nobj = {};
513 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
514 if (row.value == -1) return;
515 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
516 if (treeItem.nodeName != 'treeitem') return;
517 var treeRow = treeItem.firstChild;
518 var treeCell = treeRow.firstChild;
519 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
520 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
521 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
523 distribute_payment();
526 'on_sort' : function() {
529 'on_checkbox_toggle' : function(toggle) {
531 var retrieve_ids = g.bill_list.dump_retrieve_ids();
532 for (var i = 0; i < retrieve_ids.length; i++) {
533 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
534 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
538 alert('error in on_checkbox_toggle(): ' + E);
541 'retrieve_row' : function(params) {
543 var id = params.retrieve_id;
544 var row = params.row;
546 function handle_props(row) {
548 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
549 util.widgets.addProperty(params.row_node.firstChild,'refundable');
550 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
552 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
553 $('circulating_hint').hidden = false;
554 util.widgets.addProperty(params.row_node.firstChild,'circulating');
555 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
558 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
559 alert('Error setting list properties in bill2.js: ' + E);
564 if (typeof row.my == 'undefined') row.my = {};
565 if (typeof row.my.mbts == 'undefined' ) {
566 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
567 var blob = req.getResultObject();
568 row.my.mbts = blob.transaction;
569 row.my.circ = blob.circ;
570 row.my.acp = blob.copy;
571 row.my.mvr = blob.record;
572 if (typeof params.on_retrieve == 'function') {
573 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
574 row.my.checked = false;
577 params.on_retrieve(row);
579 g.bill_map[ id ] = blob;
580 g.check_map[ id ] = row.my.checked;
584 if (typeof params.on_retrieve == 'function') {
586 params.on_retrieve(row);
590 if (typeof params.on_retrieve == 'function') {
591 params.on_retrieve(row);
597 alert('Error in bill2.js, retrieve_row(): ' + E);
602 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
603 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
604 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
605 g.bill_list.set_list_actions();
608 function handle_add() {
609 if(g.bill_list_selection.length > 1) {
610 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
612 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
615 var r = g.error.yns_alert(msg,
616 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
617 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
618 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
619 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
621 JSAN.use('util.window');
622 var win = new util.window();
623 for (var i = 0; i < g.bill_list_selection.length; i++) {
625 urls.XUL_PATRON_BILL_WIZARD,
627 'chrome,resizable,modal',
628 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
632 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
636 function handle_void_all() {
637 if(g.bill_list_selection.length > 1) {
638 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
640 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
643 var r = g.error.yns_alert(msg,
644 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
645 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
646 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
647 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
649 for (var i = 0; i < g.bill_list_selection.length; i++) {
650 void_all_billings( g.bill_list_selection[i] );
653 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
654 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
658 function handle_opac() {
661 for (var i = 0; i < g.bill_list_selection.length; i++) {
662 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
663 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
664 if (typeof my_mvr != 'undefined' && my_mvr != null) {
665 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
668 JSAN.use('cat.util');
669 cat.util.show_in_opac( ids );
671 alert('Error in bill2.js, handle_opac: ' + E);
675 function handle_copy_details() {
678 for (var i = 0; i < g.bill_list_selection.length; i++) {
679 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
680 if (typeof my_acp != 'undefined' && my_acp != null) {
681 ids.push( my_acp.barcode() );
684 JSAN.use('circ.util');
685 circ.util.item_details_new( ids );
687 alert('Error in bill2.js, handle_opac: ' + E);
691 function handle_details() {
692 JSAN.use('util.window'); var win = new util.window();
693 for (var i = 0; i < g.bill_list_selection.length; i++) {
694 var my_xulG = win.open(
695 urls.XUL_PATRON_BILL_DETAILS,
696 'test_billdetails_' + g.bill_list_selection[i],
699 'patron_id' : g.patron_id,
700 'mbts_id' : g.bill_list_selection[i],
701 'refresh' : function() {
703 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
705 'new_tab' : xulG.new_tab,
706 'url_prefix' : xulG.url_prefix
712 function print_bills() {
714 var template = 'bills_current';
715 JSAN.use('patron.util');
716 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
719 , 'printer_context' : 'receipt'
720 , 'template' : template
722 grand_total_owed: $('tb_total_owed').value
723 , grand_total_billed: $('total_billed').value
724 , grand_total_paid: $('tb_total_paid').value
728 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
732 function distribute_payment() {
734 JSAN.use('util.money');
735 var tb = $('payment');
736 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
737 tb.setAttribute('value', tb.value );
738 var total = util.money.dollars_float_to_cents_integer( tb.value );
739 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
740 var retrieve_ids = g.bill_list.dump_retrieve_ids();
741 for (var i = 0; i < retrieve_ids.length; i++) {
742 var row_params = g.row_map[retrieve_ids[i]];
743 if (g.check_map[retrieve_ids[i]]) {
744 var bill = g.bill_map[retrieve_ids[i]].transaction;
745 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
747 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
750 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
754 row_params.row.my.payment_pending = '0.00';
756 g.bill_list.refresh_row(row_params);
760 alert('Error in bill2.js, distribute_payment(): ' + E);
764 function apply_payment() {
766 var payment_blob = {};
767 JSAN.use('util.window');
768 var win = new util.window();
769 switch($('payment_type').value) {
770 case 'credit_card_payment' :
772 g.data.stash('temp');
773 var my_xulG = win.open(
774 urls.XUL_PATRON_BILL_CC_INFO,
776 'chrome,resizable,modal',
777 {'patron_id': g.patron_id}
779 g.data.stash_retrieve();
780 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
782 case 'check_payment' :
784 g.data.stash('temp');
785 var my_xulG = win.open(
786 urls.XUL_PATRON_BILL_CHECK_INFO,
788 'chrome,resizable,modal'
790 g.data.stash_retrieve();
791 payment_blob = JSON2js( g.data.temp );
795 (typeof payment_blob == 'undefined') ||
797 payment_blob.cancelled=='true'
799 alert( $('commonStrings').getString('common.cancelled') );
802 payment_blob.userid = g.patron_id;
803 payment_blob.note = payment_blob.note || '';
804 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
805 payment_blob.payment_type = $('payment_type').value;
806 var tally_blob = tally_pending();
807 payment_blob.payments = tally_blob.payments;
808 // Handle patron credit
809 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
810 if ( $('convert_change_to_credit').checked ) {
811 // No need to convert credit into credit, handled automatically
812 payment_blob.patron_credit = '0.00';
814 // Cashing out extra credit as change
815 payment_blob.patron_credit = 0 - tally_blob.change;
817 } else if ( $('convert_change_to_credit').checked ) {
818 // Saving change from a non-credit payment as patron credit on server
819 payment_blob.patron_credit = tally_blob.change;
821 payment_blob.patron_credit = '0.00';
823 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
824 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
827 if ( pay( payment_blob ) ) {
829 $('payment').value = ''; $('payment').select(); $('payment').focus();
830 refresh({'clear_voided_summary':true});
831 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
832 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
833 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
837 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
838 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
839 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
840 if (no_print_prompting) {
841 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
843 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
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
870 g.error.sdump('D_DEBUG',js2JSON(params));
871 if ($('printer_prompt').hasAttribute('checked')) {
872 if ($('printer_prompt').getAttribute('checked')) {
873 params.no_prompt = false;
875 params.no_prompt = true;
878 params.no_prompt = true;
880 JSAN.use('util.print'); var print = new util.print('receipt');
881 for (var i = 0; i < $('num_of_receipts').value; i++) {
882 print.tree_list( params );
885 g.error.standard_unexpected_error_alert('bill receipt', E);
889 alert('Error in bill2.js, apply_payment(): ' + E);
893 function pay(payment_blob) {
895 var x = $('annotate_payment');
896 if (x && x.checked && (! payment_blob.note)) {
897 payment_blob.note = window.prompt(
898 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
900 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
903 g.previous_summary = {
904 original_balance : $('tb_total_owed').value,
905 voided_balance : $('currently_voided').value,
906 payment_received : $('payment').value,
907 payment_applied : $('pending_payment').value,
908 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
909 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
910 new_balance : util.money.cents_as_dollars(
911 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
912 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
914 payment_type : $('payment_type').getAttribute('label'),
915 note : payment_blob.note
917 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
918 if (typeof robj.ilsevent != 'undefined') {
919 switch(robj.textcode) {
920 case 'SUCCESS' : return true; break;
921 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
922 case 'INVALID_USER_XACT_ID' :
923 refresh(); default_focus();
924 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
925 default: throw(robj); break;
930 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
935 function refresh(params) {
937 if (params && params.clear_voided_summary) {
938 g.data.voided_billings = []; g.data.stash('voided_billings');
942 retrieve_mbts_for_list();
944 distribute_payment();
946 alert('Error in bill2.js, refresh(): ' + E);
950 function void_all_billings(mobts_id) {
952 JSAN.use('util.functional');
954 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
955 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
957 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
959 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
962 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
963 sum = util.money.cents_as_dollars( sum );
965 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
966 var r = g.error.yns_alert(msg,
967 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
968 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
969 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
970 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
972 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
974 switch(Number(robj.ilsevent)) {
975 case 5000 /* PERM_FAILURE */:
979 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
985 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
986 for (var i = 0; i < mb_list.length; i++) {
987 g.data.voided_billings.push( mb_list[i] );
989 g.data.stash('voided_billings');
992 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
996 function refresh_patron() {
997 JSAN.use('patron.util'); JSAN.use('util.money');
998 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
999 var au_obj = req.getResultObject();
1000 if (typeof au_obj.ilsevent == 'undefined') {
1002 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));