bill patron dialog; starting
authorBill Erickson <berick@esilibrary.com>
Wed, 21 May 2014 21:17:06 +0000 (17:17 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 21 May 2014 21:17:06 +0000 (17:17 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_bill_patron_dialog.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/circ/patron/t_bills_list.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

diff --git a/Open-ILS/src/templates/staff/circ/patron/t_bill_patron_dialog.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_bill_patron_dialog.tt2
new file mode 100644 (file)
index 0000000..ab1cd05
--- /dev/null
@@ -0,0 +1,60 @@
+<!-- edit bucket dialog -->
+<form ng-submit="ok(billArgs)" role="form" class="form-horizontal">
+  <div class="modal-content">
+    <div class="modal-header">
+      <button type="button" class="close" 
+        ng-click="cancel()" aria-hidden="true">&times;</button>
+      <h4 class="modal-title">
+        [% l('Bill Patron: [_1], [_2] [_3] : [_4]',
+            '{{patron.family_name()}}',
+            '{{patron.first_given_name()}}',
+            '{{patron.second_given_name()}}',
+            '{{patron.card().barcode()}}') %]
+      </h4>
+    </div>
+    <div class="modal-body">
+      <div class="form-group">
+        <label for="bill-dialog-location" class="control-label col-md-4">
+          [% l('Location:') %]
+        </label>
+        <div class="col-md-8">
+          <p class="form-control-static">{{location.shortname()}}</p>
+        </div>
+      </div>
+
+      <div class="form-group">
+        <label for="bill-dialog-type" class="control-label col-md-4">
+          [% l('Billing Type:') %]
+        </label>
+        <div class="col-md-8">
+          <select ng-model="billArgs.billingType" class="form-control">
+            <option ng-repeat="type in billingTypes" value="{{type.id()}}">
+              {{type.name()}}
+            </option>
+          </select>
+        </div>
+      </div>
+      <div class="form-group">
+        <label for="bill-dialog-amount" class="control-label col-md-4">[% l('Amount:') %]</label>
+        <div class="col-md-8">
+          <input type="number" min="0" step="any" class="form-control" 
+            focus-me='focus' required id="bill-dialog-amount" 
+            ng-model="billArgs.amount"/>
+        </div>
+      </div>
+      <div class="form-group">
+        <label for="bill-dialog-note" class="control-label col-md-4">[% l('Note:') %]</label>
+        <div class="col-md-8">
+          <textarea rows="3" class="form-control" placeholder="[% l('Note...') %]"
+            id="bill-dialog-note" ng-model="billArgs.note"></textarea>
+        </div>
+      </div>
+    </div>
+    <div class="modal-footer">
+      <input type="submit" class="btn btn-success" value="[% l('Submit Bill') %]"/>
+      <button class="btn btn-warning" ng-click="cancel($event)">[% l('Cancel') %]</button>
+    </div>
+  </div>
+</form>
+
+
index 68307dd..89d6252 100644 (file)
@@ -8,7 +8,7 @@
   persist-key="circ.patron.bills">
 
   <eg-grid-menu-item label="[% l('Bill Patron') %]" 
-    handler="billPatron"></eg-grid-menu-item>
+    handler="showBillDialog"></eg-grid-menu-item>
 
   <eg-grid-menu-item label="[% l('History') %]" 
     handler="showHistory"></eg-grid-menu-item>
index 6e44de7..8fabfa8 100644 (file)
@@ -39,6 +39,23 @@ function($q , egCore , patronSvc) {
         });
     }
 
+    service.fetchBillingTypes = function() {
+        if (egCore.env.cbt) 
+            return $q.when(egCore.env.cbt.list);
+
+        return egCore.pcrud.search('cbt', 
+            {   // first 100 are reserved for system-generated bills
+                id : {'>' : 100}, 
+                owner : egCore.org.ancestors(
+                    egCore.auth.user().ws_ou(), true)
+            }, 
+            {}, {atomic : true}
+        ).then(function(list) {
+            egCore.env.absorbList(list, 'cbt');
+            return list;
+        });
+    }
+
     return service;
 }])
 
