lp1810429 Issue Refund in Patron Bills user/khuckins/lp1810429-refund-not-working-as-expected
authorKyle Huckins <khuckins@catalyte.io>
Thu, 23 May 2019 17:07:16 +0000 (17:07 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Thu, 23 May 2019 17:07:16 +0000 (17:07 +0000)
- Conditionally determine if a selected item is valid for
a refund, and swap Apply Payment button for Issue Refund
button.

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
modified:   Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

Open-ILS/src/templates/staff/circ/patron/t_bills.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

index 52c2965..ee9bd12 100644 (file)
             <button
                 type="submit"
                 class="btn btn-default"
+                ng-if="!valid_refund"
                 ng-disabled="!payment_amount || invalid_check_number() || !gridControls.selectedItems().length || applyingPayment"
             >[% l('Apply Payment') %]</button>
+            <button
+                type="submit"
+                class="btn btn-default"
+                ng-if="valid_refund"
+                ng-disabled="invalid_check_number() || !gridControls.selectedItems().length || applyingPayment"
+            >[% l('Issue Refund') %]</button>
           </div>
         </div>
       </fieldset>
index ceda5c8..4fb9253 100644 (file)
@@ -189,6 +189,7 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
     $scope.max_amount = 100000;
     $scope.amount_verified = false;
     $scope.disable_auto_print = false;
+    $scope.valid_refund = false;
 
     // check receipt_on_pay setting default persisted
     egCore.hatch.getItem('circ.bills.receiptonpay')
@@ -311,10 +312,11 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
     }
 
     // update the item.payment_pending value each time the user
-    // selects different transactions to pay against.
+    // selects different transactions to pay against. Also check
+    // if any selected items are valid for issuing a refund.
     $scope.$watch(
         function() {return $scope.gridControls.selectedItems()},
-        function() {updatePendingColumn()},
+        function() {updatePendingColumn(); validateRefundability()},
         true
     );
 
@@ -354,6 +356,14 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
         }
     }
 
+    function validateRefundability() {
+        var is_valid = false;
+        angular.forEach($scope.gridControls.selectedItems(), function(item) {
+            if (Number(item['summary.balance_owed']) < 0)  is_valid = true;
+        });
+        $scope.valid_refund = is_valid;
+    }
+
     // builds payment arrays ([xact_id, ammount]) for all transactions
     // which have a pending payment amount.
     function generatePayments() {