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 if (xul_param('current')) {
20 $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.current_bills'));
21 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
23 $('caption').setAttribute('label',$("patronStrings").getString('staff.patron.bill_history.my_init.bill_history'));
24 document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.bill_history');
27 g.funcs = []; g.bill_map = {}; g.row_map = {}; g.check_map = {};
29 g.patron_id = xul_param('patron_id');
31 $('circulating_hint').hidden = true;
35 retrieve_mbts_for_list();
39 JSAN.use('util.exec'); var exec = new util.exec(20);
40 exec.on_error = function(E) { alert(E); return true; }
41 exec.timer(g.funcs,100);
43 $('credit_forward').setAttribute('value','???');
47 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));
55 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
56 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
61 function event_listeners() {
63 $('details').addEventListener(
69 $('add').addEventListener(
75 $('voidall').addEventListener(
81 $('refund').addEventListener(
87 $('opac').addEventListener(
93 $('copy_details').addEventListener(
99 $('payment').addEventListener(
102 if ($('payment_type').value == 'credit_payment') {
103 JSAN.use('util.money');
104 JSAN.use('patron.util'); g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
105 var proposed = util.money.dollars_float_to_cents_integer(ev.target.value);
106 var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance());
107 if (proposed > available) {
108 alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()]));
109 ev.target.value = util.money.cents_as_dollars( available );
110 ev.target.setAttribute('value',ev.target.value);
113 distribute_payment();
118 $('payment').addEventListener(
120 function(ev) { ev.target.select(); },
124 $('payment').addEventListener(
127 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
128 distribute_payment();
129 $('apply_payment_btn').focus();
134 $('bill_patron_btn').addEventListener(
137 JSAN.use('util.window'); var win = new util.window();
138 var my_xulG = win.open(
139 urls.XUL_PATRON_BILL_WIZARD,
141 'chrome,resizable,modal',
142 { 'patron_id' : g.patron_id }
144 if (my_xulG.xact_id) { g.funcs.push( gen_list_append_func( my_xulG.xact_id ) ); /* FIXME: do something to update summary sidebar */ }
149 $('bill_history_btn').addEventListener(
152 xulG.display_window.g.patron.right_deck.reset_iframe(
153 urls.XUL_PATRON_BILL_HISTORY,
156 'patron_id' : g.patron_id,
157 'refresh' : function() { refresh(); },
158 'new_tab' : xulG.new_tab
165 $('convert_change_to_credit').addEventListener(
168 if (ev.target.checked) {
169 addCSSClass( $('change_due'), 'change_to_credit' );
171 removeCSSClass( $('change_due'), 'change_to_credit' );
177 $('apply_payment_btn').addEventListener(
181 $('apply_payment_btn').disabled = true;
183 $('apply_payment_btn').disabled = false;
185 alert('Error in bill2.js, apply_payment_btn: ' + E);
192 alert('Error in bill2.js, event_listeners(): ' + E);
196 function $(id) { return document.getElementById(id); }
198 function default_focus() {
199 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
202 function tally_pending() {
205 JSAN.use('util.money');
206 var tb = $('payment');
207 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
208 var payment_pending = 0;
209 var retrieve_ids = g.bill_list.dump_retrieve_ids();
210 for (var i = 0; i < retrieve_ids.length; i++) {
211 var row_params = g.row_map[retrieve_ids[i]];
212 if (g.check_map[retrieve_ids[i]]) {
213 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
214 payment_pending += value;
215 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
218 var change_pending = payment_tendered - payment_pending;
219 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
220 $('pending_change').value = util.money.cents_as_dollars( change_pending );
221 $('change_due').value = util.money.cents_as_dollars( change_pending );
222 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
224 alert('Error in bill2.js, tally_pending(): ' + E);
228 function tally_selected() {
230 JSAN.use('util.money');
231 var selected_billed = 0;
232 var selected_paid = 0;
233 var selected_balance = 0;
235 for (var i = 0; i < g.bill_list_selection.length; i++) {
236 var bill = g.bill_map[g.bill_list_selection[i]];
238 //$('checked_owed').setAttribute('value', '???');
239 //$('checked_billed').setAttribute('value', '???');
240 //$('checked_paid').setAttribute('value', '???');
243 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
244 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
245 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
246 selected_billed += to;
248 selected_balance += bo;
250 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
251 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
252 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
254 alert('Error in bill2.js, tally_selected(): ' + E);
258 function tally_voided() {
260 JSAN.use('util.money');
261 var voided_total = 0;
263 g.data.stash_retrieve();
265 for (var i = 0; i < g.data.voided_billings.length; i++) {
266 var billing = g.data.voided_billings[i];
267 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
270 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
272 alert('Error in bill2.js, tally_voided(): ' + E);
276 function tally_all() {
278 JSAN.use('util.money');
279 var checked_billed = 0;
280 var checked_paid = 0;
281 var checked_balance = 0;
282 var total_billed = 0;
284 var total_balance = 0;
285 var refunds_owed = 0;
287 var retrieve_ids = g.bill_list.dump_retrieve_ids();
288 for (var i = 0; i < retrieve_ids.length; i++) {
289 var bill = g.bill_map[retrieve_ids[i]];
291 $('checked_owed').value = '???';
292 $('checked_owed2').setAttribute('value', '???');
293 $('checked_billed').value = '???';
294 $('checked_paid').value = '???';
295 $('tb_total_owed').value = '???';
296 $('total_owed2').setAttribute('value', '???');
297 $('total_billed').value = '???';
298 $('tb_total_paid').value = '???';
299 $('refunds_owed').setAttribute('value', '???');
302 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
303 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
304 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
308 if ( bo < 0 ) refunds_owed += bo;
309 if (g.check_map[retrieve_ids[i]]) {
310 checked_billed += to;
312 checked_balance += bo;
315 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
316 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
317 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
318 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
319 $('total_billed').value = util.money.cents_as_dollars( total_billed );
320 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
321 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
322 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
323 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
326 alert('Error in bill2.js, tally_all(): ' + E);
330 function handle_refund() {
331 if(g.bill_list_selection.length > 1) {
332 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
334 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
337 var r = g.error.yns_alert(msg,
338 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
339 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
340 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
341 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
343 for (var i = 0; i < g.bill_list_selection.length; i++) {
344 var bill_id = g.bill_list_selection[i];
345 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
346 g.check_map[bill_id] = true;
347 var row_params = g.row_map[bill_id];
348 row_params.row.my.checked = true;
349 g.bill_list.refresh_row(row_params);
353 distribute_payment();
357 function check_all() {
359 for (var i in g.bill_map) {
360 g.check_map[i] = true;
361 var row_params = g.row_map[i];
362 row_params.row.my.checked = true;
363 g.bill_list.refresh_row(row_params);
366 distribute_payment();
368 alert('Error in bill2.js, check_all(): ' + E);
373 function uncheck_all() {
375 for (var i in g.bill_map) {
376 g.check_map[i] = false;
377 var row_params = g.row_map[i];
378 row_params.row.my.checked = false;
379 g.bill_list.refresh_row(row_params);
382 distribute_payment();
384 alert('Error in bill2.js, check_all(): ' + E);
389 function check_all_refunds() {
391 for (var i in g.bill_map) {
392 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
393 g.check_map[i] = true;
394 var row_params = g.row_map[i];
395 row_params.row.my.checked = true;
396 g.bill_list.refresh_row(row_params);
400 distribute_payment();
402 alert('Error in bill2.js, check_all_refunds(): ' + E);
406 function gen_list_append_func(r) {
408 if (typeof r == 'object') { g.row_map[ r.id() ] = g.bill_list.append( { 'retrieve_id' : r.id(), 'flesh_immediately' : true, 'row' : { 'my' : { 'checked' : true, 'mbts' : r } } } );
409 } else { g.row_map[r] = g.bill_list.append( { 'retrieve_id' : r, 'flesh_immediately' : true, 'row' : { 'my' : { 'checked' : true } } } ); }
413 function retrieve_mbts_for_list() {
414 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
415 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
416 if (g.mbts_ids.ilsevent) {
417 switch(Number(g.mbts_ids.ilsevent)) {
418 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
419 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;
421 } else if (g.mbts_ids == null) {
422 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
425 g.mbts_ids.reverse();
427 for (var i = 0; i < g.mbts_ids.length; i++) {
428 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
429 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
434 function init_lists() {
435 JSAN.use('util.list'); JSAN.use('circ.util');
437 g.bill_list_selection = [];
439 g.bill_list = new util.list('bill_tree');
445 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
446 'render' : function(my) { return String( my.checked ) == 'true'; },
449 patron.util.mbts_columns({
450 'mbts_xact_finish' : { 'hidden' : xul_param('current') ? true : false }
454 'title' : { 'hidden' : false, 'flex' : '3' }
459 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
460 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
461 'render' : function(my) { return my.payment_pending || '0.00'; },
465 'map_row_to_columns' : patron.util.std_map_row_to_columns(' '),
466 'on_select' : function(ev) {
467 JSAN.use('util.functional');
468 g.bill_list_selection = util.functional.map_list(
469 g.bill_list.retrieve_selection(),
470 function(o) { return o.getAttribute('retrieve_id'); }
473 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
474 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
475 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
476 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
477 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
478 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
480 'on_click' : function(ev) {
481 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
482 var row = {}; var col = {}; var nobj = {};
483 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
484 if (row.value == -1) return;
485 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
486 if (treeItem.nodeName != 'treeitem') return;
487 var treeRow = treeItem.firstChild;
488 var treeCell = treeRow.firstChild;
489 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
490 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
491 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
493 distribute_payment();
496 'on_sort' : function() {
499 'on_checkbox_toggle' : function(toggle) {
501 var retrieve_ids = g.bill_list.dump_retrieve_ids();
502 for (var i = 0; i < retrieve_ids.length; i++) {
503 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
504 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
508 alert('error in on_checkbox_toggle(): ' + E);
511 'retrieve_row' : function(params) {
513 var id = params.retrieve_id;
514 var row = params.row;
516 function handle_props(row) {
518 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
519 util.widgets.addProperty(params.row_node.firstChild,'refundable');
520 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
522 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
523 $('circulating_hint').hidden = false;
524 util.widgets.addProperty(params.row_node.firstChild,'circulating');
525 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
528 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
529 alert('Error setting list properties in bill2.js: ' + E);
534 if (typeof row.my == 'undefined') row.my = {};
535 if (typeof row.my.mbts == 'undefined' ) {
536 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
537 var blob = req.getResultObject();
538 row.my.mbts = blob.transaction;
539 row.my.circ = blob.circ;
540 row.my.acp = blob.copy;
541 row.my.mvr = blob.record;
542 if (typeof params.on_retrieve == 'function') {
543 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
544 row.my.checked = false;
547 params.on_retrieve(row);
549 g.bill_map[ id ] = blob;
550 g.check_map[ id ] = row.my.checked;
554 if (typeof params.on_retrieve == 'function') {
556 params.on_retrieve(row);
560 if (typeof params.on_retrieve == 'function') {
561 params.on_retrieve(row);
567 alert('Error in bill2.js, retrieve_row(): ' + E);
572 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
573 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
574 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
575 g.bill_list.set_list_actions();
578 function handle_add() {
579 if(g.bill_list_selection.length > 1) {
580 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
582 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
585 var r = g.error.yns_alert(msg,
586 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
587 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
588 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
589 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
591 JSAN.use('util.window');
592 var win = new util.window();
593 for (var i = 0; i < g.bill_list_selection.length; i++) {
595 urls.XUL_PATRON_BILL_WIZARD,
597 'chrome,resizable,modal',
598 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
602 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
606 function handle_void_all() {
607 if(g.bill_list_selection.length > 1) {
608 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
610 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
613 var r = g.error.yns_alert(msg,
614 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
615 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
616 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
617 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
619 for (var i = 0; i < g.bill_list_selection.length; i++) {
620 void_all_billings( g.bill_list_selection[i] );
623 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
624 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
628 function handle_opac() {
631 for (var i = 0; i < g.bill_list_selection.length; i++) {
632 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
633 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
634 if (typeof my_mvr != 'undefined' && my_mvr != null) {
635 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
638 JSAN.use('cat.util');
639 cat.util.show_in_opac( ids );
641 alert('Error in bill2.js, handle_opac: ' + E);
645 function handle_copy_details() {
648 for (var i = 0; i < g.bill_list_selection.length; i++) {
649 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
650 if (typeof my_acp != 'undefined' && my_acp != null) {
651 ids.push( my_acp.barcode() );
654 JSAN.use('circ.util');
655 circ.util.item_details_new( ids );
657 alert('Error in bill2.js, handle_opac: ' + E);
661 function handle_details() {
662 JSAN.use('util.window'); var win = new util.window();
663 for (var i = 0; i < g.bill_list_selection.length; i++) {
664 var my_xulG = win.open(
665 urls.XUL_PATRON_BILL_DETAILS,
666 'test_billdetails_' + g.bill_list_selection[i],
669 'patron_id' : g.patron_id,
670 'mbts_id' : g.bill_list_selection[i],
671 'refresh' : function() {
673 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
675 'new_tab' : xulG.new_tab,
676 'url_prefix' : xulG.url_prefix
682 function print_bills() {
684 var template = 'bills_historical'; if (xul_param('current')) template = 'bills_current';
685 JSAN.use('patron.util');
686 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
689 'printer_context' : 'receipt',
690 'template' : template
692 g.bill_list.print(params);
694 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
698 function distribute_payment() {
700 JSAN.use('util.money');
701 var tb = $('payment');
702 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
703 tb.setAttribute('value', tb.value );
704 var total = util.money.dollars_float_to_cents_integer( tb.value );
705 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
706 var retrieve_ids = g.bill_list.dump_retrieve_ids();
707 for (var i = 0; i < retrieve_ids.length; i++) {
708 var row_params = g.row_map[retrieve_ids[i]];
709 if (g.check_map[retrieve_ids[i]]) {
710 var bill = g.bill_map[retrieve_ids[i]].transaction;
711 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
713 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
716 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
720 row_params.row.my.payment_pending = '0.00';
722 g.bill_list.refresh_row(row_params);
726 alert('Error in bill2.js, distribute_payment(): ' + E);
730 function apply_payment() {
732 var payment_blob = {};
733 JSAN.use('util.window');
734 var win = new util.window();
735 switch($('payment_type').value) {
736 case 'credit_card_payment' :
738 g.data.stash('temp');
739 var my_xulG = win.open(
740 urls.XUL_PATRON_BILL_CC_INFO,
742 'chrome,resizable,modal',
743 {'patron_id': g.patron_id}
745 g.data.stash_retrieve();
746 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
748 case 'check_payment' :
750 g.data.stash('temp');
751 var my_xulG = win.open(
752 urls.XUL_PATRON_BILL_CHECK_INFO,
754 'chrome,resizable,modal'
756 g.data.stash_retrieve();
757 payment_blob = JSON2js( g.data.temp );
761 (typeof payment_blob == 'undefined') ||
763 payment_blob.cancelled=='true'
765 alert( $('commonStrings').getString('common.cancelled') );
768 payment_blob.userid = g.patron_id;
769 payment_blob.note = payment_blob.note || '';
770 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
771 payment_blob.payment_type = $('payment_type').value;
772 var tally_blob = tally_pending();
773 payment_blob.payments = tally_blob.payments;
774 // Handle patron credit
775 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
776 if ( $('convert_change_to_credit').checked ) {
777 // No need to convert credit into credit, handled automatically
778 payment_blob.patron_credit = '0.00';
780 // Cashing out extra credit as change
781 payment_blob.patron_credit = 0 - tally_blob.change;
783 } else if ( $('convert_change_to_credit').checked ) {
784 // Saving change from a non-credit payment as patron credit on server
785 payment_blob.patron_credit = tally_blob.change;
787 payment_blob.patron_credit = '0.00';
789 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
790 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
793 if ( pay( payment_blob ) ) {
795 $('payment').value = ''; $('payment').select(); $('payment').focus();
796 refresh({'clear_voided_summary':true});
797 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
798 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
799 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
803 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
804 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
805 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
806 if (no_print_prompting) {
807 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
809 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
810 g.data.stash_retrieve();
811 var template = 'bill_payment';
812 JSAN.use('patron.util'); JSAN.use('util.functional');
815 'lib' : g.data.hash.aou[ ses('ws_ou') ],
816 'staff' : ses('staff'),
817 'header' : g.data.print_list_templates[template].header,
818 'line_item' : g.data.print_list_templates[template].line_item,
819 'footer' : g.data.print_list_templates[template].footer,
820 'type' : g.data.print_list_templates[template].type,
821 'list' : util.functional.map_list(
822 payment_blob.payments,
827 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
828 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
829 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
830 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
834 'data' : g.previous_summary
836 g.error.sdump('D_DEBUG',js2JSON(params));
837 if ($('printer_prompt').hasAttribute('checked')) {
838 if ($('printer_prompt').getAttribute('checked')) {
839 params.no_prompt = false;
841 params.no_prompt = true;
844 params.no_prompt = true;
846 JSAN.use('util.print'); var print = new util.print('receipt');
847 for (var i = 0; i < $('num_of_receipts').value; i++) {
848 print.tree_list( params );
851 g.error.standard_unexpected_error_alert('bill receipt', E);
855 alert('Error in bill2.js, apply_payment(): ' + E);
859 function pay(payment_blob) {
861 var x = $('annotate_payment');
862 if (x && x.checked && (! payment_blob.note)) {
863 payment_blob.note = window.prompt(
864 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
866 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
869 g.previous_summary = {
870 original_balance : $('tb_total_owed').value,
871 voided_balance : $('currently_voided').value,
872 payment_received : $('payment').value,
873 payment_applied : $('pending_payment').value,
874 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
875 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
876 new_balance : util.money.cents_as_dollars(
877 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
878 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
880 payment_type : $('payment_type').getAttribute('label'),
881 note : payment_blob.note
883 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
884 if (typeof robj.ilsevent != 'undefined') {
885 switch(robj.textcode) {
886 case 'SUCCESS' : return true; break;
887 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
888 case 'INVALID_USER_XACT_ID' :
889 refresh(); default_focus();
890 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
891 default: throw(robj); break;
896 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
901 function refresh(params) {
903 if (params && params.clear_voided_summary) {
904 g.data.voided_billings = []; g.data.stash('voided_billings');
908 retrieve_mbts_for_list();
910 distribute_payment();
912 alert('Error in bill2.js, refresh(): ' + E);
916 function void_all_billings(mobts_id) {
918 JSAN.use('util.functional');
920 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
921 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
923 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
925 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
928 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
929 sum = util.money.cents_as_dollars( sum );
931 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
932 var r = g.error.yns_alert(msg,
933 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
934 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
935 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
936 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
938 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
940 switch(Number(robj.ilsevent)) {
941 case 5000 /* PERM_FAILURE */:
945 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
951 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
952 for (var i = 0; i < mb_list.length; i++) {
953 g.data.voided_billings.push( mb_list[i] );
955 g.data.stash('voided_billings');
958 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
962 function refresh_patron() {
963 JSAN.use('patron.util'); JSAN.use('util.money');
964 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
965 var au_obj = req.getResultObject();
966 if (typeof au_obj.ilsevent == 'undefined') {
968 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));