@@ -47,8 +64,9 @@ function($q , egCore , patronSvc) {
  * Manages Bills
  */
 .controller('PatronBillsCtrl',
-       ['$scope','$q','$routeParams','$locale','egCore','egGridDataProvider','billSvc','egPromptDialog',
-function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , billSvc , egPromptDialog) {
+       ['$scope','$q','$routeParams','$locale','egCore','egGridDataProvider','billSvc','patronSvc','egPromptDialog','$modal',
+function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , billSvc , patronSvc , egPromptDialog , $modal) {
+
     $scope.initTab('bills', $routeParams.id);
     billSvc.userId = $routeParams.id;
 
@@ -58,6 +76,8 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
     $scope.focus_payment = true;
     $scope.annotate_payment = false;
     $scope.gridRevision = 0;
+    var allItems = []; // all grid items (flattened mobts)
+    var selectedItems = []; // selected grid items
 
     billSvc.fetchSummary().then(function(s) {$scope.summary = s});
 
@@ -112,13 +132,11 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
     var query = {usr : billSvc.userId, balance_owed : {'<>' : 0}};
     $scope.gridQuery = function() {return query};
 
-    var allItems = [];
     $scope.gridItemRetrieved = function(item) {
         item.payment_pending = 0;
         allItems.push(item);
     }
 
-    var selectedItems = [];
     $scope.gridSelectionChanged = function(all) {
         // update the item.payment_pending value each time the user
         // selects different transactions to pay against.
@@ -130,6 +148,10 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
     // transaction any time the user-entered payment amount is modified
     $scope.$watch('payment_amount', updatePendingColumn);
 
+    // updates the value of the payment_pending column in the grid.
+    // This has to be managed manually since the display value in the grid
+    // is derived from the value on the stored item and not the contents
+    // of our local scope variables.
     function updatePendingColumn() {
         // reset all to zero..
         angular.forEach(allItems, function(item) {item.payment_pending = 0});
@@ -144,6 +166,8 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
         });
     }
 
+    // builds payment arrays ([xact_id, ammount]) for all transactions
+    // which have a pending payment amount.
     function generatePayments() {
         var payments = [];
         var paymentAmount = $scope.pending_payment();
@@ -170,6 +194,8 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
         return payments;
     }
 
+    // generates payments, collects user note if needed, and sends payment
+    // to server.
     function sendPayment(note) {
         billSvc.applyPayment(
             $scope.payment_type, generatePayments(), note)
@@ -180,8 +206,34 @@ function($scope,  $q , $routeParams,  $locale , egCore , egGridDataProvider , bi
         })
     }
 
-    $scope.billPatron = function() {
-        // launch billing dialog
+    $scope.showBillDialog = function() {
+        $modal.open({
+            templateUrl: './circ/patron/t_bill_patron_dialog',
+            controller: 
+                       ['$scope','$modalInstance','billingTypes',
+                function($scope , $modalInstance , billingTypes) {
+                $scope.focus = true;
+                $scope.patron = patronSvc.current;
+                $scope.billingTypes = billingTypes;
+                $scope.location = egCore.org.get(egCore.auth.user().ws_ou()),
+                $scope.billArgs = {
+                    billingType : 101 // default to stock Misc. billing type
+                }
+                $scope.ok = function(args) { $modalInstance.close(args) }
+                $scope.cancel = function () { $modalInstance.dismiss() }
+            }],
+            resolve : {
+                // if we don't already have them, fetch the billing types
+                billingTypes : function() {
+                    return billSvc.fetchBillingTypes();
+                }
+            }
+        }).result.then(
+            function(args) {
+                console.log('BILL: ' + JSON.stringify(args));
+                //billSvc.billPatron(args);
+            }
+        );
     }
 
     $scope.showHistory = function() {