JBAS-1306 Reprint lost payment receipt option
authorBill Erickson <berickxx@gmail.com>
Thu, 11 Oct 2018 18:47:25 +0000 (14:47 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/RefundablePayment.pm
Open-ILS/xul/staff_client/server/patron/bill2.js
Open-ILS/xul/staff_client/server/patron/bill2.xul

index 7a00b28..10ee757 100644 (file)
@@ -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.
index ab65647..956f774 100644 (file)
@@ -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'
         });
     }
index fb74041..b5e1bfa 100644 (file)
@@ -46,6 +46,7 @@
         <command id="add" label="&staff.patron.bill_interface.add_billing.label;" accesskey="&staff.patron.bill_interface.add_billing.accesskey;" disabled="true"/>
         <command id="details" label="&staff.patron.bill_interface.full_details.label;" accesskey="&staff.patron.bill_interface.full_details.accesskey;" disabled="true"/>
         <command id="printthis" label="&staff.patron.bill_interface.print_selected.label;" accesskey="&staff.patron.bill_interface.full_details.accesskey;" disabled="true"/>
+        <command id="printlostpaid" label="Reprint Lost/Paid Receipt" disabled="true"/>
     </commandset>
 
     <popupset>
@@ -58,6 +59,7 @@
             <menuitem command="add" />
             <menuitem command="details" />
             <menuitem command="printthis" />
+            <menuitem command="printlostpaid" />
         </menupopup>
     </popupset>