Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Added transaction list to inventory edit screen
Browse files Browse the repository at this point in the history
Resolves #76
  • Loading branch information
jkleinsc committed Apr 7, 2015
1 parent af6986a commit 91af65a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
32 changes: 30 additions & 2 deletions app/inventory/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down
9 changes: 9 additions & 0 deletions app/inventory/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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();
}
});
52 changes: 52 additions & 0 deletions app/inventory/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,57 @@
{{/if}}
{{/each}}
</table>
{{#if showTransactions}}
<h3>Transactions</h3>
<table class="table">
<tr class="table-header">
<th>Date Completed</th>
<th>Quantity</th>
<th>Transaction</th>
<th>Details</th>
</tr>
{{#if haveTransactions}}
{{#each transactions itemController='inventory/completed-items'}}
<tr>
<td>{{date-format dateCompleted}}</td>
<td>{{quantity}}</td>
<td>{{transactionType}}</td>
<td>
{{#if isAdjustment}}
{{#if haveReason}}
<strong>Reason:</strong> {{reason}}<br/>
{{/if}}
<strong>Location Adjusted:</strong> {{deliveryDetails}}
{{/if}}
{{#if isFulfillment}}
<strong>Cost Per Unit:</strong> {{costPerUnit}}<br/>
<strong>Quantity At Completion:</strong> {{quantityAtCompletion}}<br/>
<strong>Pulled From:</strong>
{{#each locationsAffected}}
{{name}}<br/>
{{/each}}
{{#if patient}}
<strong>Prescription For: </strong> {{deliveryDetails}}
{{else}}
<strong>Delivered To: </strong> {{deliveryDetails}}
{{/if}}
{{/if}}
{{#if isTransfer}}
<strong>Transferred From:</strong>
{{#each locationsAffected}}
{{name}}<br/>
{{/each}}
<strong>Transferred To: </strong> {{deliveryDetails}}
{{/if}}
</td>
</tr>
{{/each}}
{{else}}
<tr>
<td colspan="4"><span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span> Loading transactions....</td>
</tr>
{{/if}}
</table>
{{/if}}
{{/unless}}
{{/em-form}}
5 changes: 5 additions & 0 deletions app/mixins/fulfill-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
Expand Down
20 changes: 20 additions & 0 deletions app/utils/pouch-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 91af65a

Please sign in to comment.