From: Bill Erickson Date: Thu, 11 Oct 2018 18:47:25 +0000 (-0400) Subject: JBAS-1306 Reprint lost payment receipt option X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7ac90478e50a96d29d749003844286821ca50aba;p=working%2FEvergreen.git JBAS-1306 Reprint lost payment receipt option Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/RefundablePayment.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/RefundablePayment.pm index 7a00b286a5..10ee7574ae 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/RefundablePayment.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/RefundablePayment.pm @@ -357,12 +357,13 @@ __PACKAGE__->register_method( __PACKAGE__->register_method( method => 'generate_refundable_payment_receipt', - api_name => 'open-ils.circ.refundable_payment.receipt.html', + api_name => 'open-ils.circ.refundable_payment.receipt.by_xact.html', signature => { - desc => q/Generate a printable HTML refundable payment receipt/, + desc => q/Generate a printable HTML refundable payment receipt + for the latest payment on the given billable transaction ID/, params => [ {desc => 'Authentication token', type => 'string'}, - {desc => 'Refundable Payment ID', type => 'number'} + {desc => 'Billable Transaction ID', type => 'number'} ], return => { desc => 'A/T event with fleshed outputs on success, event on error' @@ -386,14 +387,41 @@ __PACKAGE__->register_method( ); sub generate_refundable_payment_receipt { - my ($self, $client, $auth, $mrp_id) = @_; + my ($self, $client, $auth, $target_id) = @_; my $e = new_editor(authtoken => $auth); return $e->die_event unless $e->checkauth; - my $mrps= $e->retrieve_money_refundable_payment_summary([ - $mrp_id, {flesh => 1, flesh_fields => {mrps => ['refundable_xact']}} - ]) or return $e->event; + my $mrps; + if ($self->api_name =~ /by_xact/) { + + my $mrxs = $e->search_money_refundable_xact_summary([ + {xact => $target_id}, + { flesh => 2, + flesh_fields => { + mrxs => ['refundable_payments'], + mrps => ['payment'] + } + } + ])->[0] or return $e->event; + + # Print the most recent payment. + my @payments = @{$mrxs->refundable_payments}; + @payments = + sort {$a->payment->payment_ts cmp $b->payment->payment_ts} @payments; + $mrps = pop(@payments); + + # sync the fleshing for below + $mrxs->clear_refundable_payments; + $mrps->refundable_xact($mrxs); + + } else { + + $mrps = $e->retrieve_money_refundable_payment_summary([ + $target_id, + {flesh => 1, flesh_fields => {mrps => ['refundable_xact']}} + ]) or return $e->event; + } # ->usr may be undef when the transaction in question has been purged. # Patrons do not need to print receipts for purged transactions. diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.js b/Open-ILS/xul/staff_client/server/patron/bill2.js index ab65647332..956f774ceb 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.js +++ b/Open-ILS/xul/staff_client/server/patron/bill2.js @@ -136,6 +136,12 @@ function event_listeners() { false ); + window.bill_event_listeners.add($('printlostpaid'), + 'command', + handle_printlostpaid, + false + ); + window.bill_event_listeners.add($('payment'), 'change', function(ev) { @@ -241,6 +247,8 @@ function event_listeners() { } } + + /** * Launch secondary authentication dialog. * "Skip" option bypasses the secondary authentication step. @@ -709,6 +717,7 @@ function init_lists() { $('opac').setAttribute('disabled', g.bill_list_selection.length == 0); $('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0); $('printthis').setAttribute('disabled', g.bill_list_selection.length == 0); + $('printlostpaid').setAttribute('disabled', g.bill_list_selection.length == 0); }, 'on_click' : function(ev) { var row = {}; var col = {}; var nobj = {}; @@ -901,6 +910,41 @@ function handle_printthis() { g.bill_list.print(params); } +function handle_printlostpaid() { + var selected = g.bill_list.dump_selected_with_keys(0); + var xact_ids = selected.map(function(sel) { return sel.mbts_id }); + + for (var i = 0; i < xact_ids.length; i++) { + xact_id = xact_ids[0]; + + var receipt = g.network.request( + 'open-ils.circ', + 'open-ils.circ.refundable_payment.receipt.by_xact.html', + [ses(), xact_id] + ); + + if (receipt && + receipt.textcode == 'MONEY_REFUNDABLE_XACT_SUMMARY_NOT_FOUND') { + alert('Transaction ' + xact_id + ' has no lost payments'); + continue; + } + + if (!receipt || !receipt.template_output()) { + return alert( + 'Error creating refundable payment receipt for payment ' + xact_id); + } + + var html = receipt.template_output().data(); + JSAN.use('util.print'); + var print = new util.print('mail'); + + print.simple(html , { + no_prompt: false, // always prompt for lost payment receipts + content_type: 'text/html' + }); + } +} + function handle_opac() { try { var ids = []; @@ -1278,7 +1322,7 @@ function print_refundable_payments_receipt(mrp_ids) { var html = receipt.template_output().data(); JSAN.use('util.print'); var print = new util.print('mail'); print.simple(html , { - no_prompt: false, /*TODO*/ + no_prompt: false, // always prompt for lost payment receipts content_type: 'text/html' }); } diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.xul b/Open-ILS/xul/staff_client/server/patron/bill2.xul index fb740417bd..b5e1bfa65c 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.xul +++ b/Open-ILS/xul/staff_client/server/patron/bill2.xul @@ -46,6 +46,7 @@ + @@ -58,6 +59,7 @@ +