diff --git a/app/inventory/edit/controller.js b/app/inventory/edit/controller.js index efc9f503f1..e5fd4461e7 100644 --- a/app/inventory/edit/controller.js +++ b/app/inventory/edit/controller.js @@ -40,6 +40,11 @@ export default AbstractEditController.extend(InventoryLocations, InventoryTypeLi return (this.get('isNew')); }.property('isNew'), + haveTransactions: function() { + var transactions = this.get('transactions'); + return transactions !== null; + }.property('transactions.@each'), + inventoryTypes: function() { var defaultInventoryTypes = this.get('defaultInventoryTypes'), inventoryTypeList = this.get('inventoryTypeList'); @@ -86,6 +91,13 @@ export default AbstractEditController.extend(InventoryLocations, InventoryTypeLi } }.observes('originalQuantity'), + showTransactions: function() { + var transactions = this.get('transactions'); + return !Ember.isEmpty(transactions); + }.property('transactions.@each'), + + transactions: null, + updateCapability: 'add_inventory_item', actions: { @@ -191,7 +203,7 @@ export default AbstractEditController.extend(InventoryLocations, InventoryTypeLi request.get('inventoryItem').then(function() { //Make sure relationships are resolved before saving this._saveRequest(request); - }.bind(this)); + }.bind(this)); }, updatePurchase: function(purchase, updateQuantity) { @@ -278,10 +290,26 @@ export default AbstractEditController.extend(InventoryLocations, InventoryTypeLi request.set('completedBy',request.getUserName()); request.save().then(function() { this.send('update',true); - this.send('closeModal'); + this.send('closeModal'); + this.getTransactions(); }.bind(this)); }, + getTransactions: function() { + var inventoryId = 'inventory_'+this.get('id'); + this.set('transactions',null); + this.store.find('inv-request', { + options: { + endkey: [inventoryId, 'Completed', 0], + startkey: [inventoryId, 'Completed', 9999999999999], + descending: true + }, + mapReduce: 'inventory_request_by_item' + }).then(function(transactions) { + this.set('transactions', transactions); + }.bind(this)); + }, + beforeUpdate: function() { if (this.get('isNew')) { var type = this.get('type'); diff --git a/app/inventory/edit/route.js b/app/inventory/edit/route.js index a1b04e99bc..edb8f153d4 100644 --- a/app/inventory/edit/route.js +++ b/app/inventory/edit/route.js @@ -11,6 +11,10 @@ export default AbstractEditRoute.extend(InventoryId, { this.controller.send('adjustItems',inventoryLocation); }, + doneFulfillRequest: function() { + this.controller.getTransactions(); + }, + deletePurchase: function(purchase, deleteFromLocation) { this.controller.send('deletePurchase', purchase, deleteFromLocation); }, @@ -32,5 +36,10 @@ export default AbstractEditRoute.extend(InventoryId, { return Ember.RSVP.resolve({ dateReceived: new Date() }); + }, + + setupController: function(controller, model) { + this._super(controller, model); + controller.getTransactions(); } }); \ No newline at end of file diff --git a/app/inventory/edit/template.hbs b/app/inventory/edit/template.hbs index 3cf25fa498..1e3b4ecc3d 100644 --- a/app/inventory/edit/template.hbs +++ b/app/inventory/edit/template.hbs @@ -104,5 +104,57 @@ {{/if}} {{/each}} + {{#if showTransactions}} +

Transactions

+ + + + + + + + {{#if haveTransactions}} + {{#each transactions itemController='inventory/completed-items'}} + + + + + + + {{/each}} + {{else}} + + + + {{/if}} +
Date CompletedQuantityTransactionDetails
{{date-format dateCompleted}}{{quantity}}{{transactionType}} + {{#if isAdjustment}} + {{#if haveReason}} + Reason: {{reason}}
+ {{/if}} + Location Adjusted: {{deliveryDetails}} + {{/if}} + {{#if isFulfillment}} + Cost Per Unit: {{costPerUnit}}
+ Quantity At Completion: {{quantityAtCompletion}}
+ Pulled From: + {{#each locationsAffected}} + {{name}}
+ {{/each}} + {{#if patient}} + Prescription For: {{deliveryDetails}} + {{else}} + Delivered To: {{deliveryDetails}} + {{/if}} + {{/if}} + {{#if isTransfer}} + Transferred From: + {{#each locationsAffected}} + {{name}}
+ {{/each}} + Transferred To: {{deliveryDetails}} + {{/if}} +
Loading transactions....
+ {{/if}} {{/unless}} {{/em-form}} \ No newline at end of file diff --git a/app/mixins/fulfill-request.js b/app/mixins/fulfill-request.js index 19ae4cb77b..7e36082c7b 100644 --- a/app/mixins/fulfill-request.js +++ b/app/mixins/fulfill-request.js @@ -2,6 +2,10 @@ import Ember from "ember"; //NOTE!!! inventory-locations mixin is needed for fulfill-request mixin! export default Ember.Mixin.create({ actions: { + doneFulfillRequest: function() { + //Placeholder function; override if you need to know when fulfillrequest is complete. + }, + fulfillRequest: function(request, closeModal, increment, skipTransition) { var markAsConsumed = request.get('markAsConsumed'), transactionType = request.get('transactionType'); @@ -166,6 +170,7 @@ export default Ember.Mixin.create({ request.set('completedBy', request.getUserName()); promises.push(request.save()); Ember.RSVP.all(promises,'All saving done for inventory fulfillment').then(function(){ + this.send('doneFulfillRequest'); if (closeModal) { this.send('closeModal'); } diff --git a/app/utils/pouch-views.js b/app/utils/pouch-views.js index 7811f843b4..792b79fd59 100644 --- a/app/utils/pouch-views.js +++ b/app/utils/pouch-views.js @@ -159,6 +159,26 @@ var designDocs = [{ } }, version: 2 +}, { + name: 'inventory_request_by_item', + function: function(doc) { + var doctype, + uidx; + if (doc._id && (uidx = doc._id.indexOf("_")) > 0) { + doctype = doc._id.substring(0, uidx); + if(doctype === 'inv-request') { + var dateCompleted = doc.dateCompleted; + if (dateCompleted && dateCompleted !== '') { + dateCompleted = new Date(dateCompleted); + if (dateCompleted.getTime) { + dateCompleted = dateCompleted.getTime(); + } + } + emit([doc.inventoryItem, doc.status, dateCompleted]); + } + } + }, + version: 2 }, { name: 'inventory_request_by_status', function: function(doc) {