lp1671603 webstaff: add confirm step for voiding billings
authorJason Etheridge <jason@equinoxinitiative.org>
Mon, 12 Jun 2017 15:07:59 +0000 (11:07 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 19 Jun 2017 14:54:40 +0000 (10:54 -0400)
This patch adds a confirmation step for  both Void All Bills
in the main billing UI, and Void Billings in the Full Details UI

Signed-off-by: Jason Etheridge <jason@equinoxinitiative.org>
Signed-off-by: Andrea Neiman <abneiman@equinoxinitiative.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

index f140dab..88c5dca 100644 (file)
@@ -37,6 +37,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.ANNOTATE_PAYMENT_MSG = "[% l('Please annotate this payment') %]";
   s.CONFIRM_ADJUST_TO_ZERO = 
     "[% |l('{{xactIds}}') -%]Are you sure you would like to adjust to zero the balance on bills [_1]?[% END %]";
+  s.CONFIRM_VOID_BILLINGS = 
+    "[% l('Are you sure you would like to void $[_1] for these line-item billings? [_2]','{{amount|number:2}}','{{billIds}}') %]";
   s.CONFIRM_REFUND_PAYMENT = 
     "[% |l('{{xactIds}}') -%]Are you sure you would like to refund excess payment on bills [_1]?  This action will simply put the amount in the Payment Pending column as a negative value.  You must still select Apply Payment!  Certain types of payments may not be refunded.  The refund may be applied to checked transactions that follow the refunded transaction.[% END %]";
   s.EDIT_BILL_PAY_NOTE = "[% l('Enter new note for #[_1]:','{{ids}}') %]";
index 57bb094..c365c82 100644 (file)
@@ -517,32 +517,43 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
     }
 
     $scope.voidAllBillings = function(items) {
+        var promises = [];
+        var bill_ids = [];
+        var cents = 0;
         angular.forEach(items, function(item) {
+            promises.push(
+                billSvc.fetchBills(item.id).then(function(bills) {
+                    angular.forEach(bills, function(b) {
+                        if (b.voided() != 't') {
+                            cents += b.amount() * 100;
+                            bill_ids.push(b.id())
+                        }
+                    });
 
-            billSvc.fetchBills(item.id).then(function(bills) {
-                var bill_ids = [];
-                var cents = 0;
-                angular.forEach(bills, function(b) {
-                    if (b.voided() != 't') {
-                        cents += b.amount() * 100;
-                        bill_ids.push(b.id())
+                    if (bill_ids.length == 0) {
+                        // TODO: warn
+                        return;
                     }
-                });
 
-                $scope.session_voided = 
-                    ($scope.session_voided * 100 + cents) / 100;
+                })
+            );
+        });
 
-                if (bill_ids.length == 0) {
-                    // TODO: warn
-                    return;
+        $q.all(promises).then(function(){
+            egCore.audio.play('warning.circ.void_billings_confirmation');
+            egConfirmDialog.open(
+                egCore.strings.CONFIRM_VOID_BILLINGS, '', 
+                {   billIds : ''+bill_ids,
+                    amount : ''+(cents/100),
+                    ok : function() {
+                        billSvc.voidBills(bill_ids).then(function() {
+                            $scope.session_voided = 
+                                ($scope.session_voided * 100 + cents) / 100;
+                            refreshDisplay();
+                        });
+                    }
                 }
-
-                // TODO: alert of pending voiding
-
-                billSvc.voidBills(bill_ids).then(function() {
-                    refreshDisplay();
-                });
-            });
+            );
         });
     }
 
@@ -607,8 +618,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
  * Displays details of a single transaction
  */
 .controller('XactDetailsCtrl',
-       ['$scope','$q','$routeParams','egCore','egGridDataProvider','patronSvc','billSvc','egPromptDialog','egBilling',
-function($scope,  $q , $routeParams , egCore , egGridDataProvider , patronSvc , billSvc , egPromptDialog , egBilling) {
+       ['$scope','$q','$routeParams','egCore','egGridDataProvider','patronSvc','billSvc','egPromptDialog','egBilling','egConfirmDialog',
+function($scope,  $q , $routeParams , egCore , egGridDataProvider , patronSvc , billSvc , egPromptDialog , egBilling , egConfirmDialog ) {
 
     $scope.initTab('bills', $routeParams.id);
     var xact_id = $routeParams.xact_id;
@@ -626,8 +637,12 @@ function($scope,  $q , $routeParams , egCore , egGridDataProvider , patronSvc ,
     // -- actions
     $scope.voidBillings = function(bill_list) {
         var bill_ids = [];
+        var cents = 0;
         angular.forEach(bill_list, function(b) {
-            if (b.voided != 't') bill_ids.push(b.id);
+            if (b.voided != 't') {
+                cents += b.amount * 100;
+                bill_ids.push(b.id)
+            }
         });
 
         if (bill_ids.length == 0) {
@@ -635,18 +650,28 @@ function($scope,  $q , $routeParams , egCore , egGridDataProvider , patronSvc ,
             return;
         }
 
-        billSvc.voidBills(bill_ids).then(function() {
+        egCore.audio.play('warning.circ.void_billings_confirmation');
+        egConfirmDialog.open(
+            egCore.strings.CONFIRM_VOID_BILLINGS, '', 
+            {   billIds : ''+bill_ids,
+                amount : ''+(cents/100),
+                ok : function() {
+                    billSvc.voidBills(bill_ids).then(function() {
+                        // TODO? $scope.session_voided = ...
 
-            // refresh bills and summary data
-            // note: no need to update payments
-            patronSvc.fetchUserStats();
+                        // refresh bills and summary data
+                        // note: no need to update payments
+                        patronSvc.fetchUserStats();
 
-            egBilling.fetchXact(xact_id).then(function(xact) {
-                $scope.xact = xact
-            });
+                        egBilling.fetchXact(xact_id).then(function(xact) {
+                            $scope.xact = xact
+                        });
 
-            xactGrid.refresh();
-        });
+                        xactGrid.refresh();
+                    });
+                }
+            }
+        );
     }
 
     // batch-edit billing and payment notes, depending on 'type'