From: phasefx Date: Tue, 8 Dec 2009 14:23:29 +0000 (+0000) Subject: This wires up most of the new billing interface, which has aesthetic and internal... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8d84ae5d0a4c573d728c6a161ea80465f178b639;p=contrib%2FConifer.git This wires up most of the new billing interface, which has aesthetic and internal changes, but not a lot of new functionality (if any) yet. Let me know if we lost anything. Also some drive-by edits to other files: lighter-weight refresh callback for billing interface in display.js tweaks to logging levels in error.js default non-maximized window size for the main menu in menu_frame.xul some utility functions (addProperty, removeProperty) in widgets.js an attempt to workaround the "parent window loses focus or gets lowered behind another application after a child modal window closes" issue in window.js made the patron.util.retrieve_au_via_id utility method .authoritative tweaked the CSS for currently selected rows in lists/trees whitespace/indentation in bill_history.js TODO: Wire up Refund and Show in Catalog menu options (though refunds should be working via the checkbox column). Provide an alternate bill history view which centers around payments received, rather than the billable transactions WISHLIST: Library filtering for transactions. The interface is currently using open-ils.actor.user.transaction.fleshed.retrieve for fleshing rows; if we could get it to return a generalized location field regardless of the transaction type (circ, grocery, booking, etc.), then this'll be much easier to do in the client. git-svn-id: svn://svn.open-ils.org/ILS/trunk@15097 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 6108fba049..7c8bf63a37 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -2556,13 +2556,35 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 5687bfa2a5..1d22a879db 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -337,7 +337,7 @@ const urls = { 'XUL_REMOTE_OPAC_WRAPPER' : '/xul/server/cat/opac.xul', 'XUL_OPAC_WRAPPER' : 'chrome://open_ils_staff_client/content/cat/opac.xul', 'XUL_PATRON_BARCODE_ENTRY' : '/xul/server/patron/barcode_entry.xul', - 'XUL_PATRON_BILLS' : '/xul/server/patron/bills.xul', + 'XUL_PATRON_BILLS' : '/xul/server/patron/bill2.xul', 'XUL_PATRON_BILL_CC_INFO' : '/xul/server/patron/bill_cc_info.xul', 'XUL_PATRON_BILL_CHECK_INFO' : '/xul/server/patron/bill_check_info.xul', 'XUL_PATRON_BILL_DETAILS' : '/xul/server/patron/bill_details.xul', diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul index cb044095bf..9b87990346 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul @@ -29,7 +29,7 @@ diff --git a/Open-ILS/xul/staff_client/chrome/content/util/error.js b/Open-ILS/xul/staff_client/chrome/content/util/error.js index 70f0829c14..9ab2510ca2 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/error.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/error.js @@ -57,7 +57,7 @@ util.error.prototype = { 'D_DEBUG' : { 'debug' : true, 'console' : true }, 'D_TRACE' : { 'debug' : false }, 'D_ALERT' : { 'alert' : true, 'debug' : true }, - 'D_WARN' : { 'debug' : false }, + 'D_WARN' : { 'debug' : true }, 'D_COLUMN_RENDER_ERROR' : { 'debug' : false }, 'D_XULRUNNER' : { 'debug' : false }, 'D_DECK' : { 'debug' : false }, @@ -116,7 +116,7 @@ util.error.prototype = { 'D_CACHE' : { 'debug' : false, 'console' : false, 'alert' : false }, 'D_SES' : { 'debug' : true, 'console' : true }, 'D_SES_FUNC' : { 'debug' : false }, - 'D_SES_RESULT' : { 'debug' : false }, + 'D_SES_RESULT' : { 'debug' : true }, 'D_SES_ERROR' : { 'debug' : true, 'console' : true }, 'D_SPAWN' : { 'debug' : false }, 'D_STRING' : { 'debug' : false }, diff --git a/Open-ILS/xul/staff_client/chrome/content/util/widgets.js b/Open-ILS/xul/staff_client/chrome/content/util/widgets.js index 683c6acc60..0ef5dd95ad 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/widgets.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/widgets.js @@ -405,4 +405,47 @@ util.widgets.load_attributes = function (file) { } } +util.widgets.addProperty = function(e,c) { + if(!e || !c) return; + + var prop_class_string = e.getAttribute('properties'); + var prop_class_array; + + if(prop_class_string) + prop_class_array = prop_class_string.split(/\s+/); + + var string_ip = ""; /*strip out nulls*/ + for (var prop_class in prop_class_array) { + if (prop_class_array[prop_class] == c) { return; } + if(prop_class_array[prop_class] !=null) + string_ip += prop_class_array[prop_class] + " "; + } + string_ip += c; + e.setAttribute('properties',string_ip); +} + +util.widgets.removeProperty = function(e, c) { + if(!e || !c) return; + + var prop_class_string = ''; + + var prop_class_array = e.getAttribute('properties'); + if( prop_class_array ) + prop_class_array = prop_class_array.split(/\s+/); + + var first = 1; + for (var prop_class in prop_class_array) { + if (prop_class_array[prop_class] != c) { + if (first == 1) { + prop_class_string = prop_class_array[prop_class]; + first = 0; + } else { + prop_class_string = prop_class_string + ' ' + + prop_class_array[prop_class]; + } + } + } + e.setAttribute('properties', prop_class_string); +} + dump('exiting util/widgets.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/util/window.js b/Open-ILS/xul/staff_client/chrome/content/util/window.js index bce563288e..9d803670a2 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/window.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/window.js @@ -100,6 +100,7 @@ util.window.prototype = { data.init({'via':'stash'}); var x = data.modal_xulG_stack[key].pop(); data.stash('modal_xulG_stack'); + w.focus(); return x; } else { if (my_xulG) { diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties index 99e3957bfe..0286f9da7f 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties @@ -10,6 +10,7 @@ staff.patron.barcode_entry.patron_consent_deny=Deny staff.patron.barcode_entry.patron_consent_confirm=Check here to confirm this message staff.patron.barcode_entry.patron_display_error=spawning patron display staff.patron.barcode_entry.user_perm_display_error=spawning user perm editor +staff.patron.bill_interface.payment_pending.column_header=Payment Pending staff.patron.bill_cc_info.need_cc_number=You must provide a credit card number staff.patron.bill_cc_info.need_approval_code=You must provide an approval code or an imprint slip number staff.patron.bill_details.my_init.error=bill_details.xul, my_init: @@ -26,7 +27,6 @@ staff.patron.bill_details.handle_void.confirm_void_billing_yes=Yes staff.patron.bill_details.handle_void.confirm_void_billing_no=No staff.patron.bill_details.handle_void.confirm_void_billing_confirm_message=Check here to confirm this message staff.patron.bill_details.handle_void.voiding_error=Error voiding bills. -staff.patron.bill_details.handle_void.billings_voided=Billings voided. staff.patron.bill_history.retrieve_mbts_for_list.close_win_try_again=Please close this window and try again. staff.patron.bill_history.my_init.current_bills=Current Bills staff.patron.bill_history.my_init.bill_history=Bill History @@ -36,6 +36,12 @@ staff.patron.bill_history.handle_add.title=Bill Patron staff.patron.bill_history.handle_add.btn_yes=Yes staff.patron.bill_history.handle_add.btn_no=No staff.patron.bill_history.handle_add.confirm_message=Check here to confirm this message +staff.patron.bill_history.handle_void.message_plural=Are you sure you would like to void all billings on bills %1$s? +staff.patron.bill_history.handle_void.message_singular=Are you sure you would like to void all billings on bill %1$s? +staff.patron.bill_history.handle_void.title=Void All Billings +staff.patron.bill_history.handle_void.btn_yes=Yes +staff.patron.bill_history.handle_void.btn_no=No +staff.patron.bill_history.handle_void.confirm_message=Check here to confirm this message staff.patron.bill_history.print_bills.print_error=printing bills staff.patron.bills.init_controller.money_summary_label=Money Summary staff.patron.bills.bill_payment_amount.credit_amount=Patron only has %1$s in credit. diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.js b/Open-ILS/xul/staff_client/server/patron/bill2.js index 6a7bdfd413..9d6e0a724f 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.js +++ b/Open-ILS/xul/staff_client/server/patron/bill2.js @@ -9,9 +9,10 @@ function my_init() { JSAN.use('util.network'); g.network = new util.network(); JSAN.use('util.date'); JSAN.use('util.money'); + JSAN.use('util.widgets'); JSAN.use('patron.util'); JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'}); - //g.data.temp = ''; g.data.stash('temp'); + g.data.voided_billings = []; g.data.stash('voided_billings'); g.error.sdump('D_TRACE','my_init() for bill2.xul'); @@ -27,6 +28,8 @@ function my_init() { g.patron_id = xul_param('patron_id'); + $('circulating_hint').hidden = true; + init_lists(); retrieve_mbts_for_list(); @@ -46,14 +49,14 @@ function my_init() { try { g.patron = req.getResultObject(); if (typeof g.patron.ilsevent != 'undefined') throw(g.patron); - $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() )); + $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() )); } catch(E) { alert('Error in bill2.js, retrieve patron callback: ' + E); } } ); } else { - $('credit_forward').setAttribute('value','$' + util.money.sanitize( g.patron.credit_forward_balance() )); + $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() )); } default_focus(); @@ -79,9 +82,34 @@ function event_listeners() { false ); + $('voidall').addEventListener( + 'command', + handle_void_all, + false + ); + $('payment').addEventListener( 'change', - function(ev) { distribute_payment(); }, + function(ev) { + if ($('payment_type').value == 'credit_payment') { + JSAN.use('util.money'); + JSAN.use('patron.util'); g.patron = patron.util.retrieve_au_via_id(ses(),g.patron_id); + var proposed = util.money.dollars_float_to_cents_integer(ev.target.value); + var available = util.money.dollars_float_to_cents_integer(g.patron.credit_forward_balance()); + if (proposed > available) { + alert($("patronStrings").getFormattedString('staff.patron.bills.bill_payment_amount.credit_amount', [g.patron.credit_forward_balance()])); + ev.target.value = util.money.cents_as_dollars( available ); + ev.target.setAttribute('value',ev.target.value); + } + } + distribute_payment(); + }, + false + ); + + $('payment').addEventListener( + 'focus', + function(ev) { ev.target.select(); }, false ); @@ -110,6 +138,21 @@ function event_listeners() { false ); + $('bill_history_btn').addEventListener( + 'command', + function() { + xulG.display_window.g.patron.right_deck.reset_iframe( + urls.XUL_PATRON_BILL_HISTORY, + {}, + { + 'patron_id' : g.patron_id, + 'refresh' : function() { refresh(); } + } + ); + }, + false + ); + $('convert_change_to_credit').addEventListener( 'command', function(ev) { @@ -122,6 +165,18 @@ function event_listeners() { false ); + $('apply_payment_btn').addEventListener( + 'command', + function(ev) { + try { + apply_payment(); + } catch(E) { + alert('Error in bill2.js, apply_payment_btn: ' + E); + } + }, + false + ); + } catch(E) { alert('Error in bill2.js, event_listeners(): ' + E); } @@ -146,14 +201,14 @@ function tally_pending() { if (g.check_map[retrieve_ids[i]]) { var value = util.money.dollars_float_to_cents_integer( row_params.row.my.payment_pending ); payment_pending += value; - if (value != '0.00') { payments.push( [ retrieve_ids[i], value ] ); } + if (value != '0.00') { payments.push( [ retrieve_ids[i], util.money.cents_as_dollars(value) ] ); } } } var change_pending = payment_tendered - payment_pending; $('pending_payment').value = util.money.cents_as_dollars( payment_pending ); $('pending_change').value = util.money.cents_as_dollars( change_pending ); $('change_due').value = util.money.cents_as_dollars( change_pending ); - return { 'payments' : payments, 'change' : change_pending }; + return { 'payments' : payments, 'change' : util.money.cents_as_dollars( change_pending ) }; } catch(E) { alert('Error in bill2.js, tally_pending(): ' + E); } @@ -181,14 +236,32 @@ function tally_selected() { selected_paid += tp; selected_balance += bo; } - //$('checked_billed').setAttribute('value', '$' + util.money.cents_as_dollars( selected_billed ) ); - //$('checked_paid').setAttribute('value', '$' + util.money.cents_as_dollars( selected_paid ) ); - //$('checked_owed').setAttribute('value', '$' + util.money.cents_as_dollars( selected_balance ) ); + //$('checked_billed').setAttribute('value', util.money.cents_as_dollars( selected_billed ) ); + //$('checked_paid').setAttribute('value', util.money.cents_as_dollars( selected_paid ) ); + //$('checked_owed').setAttribute('value', util.money.cents_as_dollars( selected_balance ) ); } catch(E) { alert('Error in bill2.js, tally_selected(): ' + E); } } +function tally_voided() { + try { + JSAN.use('util.money'); + var voided_total = 0; + + g.data.stash_retrieve(); + + for (var i = 0; i < g.data.voided_billings.length; i++) { + var billing = g.data.voided_billings[i]; + var bv = util.money.dollars_float_to_cents_integer( billing.amount() ); + voided_total += bv; + } + $('currently_voided').setAttribute('value', util.money.cents_as_dollars( voided_total ) ); + } catch(E) { + alert('Error in bill2.js, tally_voided(): ' + E); + } +} + function tally_all() { try { JSAN.use('util.money'); @@ -228,15 +301,15 @@ function tally_all() { checked_balance += bo; } } - $('checked_billed').setAttribute('value', '$' + util.money.cents_as_dollars( checked_billed ) ); - $('checked_paid').setAttribute('value', '$' + util.money.cents_as_dollars( checked_paid ) ); - $('checked_owed').setAttribute('value', '$' + util.money.cents_as_dollars( checked_balance ) ); - $('checked_owed2').setAttribute('value', '$' + util.money.cents_as_dollars( checked_balance ) ); - $('total_billed').setAttribute('value', '$' + util.money.cents_as_dollars( total_billed ) ); - $('total_paid').setAttribute('value', '$' + util.money.cents_as_dollars( total_paid ) ); - $('total_owed').setAttribute('value', '$' + util.money.cents_as_dollars( total_balance ) ); - $('total_owed2').setAttribute('value', '$' + util.money.cents_as_dollars( total_balance ) ); - $('refunds_owed').setAttribute('value', '$' + util.money.cents_as_dollars( Math.abs( refunds_owed ) ) ); + $('checked_billed').setAttribute('value', util.money.cents_as_dollars( checked_billed ) ); + $('checked_paid').setAttribute('value', util.money.cents_as_dollars( checked_paid ) ); + $('checked_owed').setAttribute('value', util.money.cents_as_dollars( checked_balance ) ); + $('checked_owed2').setAttribute('value', util.money.cents_as_dollars( checked_balance ) ); + $('total_billed').setAttribute('value', util.money.cents_as_dollars( total_billed ) ); + $('total_paid').setAttribute('value', util.money.cents_as_dollars( total_paid ) ); + $('total_owed').setAttribute('value', util.money.cents_as_dollars( total_balance ) ); + $('total_owed2').setAttribute('value', util.money.cents_as_dollars( total_balance ) ); + $('refunds_owed').setAttribute('value', util.money.cents_as_dollars( Math.abs( refunds_owed ) ) ); // tally_selected(); } catch(E) { alert('Error in bill2.js, tally_all(): ' + E); @@ -251,6 +324,7 @@ function check_all() { row_params.row.my.checked = true; g.bill_list.refresh_row(row_params); } + tally_all(); distribute_payment(); } catch(E) { alert('Error in bill2.js, check_all(): ' + E); @@ -266,6 +340,7 @@ function uncheck_all() { row_params.row.my.checked = false; g.bill_list.refresh_row(row_params); } + tally_all(); distribute_payment(); } catch(E) { alert('Error in bill2.js, check_all(): ' + E); @@ -276,13 +351,14 @@ function uncheck_all() { function check_all_refunds() { try { for (var i in g.bill_map) { - g.check_map[i] = true; if ( Number( g.bill_map[i].transaction.balance_owed() ) < 0 ) { + g.check_map[i] = true; var row_params = g.row_map[i]; row_params.row.my.checked = true; g.bill_list.refresh_row(row_params); } } + tally_all(); distribute_payment(); } catch(E) { alert('Error in bill2.js, check_all_refunds(): ' + E); @@ -328,7 +404,8 @@ function init_lists() { 'columns' : [ { - 'id' : 'select', 'type' : 'checkbox', 'editable' : true, 'label' : '', 'render' : function(my) { return String( my.checked ) == 'true'; }, + 'id' : 'select', 'primary' : true, 'type' : 'checkbox', 'editable' : true, 'label' : '', 'style' : 'min-width: 3em;', + 'render' : function(my) { return String( my.checked ) == 'true'; }, } ].concat( patron.util.mbts_columns({ @@ -341,7 +418,9 @@ function init_lists() { ).concat( [ { - 'id' : 'payment_pending', 'editable' : false, 'label' : 'Payment Pending', 'sort_type' : 'money', 'render' : function(my) { return my.payment_pending || '0.00'; }, + 'id' : 'payment_pending', 'editable' : false, 'sort_type' : 'money', + 'label' : $('patronStrings').getString('staff.patron.bill_interface.payment_pending.column_header'), + 'render' : function(my) { return my.payment_pending || '0.00'; }, } ] ))), @@ -392,6 +471,22 @@ function init_lists() { try { var id = params.retrieve_id; var row = params.row; + + function handle_props(row) { + try { + if ( row && row.my && row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) { + util.widgets.addProperty(params.row_node.firstChild,'refundable'); + } + if ( row && row.my && row.my.circ && ! row.my.circ.checkin_time() ) { + $('circulating_hint').hidden = false; + util.widgets.addProperty(params.row_node.firstChild,'circulating'); + } + } catch(E) { + g.error.sdump('D_WARN','Error setting list properties in bill2.js: ' + E); + alert('Error setting list properties in bill2.js: ' + E); + } + } + if (id) { if (typeof row.my == 'undefined') row.my = {}; if (typeof row.my.mbts == 'undefined' ) { @@ -402,10 +497,10 @@ function init_lists() { row.my.acp = blob.copy; row.my.mvr = blob.record; if (typeof params.on_retrieve == 'function') { - if ( Number( row.my.mbts.balance_owed() ) < 0 ) { - params.row_node.firstChild.setAttribute('properties','refundable'); + if ( row.my.mbts && Number( row.my.mbts.balance_owed() ) < 0 ) { row.my.checked = false; } + handle_props(row); params.on_retrieve(row); }; g.bill_map[ id ] = blob; @@ -413,11 +508,17 @@ function init_lists() { tally_all(); } ); } else { - if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); } + if (typeof params.on_retrieve == 'function') { + handle_props(row); + params.on_retrieve(row); + } } } else { - if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); } + if (typeof params.on_retrieve == 'function') { + params.on_retrieve(row); + } } + return row; } catch(E) { alert('Error in bill2.js, retrieve_row(): ' + E); @@ -430,10 +531,11 @@ function init_lists() { } function handle_add() { - if(g.bill_list_selection.length > 1) + if(g.bill_list_selection.length > 1) { var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]); - else + } else { var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_singular', [g.bill_list_selection]); + } var r = g.error.yns_alert(msg, $("patronStrings").getString('staff.patron.bill_history.handle_add.title'), @@ -451,13 +553,34 @@ function handle_add() { { 'patron_id' : g.patron_id, 'xact_id' : g.bill_list_selection[i] } ); } - g.bill_list.clear(); - retrieve_mbts_for_list(); - if (typeof window.refresh == 'function') window.refresh(); + refresh(); + if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh(); + } +} + +function handle_void_all() { + if(g.bill_list_selection.length > 1) { + var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_plural', [g.bill_list_selection]); + } else { + var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_void.message_singular', [g.bill_list_selection]); + } + + var r = g.error.yns_alert(msg, + $("patronStrings").getString('staff.patron.bill_history.handle_void.title'), + $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_yes'), + $("patronStrings").getString('staff.patron.bill_history.handle_void.btn_no'),null, + $("patronStrings").getString('staff.patron.bill_history.handle_void.confirm_message')); + if (r == 0) { + for (var i = 0; i < g.bill_list_selection.length; i++) { + void_all_billings( g.bill_list_selection[i] ); + } + refresh(); if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh(); + if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change(); } } + function handle_details() { JSAN.use('util.window'); var win = new util.window(); for (var i = 0; i < g.bill_list_selection.length; i++) { @@ -468,8 +591,8 @@ function handle_details() { { 'patron_id' : g.patron_id, 'mbts_id' : g.bill_list_selection[i], - 'refresh' : function() { - if (typeof window.refresh == 'function') window.refresh(); + 'refresh' : function() { + refresh(); if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh(); }, } @@ -574,15 +697,25 @@ function apply_payment() { } if ( pay( payment_blob ) ) { - g.data.voided_billings = []; g.data.stash('voided_billings'); - g.bill_list.clear(); - retrieve_mbts_for_list(); - if (typeof window.refresh == 'function') window.refresh(); + $('payment').value = ''; $('payment').select(); $('payment').focus(); + refresh({'clear_voided_summary':true}); if (typeof window.xulG == 'object' && typeof window.xulG.refresh == 'function') window.xulG.refresh(); + if (typeof window.xulG == 'object' && typeof window.xulG.on_money_change == 'function') window.xulG.on_money_change(); + if ( $('payment_type').value == 'credit_payment' || $('convert_change_to_credit').checked ) { + JSAN.use('patron.util'); + patron.util.retrieve_au_via_id(ses(),g.patron_id, function(req) { + var au_obj = req.getResultObject(); + if (typeof au_obj.ils_event == 'undefined') { + g.patron = au_obj; + $('credit_forward').setAttribute('value',util.money.sanitize( g.patron.credit_forward_balance() )); + } + }); + } try { + if ( ! $('receipt_upon_payment').hasAttribute('checked') ) { return; } // Skip print attempt var no_print_prompting = g.data.hash.aous['circ.staff_client.do_not_auto_attempt_print']; if (no_print_prompting) { - if (no_print_prompting.indexOf( "Bill Pay" ) > -1) return; // Skip print attempt + if (no_print_prompting.indexOf( "Bill Pay" ) > -1) { return; } // Skip print attempt } netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); g.data.stash_retrieve(); @@ -590,12 +723,12 @@ function apply_payment() { JSAN.use('patron.util'); JSAN.use('util.functional'); var params = { 'patron' : g.patron, - 'lib' : data.hash.aou[ ses('ws_ou') ], + 'lib' : g.data.hash.aou[ ses('ws_ou') ], 'staff' : ses('staff'), - 'header' : data.print_list_templates[template].header, - 'line_item' : data.print_list_templates[template].line_item, - 'footer' : data.print_list_templates[template].footer, - 'type' : data.print_list_templates[template].type, + 'header' : g.data.print_list_templates[template].header, + 'line_item' : g.data.print_list_templates[template].line_item, + 'footer' : g.data.print_list_templates[template].footer, + 'type' : g.data.print_list_templates[template].type, 'list' : util.functional.map_list( payment_blob.payments, function(o) { @@ -612,11 +745,11 @@ function apply_payment() { 'data' : g.previous_summary }; g.error.sdump('D_DEBUG',js2JSON(params)); - if ($('auto_print').checked) params.no_prompt = true; + if (! $('printer_prompt').hasAttribute('checked')) params.no_prompt = true; JSAN.use('util.print'); var print = new util.print(); - print.tree_list( params ); + print.tree_list( params ); } catch(E) { - g.standard_unexpected_error_alert('bill receipt', E); + g.error.standard_unexpected_error_alert('bill receipt', E); } } } catch(E) { @@ -634,22 +767,21 @@ function pay(payment_blob) { $("patronStrings").getString('staff.patron.bills.pay.annotate_payment.title') ); } - previous_summary = { - original_balance : obj.controller.view.bill_total_owed.value, - voided_balance : obj.controller.view.voided_balance.value, - payment_received : obj.controller.view.bill_payment_amount.value, - payment_applied : obj.controller.view.bill_payment_applied.value, - change_given : obj.controller.view.bill_change_amount.value, - credit_given : obj.controller.view.bill_credit_amount.value, - new_balance : obj.controller.view.bill_new_balance.value, - payment_type : obj.controller.view.payment_type.getAttribute('label'), + g.previous_summary = { + original_balance : $('total_owed').value, + voided_balance : $('currently_voided').value, + payment_received : $('payment').value, + payment_applied : $('pending_payment').value, + change_given : $('convert_change_to_credit').checked ? 0 : $('pending_change').value, + credit_given : $('convert_change_to_credit').checked ? $('pending_change').value : 0, + new_balance : util.money.cents_as_dollars( + util.money.dollars_float_to_cents_integer( $('total_owed').value ) - + util.money.dollars_float_to_cents_integer( $('pending_payment').value ) + ), + payment_type : $('payment_type').getAttribute('label'), note : payment_blob.note } - var robj = g.network.request( - api.BILL_PAY.app, - api.BILL_PAY.method, - [ ses(), payment_blob ] - ); + var robj = g.network.simple_request( 'BILL_PAY', [ ses(), payment_blob ]); if (robj == 1) { return true; } if (typeof robj.ilsevent != 'undefined') { switch(Number(robj.ilsevent)) { @@ -659,9 +791,65 @@ function pay(payment_blob) { } } } catch(E) { - obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E); + g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.pay.payment_failed'),E); return false; } } +function refresh(params) { + try { + if (params && params.clear_voided_summary) { + g.data.voided_billings = []; g.data.stash('voided_billings'); + } + g.bill_list.clear(); + retrieve_mbts_for_list(); + tally_voided(); + distribute_payment(); + } catch(E) { + alert('Error in bill2.js, refresh(): ' + E); + } +} + +function void_all_billings(mobts_id) { + try { + JSAN.use('util.functional'); + + var mb_list = g.network.simple_request( 'FM_MB_RETRIEVE_VIA_MBTS_ID.authoritative', [ ses(), mobts_id ] ); + if (typeof mb_list.ilsevent != 'undefined') throw(mb_list); + + mb_list = util.functional.filter_list( mb_list, function(o) { return ! get_bool( o.voided() ) }); + + if (mb_list.length == 0) { alert($("patronStrings").getString('staff.patron.bills.void_all_billings.all_voided')); return; } + + var sum = 0; + for (var i = 0; i < mb_list.length; i++) sum += util.money.dollars_float_to_cents_integer( mb_list[i].amount() ); + sum = util.money.cents_as_dollars( sum ); + + var msg = $("patronStrings").getFormattedString('staff.patron.bills.void_all_billings.void.message', [sum]); + var r = g.error.yns_alert(msg, + $("patronStrings").getString('staff.patron.bills.void_all_billings.void.title'), + $("patronStrings").getString('staff.patron.bills.void_all_billings.void.yes'), + $("patronStrings").getString('staff.patron.bills.void_all_billings.void.no'), null, + $("patronStrings").getString('staff.patron.bills.void_all_billings.void.confirm_message')); + if (r == 0) { + var robj = g.network.simple_request('FM_MB_VOID',[ses()].concat(util.functional.map_list(mb_list,function(o){return o.id();}))); + if (robj.ilsevent) { + switch(Number(robj.ilsevent)) { + default: + g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bills.void_all_billings.error_voiding_bills'),robj); + refresh(); return; + break; + } + } + + g.data.stash_retrieve(); if (! g.data.voided_billings ) g.data.voided_billings = []; + for (var i = 0; i < mb_list.length; i++) { + g.data.voided_billings.push( mb_list[i] ); + } + g.data.stash('voided_billings'); + } + } catch(E) { + try { g.error.standard_unexpected_error_alert('bill2.js, void_all_billings():',E); } catch(F) { alert(E); } + } +} diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.xul b/Open-ILS/xul/staff_client/server/patron/bill2.xul index b7c3961d62..61d5260158 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.xul +++ b/Open-ILS/xul/staff_client/server/patron/bill2.xul @@ -21,7 +21,7 @@ @@ -119,6 +119,9 @@