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;
184 $('apply_payment_btn').disabled = false;
186 alert('Error in bill2.js, apply_payment_btn: ' + E);
193 alert('Error in bill2.js, event_listeners(): ' + E);
197 function $(id) { return document.getElementById(id); }
199 function default_focus() {
200 try { $('payment').focus(); } catch(E) { alert('Error in default_focus(): ' + E); }
203 function tally_pending() {
206 JSAN.use('util.money');
207 var tb = $('payment');
208 var payment_tendered = util.money.dollars_float_to_cents_integer( tb.value );
209 var payment_pending = 0;
210 var retrieve_ids = g.bill_list.dump_retrieve_ids();
211 for (var i = 0; i < retrieve_ids.length; i++) {
212 var row_params = g.row_map[retrieve_ids[i]];
213 if (g.check_map[retrieve_ids[i]]) {
214 var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending );
215 payment_pending += value;
216 if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); }
219 var change_pending = payment_tendered - payment_pending;
220 $('pending_payment').value = util.money.cents_as_dollars( payment_pending );
221 $('pending_change').value = util.money.cents_as_dollars( change_pending );
222 $('change_due').value = util.money.cents_as_dollars( change_pending );
223 return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) };
225 alert('Error in bill2.js, tally_pending(): ' + E);
229 function tally_selected() {
231 JSAN.use('util.money');
232 var selected_billed = 0;
233 var selected_paid = 0;
234 var selected_balance = 0;
236 for (var i = 0; i < g.bill_list_selection.length; i++) {
237 var bill = g.bill_map[g.bill_list_selection[i]];
239 //$('checked_owed').setAttribute('value', '???');
240 //$('checked_billed').setAttribute('value', '???');
241 //$('checked_paid').setAttribute('value', '???');
244 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
245 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
246 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
247 selected_billed += to;
249 selected_balance += bo;
251 //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) );
252 //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) );
253 //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) );
255 alert('Error in bill2.js, tally_selected(): ' + E);
259 function tally_voided() {
261 JSAN.use('util.money');
262 var voided_total = 0;
264 g.data.stash_retrieve();
266 for (var i = 0; i < g.data.voided_billings.length; i++) {
267 var billing = g.data.voided_billings[i];
268 var bv = util.money.dollars_float_to_cents_integer( billing.amount() );
271 $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) );
273 alert('Error in bill2.js, tally_voided(): ' + E);
277 function tally_all() {
279 JSAN.use('util.money');
280 var checked_billed = 0;
281 var checked_paid = 0;
282 var checked_balance = 0;
283 var total_billed = 0;
285 var total_balance = 0;
286 var refunds_owed = 0;
288 var retrieve_ids = g.bill_list.dump_retrieve_ids();
289 for (var i = 0; i < retrieve_ids.length; i++) {
290 var bill = g.bill_map[retrieve_ids[i]];
292 $('checked_owed').value = '???';
293 $('checked_owed2').setAttribute('value', '???');
294 $('checked_billed').value = '???';
295 $('checked_paid').value = '???';
296 $('tb_total_owed').value = '???';
297 $('total_owed2').setAttribute('value', '???');
298 $('total_billed').value = '???';
299 $('tb_total_paid').value = '???';
300 $('refunds_owed').setAttribute('value', '???');
303 var to = util.money.dollars_float_to_cents_integer( bill.transaction.total_owed() );
304 var tp = util.money.dollars_float_to_cents_integer( bill.transaction.total_paid() );
305 var bo = util.money.dollars_float_to_cents_integer( bill.transaction.balance_owed() );
309 if ( bo < 0 ) refunds_owed += bo;
310 if (g.check_map[retrieve_ids[i]]) {
311 checked_billed += to;
313 checked_balance += bo;
316 $('checked_billed').value = util.money.cents_as_dollars( checked_billed );
317 $('checked_paid').value = util.money.cents_as_dollars( checked_paid );
318 $('checked_owed').value = util.money.cents_as_dollars( checked_balance );
319 $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) );
320 $('total_billed').value = util.money.cents_as_dollars( total_billed );
321 $('tb_total_paid').value = util.money.cents_as_dollars( total_paid );
322 $('tb_total_owed').value = util.money.cents_as_dollars( total_balance );
323 $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) );
324 $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) );
327 alert('Error in bill2.js, tally_all(): ' + E);
331 function handle_refund() {
332 if(g.bill_list_selection.length > 1) {
333 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_plural', [g.bill_list_selection]);
335 var msg = $("patronStrings").getFormattedString('staff.patron.bills.handle_refund.message_singular', [g.bill_list_selection]);
338 var r = g.error.yns_alert(msg,
339 $("patronStrings").getString('staff.patron.bills.handle_refund.title'),
340 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_yes'),
341 $("patronStrings").getString('staff.patron.bills.handle_refund.btn_no'),null,
342 $("patronStrings").getString('staff.patron.bills.handle_refund.confirm_message'));
344 for (var i = 0; i < g.bill_list_selection.length; i++) {
345 var bill_id = g.bill_list_selection[i];
346 //alert('g.check_map['+bill_id+'] = '+g.check_map[bill_id]+' bill_map['+bill_id+'] = ' + js2JSON(g.bill_map[bill_id]));
347 g.check_map[bill_id] = true;
348 var row_params = g.row_map[bill_id];
349 row_params.row.my.checked = true;
350 g.bill_list.refresh_row(row_params);
354 distribute_payment();
358 function check_all() {
360 for (var i in g.bill_map) {
361 g.check_map[i] = true;
362 var row_params = g.row_map[i];
363 row_params.row.my.checked = true;
364 g.bill_list.refresh_row(row_params);
367 distribute_payment();
369 alert('Error in bill2.js, check_all(): ' + E);
374 function uncheck_all() {
376 for (var i in g.bill_map) {
377 g.check_map[i] = false;
378 var row_params = g.row_map[i];
379 row_params.row.my.checked = false;
380 g.bill_list.refresh_row(row_params);
383 distribute_payment();
385 alert('Error in bill2.js, check_all(): ' + E);
390 function check_all_refunds() {
392 for (var i in g.bill_map) {
393 if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) {
394 g.check_map[i] = true;
395 var row_params = g.row_map[i];
396 row_params.row.my.checked = true;
397 g.bill_list.refresh_row(row_params);
401 distribute_payment();
403 alert('Error in bill2.js, check_all_refunds(): ' + E);
407 function gen_list_append_func(r) {
409 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 } } } );
410 } else { g.row_map[r] = g.bill_list.append( { 'retrieve_id' : r, 'flesh_immediately' : true, 'row' : { 'my' : { 'checked' : true } } } ); }
414 function retrieve_mbts_for_list() {
415 var method = 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative';
416 g.mbts_ids = g.network.simple_request(method,[ses(),g.patron_id]);
417 if (g.mbts_ids.ilsevent) {
418 switch(Number(g.mbts_ids.ilsevent)) {
419 case -1: g.error.standard_network_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again')); break;
420 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;
422 } else if (g.mbts_ids == null) {
423 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again'),null);
426 g.mbts_ids.reverse();
428 for (var i = 0; i < g.mbts_ids.length; i++) {
429 dump('i = ' + i + ' g.mbts_ids[i] = ' + g.mbts_ids[i] + '\n');
430 g.funcs.push( gen_list_append_func(g.mbts_ids[i]) );
435 function init_lists() {
436 JSAN.use('util.list'); JSAN.use('circ.util');
438 g.bill_list_selection = [];
440 g.bill_list = new util.list('bill_tree');
446 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;',
447 'render' : function(my) { return String( my.checked ) == 'true'; },
450 patron.util.mbts_columns({
451 'mbts_xact_finish' : { 'hidden' : xul_param('current') ? true : false }
455 'title' : { 'hidden' : false, 'flex' : '3' }
460 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money',
461 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'),
462 'render' : function(my) { return my.payment_pending || '0.00'; },
466 'map_row_to_columns' : patron.util.std_map_row_to_columns(' '),
467 'on_select' : function(ev) {
468 JSAN.use('util.functional');
469 g.bill_list_selection = util.functional.map_list(
470 g.bill_list.retrieve_selection(),
471 function(o) { return o.getAttribute('retrieve_id'); }
474 $('details').setAttribute('disabled', g.bill_list_selection.length == 0);
475 $('add').setAttribute('disabled', g.bill_list_selection.length == 0);
476 $('voidall').setAttribute('disabled', g.bill_list_selection.length == 0);
477 $('refund').setAttribute('disabled', g.bill_list_selection.length == 0);
478 $('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
479 $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
481 'on_click' : function(ev) {
482 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead');
483 var row = {}; var col = {}; var nobj = {};
484 g.bill_list.node.treeBoxObject.getCellAt(ev.clientX,ev.clientY,row,col,nobj);
485 if (row.value == -1) return;
486 var treeItem = g.bill_list.node.contentView.getItemAtIndex(row.value);
487 if (treeItem.nodeName != 'treeitem') return;
488 var treeRow = treeItem.firstChild;
489 var treeCell = treeRow.firstChild;
490 if (g.check_map[ treeItem.getAttribute('retrieve_id') ] != (treeCell.getAttribute('value') == 'true')) {
491 g.check_map[ treeItem.getAttribute('retrieve_id') ] = treeCell.getAttribute('value') == 'true';
492 g.row_map[ treeItem.getAttribute('retrieve_id') ].row.my.checked = treeCell.getAttribute('value') == 'true';
494 distribute_payment();
497 'on_sort' : function() {
500 'on_checkbox_toggle' : function(toggle) {
502 var retrieve_ids = g.bill_list.dump_retrieve_ids();
503 for (var i = 0; i < retrieve_ids.length; i++) {
504 g.check_map[ retrieve_ids[i] ] = (toggle=='on');
505 g.row_map[ retrieve_ids[i] ].row.my.checked = (toggle=='on');
509 alert('error in on_checkbox_toggle(): ' + E);
512 'retrieve_row' : function(params) {
514 var id = params.retrieve_id;
515 var row = params.row;
517 function handle_props(row) {
519 if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
520 util.widgets.addProperty(params.row_node.firstChild,'refundable');
521 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.payment_pending_column_idx ],'refundable');
523 if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) {
524 $('circulating_hint').hidden = false;
525 util.widgets.addProperty(params.row_node.firstChild,'circulating');
526 util.widgets.addProperty(params.row_node.firstChild.childNodes[ g.title_column_idx ],'circulating');
529 g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E);
530 alert('Error setting list properties in bill2.js: ' + E);
535 if (typeof row.my == 'undefined') row.my = {};
536 if (typeof row.my.mbts == 'undefined' ) {
537 g.network.simple_request('BLOB_MBTS_DETAILS_RETRIEVE',[ses(),id], function(req) {
538 var blob = req.getResultObject();
539 row.my.mbts = blob.transaction;
540 row.my.circ = blob.circ;
541 row.my.acp = blob.copy;
542 row.my.mvr = blob.record;
543 if (typeof params.on_retrieve == 'function') {
544 if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) {
545 row.my.checked = false;
548 params.on_retrieve(row);
550 g.bill_map[ id ] = blob;
551 g.check_map[ id ] = row.my.checked;
555 if (typeof params.on_retrieve == 'function') {
557 params.on_retrieve(row);
561 if (typeof params.on_retrieve == 'function') {
562 params.on_retrieve(row);
568 alert('Error in bill2.js, retrieve_row(): ' + E);
573 g.title_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'title' );
574 g.payment_pending_column_idx = util.functional.map_list( g.bill_list.columns, function(o) { return o.id; } ).indexOf( 'payment_pending' );
575 $('bill_list_actions').appendChild( g.bill_list.render_list_actions() );
576 g.bill_list.set_list_actions();
579 function handle_add() {
580 if(g.bill_list_selection.length > 1) {
581 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
583 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]);
586 var r = g.error.yns_alert(msg,
587 $("patronStrings").getString('staff.patron.bill_history.handle_add.title'),
588 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_yes'),
589 $("patronStrings").getString('staff.patron.bill_history.handle_add.btn_no'),null,
590 $("patronStrings").getString('staff.patron.bill_history.handle_add.confirm_message'));
592 JSAN.use('util.window');
593 var win = new util.window();
594 for (var i = 0; i < g.bill_list_selection.length; i++) {
596 urls.XUL_PATRON_BILL_WIZARD,
598 'chrome,resizable,modal',
599 { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] }
603 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
607 function handle_void_all() {
608 if(g.bill_list_selection.length > 1) {
609 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]);
611 var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]);
614 var r = g.error.yns_alert(msg,
615 $("patronStrings").getString('staff.patron.bill_history.handle_void.title'),
616 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'),
617 $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null,
618 $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message'));
620 for (var i = 0; i < g.bill_list_selection.length; i++) {
621 void_all_billings( g.bill_list_selection[i] );
624 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
625 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
629 function handle_opac() {
632 for (var i = 0; i < g.bill_list_selection.length; i++) {
633 var my_mvr = g.bill_map[ g.bill_list_selection[i] ].record;
634 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
635 if (typeof my_mvr != 'undefined' && my_mvr != null) {
636 ids.push( { 'barcode' : my_acp.barcode(), 'doc_id' : my_mvr.doc_id() } );
639 JSAN.use('cat.util');
640 cat.util.show_in_opac( ids );
642 alert('Error in bill2.js, handle_opac: ' + E);
646 function handle_copy_details() {
649 for (var i = 0; i < g.bill_list_selection.length; i++) {
650 var my_acp = g.bill_map[ g.bill_list_selection[i] ].copy;
651 if (typeof my_acp != 'undefined' && my_acp != null) {
652 ids.push( my_acp.barcode() );
655 JSAN.use('circ.util');
656 circ.util.item_details_new( ids );
658 alert('Error in bill2.js, handle_opac: ' + E);
662 function handle_details() {
663 JSAN.use('util.window'); var win = new util.window();
664 for (var i = 0; i < g.bill_list_selection.length; i++) {
665 var my_xulG = win.open(
666 urls.XUL_PATRON_BILL_DETAILS,
667 'test_billdetails_' + g.bill_list_selection[i],
670 'patron_id' : g.patron_id,
671 'mbts_id' : g.bill_list_selection[i],
672 'refresh' : function() {
674 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
676 'new_tab' : xulG.new_tab,
677 'url_prefix' : xulG.url_prefix
683 function print_bills() {
685 var template = 'bills_historical'; if (xul_param('current')) template = 'bills_current';
686 JSAN.use('patron.util');
687 g.patron = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null);
690 'printer_context' : 'receipt',
691 'template' : template
693 g.bill_list.print(params);
695 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_history.print_bills.print_error'), E);
699 function distribute_payment() {
701 JSAN.use('util.money');
702 var tb = $('payment');
703 tb.value = util.money.cents_as_dollars( util.money.dollars_float_to_cents_integer( tb.value ) );
704 tb.setAttribute('value', tb.value );
705 var total = util.money.dollars_float_to_cents_integer( tb.value );
706 if (total < 0) { tb.value = '0.00'; tb.setAttribute('value','0.00'); total = 0; }
707 var retrieve_ids = g.bill_list.dump_retrieve_ids();
708 for (var i = 0; i < retrieve_ids.length; i++) {
709 var row_params = g.row_map[retrieve_ids[i]];
710 if (g.check_map[retrieve_ids[i]]) {
711 var bill = g.bill_map[retrieve_ids[i]].transaction;
712 var bo = util.money.dollars_float_to_cents_integer( bill.balance_owed() );
714 row_params.row.my.payment_pending = util.money.cents_as_dollars( total );
717 row_params.row.my.payment_pending = util.money.cents_as_dollars( bo );
721 row_params.row.my.payment_pending = '0.00';
723 g.bill_list.refresh_row(row_params);
727 alert('Error in bill2.js, distribute_payment(): ' + E);
731 function apply_payment() {
733 var payment_blob = {};
734 JSAN.use('util.window');
735 var win = new util.window();
736 switch($('payment_type').value) {
737 case 'credit_card_payment' :
739 g.data.stash('temp');
740 var my_xulG = win.open(
741 urls.XUL_PATRON_BILL_CC_INFO,
743 'chrome,resizable,modal',
744 {'patron_id': g.patron_id}
746 g.data.stash_retrieve();
747 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
749 case 'check_payment' :
751 g.data.stash('temp');
752 var my_xulG = win.open(
753 urls.XUL_PATRON_BILL_CHECK_INFO,
755 'chrome,resizable,modal'
757 g.data.stash_retrieve();
758 payment_blob = JSON2js( g.data.temp );
762 (typeof payment_blob == 'undefined') ||
764 payment_blob.cancelled=='true'
766 alert( $('commonStrings').getString('common.cancelled') );
769 payment_blob.userid = g.patron_id;
770 payment_blob.note = payment_blob.note || '';
771 //payment_blob.cash_drawer = 1; // FIXME: get new Config() to work
772 payment_blob.payment_type = $('payment_type').value;
773 var tally_blob = tally_pending();
774 payment_blob.payments = tally_blob.payments;
775 // Handle patron credit
776 if ( payment_blob.payment_type == 'credit_payment' ) { // paying with patron credit
777 if ( $('convert_change_to_credit').checked ) {
778 // No need to convert credit into credit, handled automatically
779 payment_blob.patron_credit = '0.00';
781 // Cashing out extra credit as change
782 payment_blob.patron_credit = 0 - tally_blob.change;
784 } else if ( $('convert_change_to_credit').checked ) {
785 // Saving change from a non-credit payment as patron credit on server
786 payment_blob.patron_credit = tally_blob.change;
788 payment_blob.patron_credit = '0.00';
790 if ( payment_blob.payments.length == 0 && payment_blob.patron_credit == '0.00' ) {
791 alert($("patronStrings").getString('staff.patron.bills.apply_payment.nothing_applied'));
794 if ( pay( payment_blob ) ) {
796 $('payment').value = ''; $('payment').select(); $('payment').focus();
797 refresh({'clear_voided_summary':true});
798 if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh();
799 if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change();
800 if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) {
804 if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt
805 if ( ! $('receipt_upon_payment').getAttribute('checked') ) { return; } // Skip print attempt
806 var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
807 if (no_print_prompting) {
808 if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt
810 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
811 g.data.stash_retrieve();
812 var template = 'bill_payment';
813 JSAN.use('patron.util'); JSAN.use('util.functional');
816 'lib' : g.data.hash.aou[ ses('ws_ou') ],
817 'staff' : ses('staff'),
818 'header' : g.data.print_list_templates[template].header,
819 'line_item' : g.data.print_list_templates[template].line_item,
820 'footer' : g.data.print_list_templates[template].footer,
821 'type' : g.data.print_list_templates[template].type,
822 'list' : util.functional.map_list(
823 payment_blob.payments,
828 'last_billing_type' : g.bill_map[ o[0] ].transaction.last_billing_type(),
829 'last_billing_note' : g.bill_map[ o[0] ].transaction.last_billing_note(),
830 'title' : typeof g.bill_map[ o[0] ].record != 'undefined' ? g.bill_map[ o[0] ].record.title() : '',
831 'barcode' : typeof g.bill_map[ o[0] ].copy != 'undefined' ? g.bill_map[ o[0] ].copy.barcode() : ''
835 'data' : g.previous_summary
837 g.error.sdump('D_DEBUG',js2JSON(params));
838 if ($('printer_prompt').hasAttribute('checked')) {
839 if ($('printer_prompt').getAttribute('checked')) {
840 params.no_prompt = false;
842 params.no_prompt = true;
845 params.no_prompt = true;
847 JSAN.use('util.print'); var print = new util.print('receipt');
848 for (var i = 0; i < $('num_of_receipts').value; i++) {
849 print.tree_list( params );
852 g.error.standard_unexpected_error_alert('bill receipt', E);
856 alert('Error in bill2.js, apply_payment(): ' + E);
860 function pay(payment_blob) {
862 var x = $('annotate_payment');
863 if (x && x.checked && (! payment_blob.note)) {
864 payment_blob.note = window.prompt(
865 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment'),
867 $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title')
870 g.previous_summary = {
871 original_balance : $('tb_total_owed').value,
872 voided_balance : $('currently_voided').value,
873 payment_received : $('payment').value,
874 payment_applied : $('pending_payment').value,
875 change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value,
876 credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0,
877 new_balance : util.money.cents_as_dollars(
878 util.money.dollars_float_to_cents_integer( $('tb_total_owed').value ) -
879 util.money.dollars_float_to_cents_integer( $('pending_payment').value )
881 payment_type : $('payment_type').getAttribute('label'),
882 note : payment_blob.note
884 var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob, g.patron.last_xact_id() ]);
885 if (typeof robj.ilsevent != 'undefined') {
886 switch(robj.textcode) {
887 case 'SUCCESS' : return true; break;
888 case 'REFUND_EXCEEDS_DESK_PAYMENTS' : alert($("patronStrings").getFormattedString('staff.patron.bills.pay.refund_exceeds_desk_payment', [robj.desc])); return false; break;
889 case 'INVALID_USER_XACT_ID' :
890 refresh(); default_focus();
891 alert($("patronStrings").getFormattedString('staff.patron.bills.pay.invalid_user_xact_id', [robj.desc])); return false; break;
892 default: throw(robj); break;
897 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E);
902 function refresh(params) {
904 if (params && params.clear_voided_summary) {
905 g.data.voided_billings = []; g.data.stash('voided_billings');
909 retrieve_mbts_for_list();
911 distribute_payment();
913 alert('Error in bill2.js, refresh(): ' + E);
917 function void_all_billings(mobts_id) {
919 JSAN.use('util.functional');
921 var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] );
922 if (typeof mb_list.ilsevent != 'undefined') throw(mb_list);
924 mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) });
926 if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; }
929 for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() );
930 sum = util.money.cents_as_dollars( sum );
932 var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]);
933 var r = g.error.yns_alert(msg,
934 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'),
935 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'),
936 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null,
937 $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message'));
939 var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();})));
941 switch(Number(robj.ilsevent)) {
942 case 5000 /* PERM_FAILURE */:
946 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj);
952 g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = [];
953 for (var i = 0; i < mb_list.length; i++) {
954 g.data.voided_billings.push( mb_list[i] );
956 g.data.stash('voided_billings');
959 try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); }
963 function refresh_patron() {
964 JSAN.use('patron.util'); JSAN.use('util.money');
965 patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id,null,function(req) {
966 var au_obj = req.getResultObject();
967 if (typeof au_obj.ilsevent == 'undefined') {
969 $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() ));