JBAS-2118 Reprint refundable; show staff login in details
authorBill Erickson <berickxx@gmail.com>
Mon, 14 Jan 2019 21:11:01 +0000 (16:11 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Show lost/paid receipt reprint options in main billing list and in
payments history list.

Show staff A/D login under new "Staff" column in billing payment
details.

Remove the bogus "@ library" for the "Login" column since it referred to
the home library and not the payment library -- best to just not show
it.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/patron/t_bill_history_payments.tt2
Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2
Open-ILS/src/templates/staff/circ/patron/t_xact_details_details.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

index 328ab1d..a11f215 100644 (file)
@@ -7,9 +7,13 @@
     grid-controls="gridControls"
     dateformat="{{$root.egDateAndTimeFormat}}"
     persist-key="circ.patron.billhistory_payments">
+
     <eg-grid-action 
       label="[% l('Full Details') %]" handler="showFullDetails"></eg-grid-action>
 
+    <eg-grid-action label="[% l('Reprint Lost/Paid Receipt') %]" 
+      handler="printLostPaidReceipt"></eg-grid-action>
+
     <eg-grid-field path="amount" label="[% l('Amount') %]"></eg-grid-field>
     <eg-grid-field path="id" label="[% l('Payment ID') %]"></eg-grid-field>
     <eg-grid-field path="payment_ts" label="[% l('Payment Time') %]" datatype="timestamp"></eg-grid-field>
index d622db6..48c0499 100644 (file)
@@ -50,6 +50,9 @@
   <eg-grid-action label="[% l('Full Details') %]" 
     handler="showFullDetails"></eg-grid-action>
 
+  <eg-grid-action label="[% l('Reprint Lost/Paid Receipt') %]" 
+    handler="printLostPaidReceipt"></eg-grid-action>
+
   <eg-grid-field label="[% l('Balance Owed') %]" path='summary.balance_owed'></eg-grid-field>
   <eg-grid-field required label="[% l('Bill #') %]" path='id'></eg-grid-field>
   <eg-grid-field label="[% l('Start') %]" path='xact_start' datatype="timestamp"></eg-grid-field>
index 6cd026a..15e363b 100644 (file)
   <eg-grid-field path="cash_payment.cash_drawer.name" parent-idl-class="mbp"
     label="[% l('Cash Drawer') %]"></eg-grid-field>
 
-  <eg-grid-field path="accepting_usr">{{item.staff_name}} ({{item.staff_barcode}}) @ {{item.staff_org}}</eg-grid-field>
+  <eg-grid-field path="accepting_usr" label="[% l('Login') %]">
+    {{item.staff_name}} ({{item.staff_barcode}})
+  </eg-grid-field>
+
+  <eg-grid-field path="refundable_payment_staff" label="[% l('Staff') %]">
+  </eg-grid-field>
 
   <eg-grid-field path="amount"></eg-grid-field>
   <eg-grid-field path="id"></eg-grid-field>
@@ -52,7 +57,7 @@
     label="[% l('Staff Barcode') %]" hidden required></eg-grid-field>
 
   <eg-grid-field path="accepting_usr.home_ou.shortname" name="staff_org"
-    label="[% l('Staff Org Unit') %]" hidden required></eg-grid-field>
+    label="[% l('Staff Home Org Unit') %]" hidden required></eg-grid-field>
 
 </eg-grid>
 
index 0f34ab3..2c70efd 100644 (file)
@@ -954,6 +954,48 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
 
     }
 
+    // Reprints the lost/paid (refundable payment) receipt for the
+    // most recent payment on a refundable transaction.
+    $scope.printLostPaidReceipt = function(items) {
+        if (items.length == 0) return;
+
+        var ids = items.map(function(item) {return item.id});
+
+        function printOne() {
+            var id = ids.shift();
+            if (!id) return $q.when();
+
+            return egCore.net.request(
+                'open-ils.circ', 
+                'open-ils.circ.refundable_payment.receipt.by_xact.html',
+                egCore.auth.token(), id
+            ).then(function(receipt) {
+
+                if (receipt && 
+                    receipt.textcode == 'MONEY_REFUNDABLE_XACT_SUMMARY_NOT_FOUND') {
+                    alert('Cannot generate lost/paid receipt for transaction #' + id);
+                    return;
+                }
+
+                if (!receipt || !receipt.template_output()) {
+                    return alert(
+                        'Error creating refundable payment receipt for transaction #' + id);
+                }
+
+                var html = receipt.template_output().data();
+                return egCore.print.print({
+                    context : 'default', 
+                    content_type: 'text/html',
+                    content: html,
+                    show_dialog: true,
+                    scope : {}
+                });
+            }).then(printOne);
+        }
+
+        printOne();
+    }
+
     // note this is functionally equivalent to selecting a neg. transaction
     // then clicking Apply Payment -- this just adds a speed bump (ditto
     // the XUL client).
@@ -1010,7 +1052,29 @@ function($scope,  $q , $routeParams , egCore , egGridDataProvider , patronSvc ,
 
     var paymentGrid = $scope.paymentGridControls = {
         setQuery : function() { return {xact : xact_id} },
-        setSort : function() { return ['payment_ts'] }
+        setSort : function() { return ['payment_ts'] },
+        allItemsRetrieved: function() {
+            // See if any of these payments are refundable.
+            // If so, fetch the staff A/D login name for display.
+            var items = $scope.paymentGridControls.allItems().concat([]);
+
+            function fetchOne() {
+                var item = items.shift();
+                if (!item) { return $q.when(); }
+                return egCore.net.request(
+                    'open-ils.circ',
+                    'open-ils.circ.refundable_payment.retrieve.by_payment',
+                    egCore.auth.token(), item.id
+                ).then(function(rfPayment) {
+                    if (rfPayment) {
+                        item.refundable_payment_staff = 
+                            rfPayment.staff_email().replace(/@.*/g, ''); // remove @kcls.org
+                    }
+                    fetchOne();
+                })
+            }
+            fetchOne();
+        }
     }
 
     // -- actions
@@ -1151,6 +1215,47 @@ function($scope,  $q , $routeParams , egCore , patronSvc , billSvc , egPromptDia
         if (end == today) end = 'now';
         return [start, end];
     }
+
+    // Reprints the lost/paid (refundable payment) receipt for selected payments
+    $scope.printLostPaidReceipt = function(items) {
+        if (items.length == 0) return;
+
+        var ids = items.map(function(item) {return item.id});
+
+        function printOne() {
+            var id = ids.shift();
+            if (!id) return $q.when();
+
+            return egCore.net.request(
+                'open-ils.circ', 
+                'open-ils.circ.refundable_payment.receipt.by_pay.html',
+                egCore.auth.token(), id
+            ).then(function(receipt) {
+
+                if (receipt && 
+                    receipt.textcode == 'MONEY_REFUNDABLE_PAYMENT_SUMMARY_NOT_FOUND') {
+                    alert('Cannot generate lost/paid receipt for payment #' + id);
+                    return;
+                }
+
+                if (!receipt || !receipt.template_output()) {
+                    return alert(
+                        'Error creating refundable payment receipt for payment #' + id);
+                }
+
+                var html = receipt.template_output().data();
+                return egCore.print.print({
+                    context : 'default', 
+                    content_type: 'text/html',
+                    content: html,
+                    show_dialog: true,
+                    scope : {}
+                });
+            }).then(printOne);
+        }
+
+        printOne();
+    }
 }])