JBAS-1306 Reprint lost/paid from payment history
authorBill Erickson <berickxx@gmail.com>
Thu, 18 Oct 2018 19:21:10 +0000 (15:21 -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/bill_history.js
Open-ILS/xul/staff_client/server/patron/bill_history.xul

index 10ee757..18bad4b 100644 (file)
@@ -373,6 +373,23 @@ __PACKAGE__->register_method(
 
 __PACKAGE__->register_method(
     method    => 'generate_refundable_payment_receipt',
+    api_name  => 'open-ils.circ.refundable_payment.receipt.by_pay.html',
+    signature => {
+        desc   => q/Generate a printable HTML refundable payment receipt
+            for the requested money.payment entry/,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Source Payment ID', type => 'number'}
+        ],
+        return => {
+            desc => 'A/T event with fleshed outputs on success, event on error'
+        }
+    }
+);
+
+
+__PACKAGE__->register_method(
+    method    => 'generate_refundable_payment_receipt',
     api_name  => 'open-ils.circ.refundable_payment.receipt.email',
     signature => {
         desc   => q/Generate an email refundable payment receipt/,
@@ -390,7 +407,7 @@ sub generate_refundable_payment_receipt {
     my ($self, $client, $auth, $target_id) = @_;
 
     my $e = new_editor(authtoken => $auth);
-    return $e->die_event unless $e->checkauth;
+    return $e->event unless $e->checkauth;
 
     my $mrps;
     if ($self->api_name =~ /by_xact/) {
@@ -415,6 +432,13 @@ sub generate_refundable_payment_receipt {
         $mrxs->clear_refundable_payments;
         $mrps->refundable_xact($mrxs);
 
+    } elsif ($self->api_name =~ /by_pay/) {
+
+        $mrps = $e->search_money_refundable_payment_summary([
+            {payment => $target_id},
+            {flesh => 1, flesh_fields => {mrps => ['refundable_xact']}}
+        ])->[0] or return $e->event;
+
     } else {
 
         $mrps = $e->retrieve_money_refundable_payment_summary([
index 8750c06..73831ca 100644 (file)
@@ -914,7 +914,7 @@ function handle_printlostpaid() {
     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];
+        xact_id = xact_ids[i];
 
         var receipt = g.network.request(
             'open-ils.circ', 
@@ -924,7 +924,7 @@ function handle_printlostpaid() {
 
         if (receipt && 
             receipt.textcode == 'MONEY_REFUNDABLE_XACT_SUMMARY_NOT_FOUND') {
-            alert('Transaction ' + xact_id + ' has no lost payments');
+            alert('Cannot generate lost/paid receipt for transaction #' + xact_id);
             continue;
         }
 
index 2a2604a..e5c0173 100644 (file)
@@ -412,6 +412,41 @@ function print_bills_from_history(selected) {
     }
 }
 
+function print_lostpaid_from_history() {
+    var selected = g.payments_list.dump_selected_with_keys(0);
+    var pay_ids = selected.map(function(sel) { return sel.mp_id });
+
+    for (var i = 0; i < pay_ids.length; i++) {
+        pay_id = pay_ids[i];
+
+        var receipt = g.network.request(
+            'open-ils.circ', 
+            'open-ils.circ.refundable_payment.receipt.by_pay.html',
+            [ses(), pay_id]
+        );
+
+        if (receipt && 
+            receipt.textcode == 'MONEY_REFUNDABLE_PAYMENT_SUMMARY_NOT_FOUND') {
+            alert('Cannot generate lost/paid receipt for payment #' + pay_id);
+            continue;
+        }
+
+        if (!receipt || !receipt.template_output()) {
+            return alert(
+                'Error creating refundable payment receipt for payment ' + pay_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 payment_history_init() {
     try {
         if (payment_history_fetched) { return; } else { payment_history_fetched = true; }
index 4a505b9..eb7a294 100644 (file)
     <popupset id="payment_history_popupset">
         <menupopup id="payment_history_actions" position="at_pointer">
             <menuitem label="&staff.patron.bill_interface.print_selected.label;" accesskey="&staff.patron.bill_interface.full_details.accesskey;" oncommand="print_bills_from_history(true);"/>
+            <menuitem label="Reprint Lost/Paid Receipt" oncommand="print_lostpaid_from_history();"/>
         </menupopup>
     </popupset>
     <popupset id="bill_history_popupset">