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

Commit

Permalink
Starting batch inventory entry
Browse files Browse the repository at this point in the history
Work for #75
  • Loading branch information
jkleinsc committed Apr 15, 2015
1 parent 94c7a25 commit 9a9f826
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 48 deletions.
10 changes: 0 additions & 10 deletions app/inventory/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ export default AbstractEditController.extend(InventoryLocations, InventoryTypeLi
return transactions !== null;
}.property('transactions.@each'),

inventoryTypes: function() {
var defaultInventoryTypes = this.get('defaultInventoryTypes'),
inventoryTypeList = this.get('inventoryTypeList');
if (Ember.isEmpty(inventoryTypeList)) {
return defaultInventoryTypes;
} else {
return inventoryTypeList;
}
}.property('inventoryTypeList', 'defaultInventoryTypes'),

locationQuantityTotal: function() {
var locations = this.get('locations');
var total = locations.reduce(function(previousValue, location) {
Expand Down
38 changes: 1 addition & 37 deletions app/inventory/edit/template.hbs
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
{{#em-form model=this submit_button=false }}
<div class="row">
{{#unless isNew}}
<div class="form-group col-sm-2">
<label>ID</label>
{{input class="form-control" value=friendlyId type="text" disabled=true }}
</div>
{{/unless}}
{{em-input property="name" label="Name" class="required col-sm-8"}}
{{#unless isNew}}
<div class="form-group col-sm-2">
<label>Quantity</label>
<p class="form-control-static">{{quantity}}</p>
</div>
{{/unless}}

</div>
{{em-text label="Description" property="description" rows=1 }}
<div class="row">
{{em-select label="Type" property="type"
content=inventoryTypes
optionValuePath="content"
optionLabelPath="content"
class="required col-sm-4"
}}
{{em-input property="crossReference" label="Cross Reference" class="col-sm-8"}}
</div>
<div class="row">
{{em-input property="reorderPoint" label="Reorder Point" class="col-sm-3"}}
{{em-input property="price" label="Price Per Unit" class="col-sm-3"}}
{{em-select label="Distribution Unit" class="col-sm-3"
property="distributionUnit"
content=unitList
optionLabelPath="content"
optionValuePath="content"

}}
</div>
{{partial 'inventory-basic'}}
{{#if isNew}}
<h3>Purchase information</h3>
{{partial 'inv-purchase'}}
Expand Down
107 changes: 107 additions & 0 deletions app/inventory/invoice/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller';
import InventorySelection from 'hospitalrun/mixins/inventory-selection';
import Ember from 'ember';

export default AbstractEditController.extend(InventorySelection, {
needs: ['inventory','pouchdb'],

warehouseList: Ember.computed.alias('controllers.inventory.warehouseList'),
aisleLocationList: Ember.computed.alias('controllers.inventory.aisleLocationList'),


inventoryList: function() {
var inventoryItems = this.get('inventoryItems');
if (!Ember.isEmpty(inventoryItems)) {
var mappedItems = inventoryItems.map(function(item) {
return item.doc;
});
return mappedItems;
}
}.property('inventoryItems.[]'),

lookupListsToUpdate: [{
name: 'aisleLocationList', //Name of property containing lookup list
property: 'deliveryAisle', //Corresponding property on model that potentially contains a new value to add to the list
id: 'aisle_location_list' //Id of the lookup list to update
}, {
name: 'warehouseList', //Name of property containing lookup list
property: 'deliveryLocation', //Corresponding property on model that potentially contains a new value to add to the list
id: 'warehouse_list' //Id of the lookup list to update
}],


showInvoiceItems: function() {
var invoiceItems = this.get('invoiceItems');
return !Ember.isEmpty(invoiceItems);
}.property('invoiceItems.@each'),

updateCapability: 'add_inventory_item',

_addNewInventoryItem: function() {
var inventoryItem = this.store.createRecord('inventory', {
name: this.get('inventoryItemTypeAhead'),
quantity: this.get('quantity')
});
this.send('openModal', 'inventory.quick-add', inventoryItem);
},

_addInvoiceItem: function() {
var inventoryItem = this.get('inventoryItem'),
invoiceItems = this.get('invoiceItems'),
purchaseCost = this.get('purchaseCost'),
quantity = this.get('quantity'),
vendorItemNo = this.get('vendorItemNo'),
invoiceItem = Ember.Object.create({
item: inventoryItem,
quantity: quantity,
purchaseCost: purchaseCost,
vendorItemNo: vendorItemNo
});
invoiceItems.addObject(invoiceItem);
this.set('inventoryItem');
this.set('inventoryItemTypeAhead');
this.set('purchaseCost');
this.set('quantity');
this.set('selectedInventoryItem');
this.set('vendorItemNo');
},

actions: {
addInventoryItem: function() {
var model = this.get('model'),
inventoryItemTypeAhead = this.get('inventoryItemTypeAhead'),
purchaseCost = this.get('purchaseCost'),
quantity = this.get('quantity');
model.validate();
if (this.get('isValid') && !Ember.isEmpty(inventoryItemTypeAhead) && !Ember.isEmpty(quantity) && !Ember.isEmpty(purchaseCost)) {
if (Ember.isEmpty(this.get('selectedInventoryItem'))) {
this._addNewInventoryItem();
} else {
this._addInvoiceItem();
}
}
},

addedNewInventoryItem: function(inventoryItem) {
this.set('inventoryItem', inventoryItem);
this._addInvoiceItem();
this.send('closeModal');
},

removeItem: function(removeInfo) {
var invoiceItems = this.get('invoiceItems'),
item = removeInfo.itemToRemove;
invoiceItems.removeObject(item);
this.send('closeModal');
},

showRemoveItem: function(item) {
var message= 'Are you sure you want to remove this item from this invoice?',
model = Ember.Object.create({
itemToRemove: item
}),
title = 'Remove Item';
this.displayConfirm(title, message, 'removeItem', model);
},
}
});
18 changes: 18 additions & 0 deletions app/inventory/invoice/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import InventoryRequestRoute from 'hospitalrun/inventory/request/route';
import Ember from 'ember';
export default InventoryRequestRoute.extend({
editTitle: 'Invoice Received',
modelName: 'inventory-invoice',
newTitle: 'Invoice Received',
getNewData: function() {
return Ember.RSVP.resolve({
invoiceItems: []
});
},

actions: {
addedNewInventoryItem: function(model) {
this.controller.send('addedNewInventoryItem', model);
}
},
});
78 changes: 78 additions & 0 deletions app/inventory/invoice/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{#em-form model=this submit_button=false }}
<div class="row">
<div class="col-sm-6">
{{em-input property="vendor" label="Vendor"}}
</div>
<div class="col-sm-6">
{{em-input property="invoiceNo" label="Invoice Number"}}
</div>
</div>
<div class="row">
{{inventory-typeahead
class="col-sm-4 required"
property="inventoryItemTypeAhead"
label="Inventory Item"
content=inventoryList
selection=selectedInventoryItem
showQuantity=false
}}
{{em-input property="quantity" label="Quantity" class="col-sm-2 required"}}
{{em-input property="purchaseCost" label="Purchase Cost" class="col-sm-2 required"}}
{{em-input property="vendorItemNo" label="Vendor Item Number" class="col-sm-3"}}
<div class="form-group col-sm-1">
<label class="control-label"></label>
<h4 class="form-control-static">
<span class="glyphicon glyphicon-plus" {{action 'addInventoryItem'}}></span>
</h4>
</div>
</div>
<textarea>
name
quantity
price
item number

Need for new item type
Need to new item unit
</textarea>
{{#if invoiceItems}}
<h3>Invoice Items</h3>
<table class="table">
<tr class="table-header">
<th>Name</th>
<th>Quantity</th>
<th>Cost</th>
<th>Item Number</th>
<th>Action</th>
</tr>
{{#each invoiceItems}}
<tr>
<td class="col-sm-4">
{{item.name}}
</td>
<td class="col-sm-2">
<div class="form-group">
{{input class="form-control" value=quantity }}
</div>
</td>
<td class="col-sm-2">
<div class="form-group">
{{input class="form-control" value=purchaseCost }}
</div>
</td>
<td class="col-sm-3">
<div class="form-group">
{{input class="form-control" value=vendorItemNo }}
</div>
</td>
<td class="col-sm-1">
<button class="btn btn-default warning" {{action "showRemoveItem" this bubbles=false }}>
<span class="octicon octicon-x"></span>Remove
</button>
</td>
</tr>
{{/each}}
</table>
{{/if}}

{{/em-form}}
2 changes: 2 additions & 0 deletions app/inventory/invoice/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import PanelView from 'hospitalrun/views/panel';
export default PanelView.extend();
16 changes: 16 additions & 0 deletions app/inventory/quick-add/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import InventoryEditController from 'hospitalrun/inventory/edit/controller';
export default InventoryEditController.extend({
title: 'New Inventory Item',

updateCapability: 'add_inventory_item',

actions: {
cancel: function() {
this.send('closeModal');
}
},

afterUpdate: function(record) {
this.send('addedNewInventoryItem', record);
}
});
3 changes: 3 additions & 0 deletions app/inventory/quick-add/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#em-form model=this submit_button=false }}
{{partial 'inventory-basic'}}
{{/em-form}}
2 changes: 2 additions & 0 deletions app/inventory/quick-add/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ModalView from 'hospitalrun/views/modal';
export default ModalView.extend();
12 changes: 11 additions & 1 deletion app/mixins/inventory-type-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ export default Ember.Mixin.create({
defaultInventoryTypes: [
'Medication',
'Supply'
]
],

inventoryTypes: function() {
var defaultInventoryTypes = this.get('defaultInventoryTypes'),
inventoryTypeList = this.get('inventoryTypeList');
if (Ember.isEmpty(inventoryTypeList)) {
return defaultInventoryTypes;
} else {
return inventoryTypeList;
}
}.property('inventoryTypeList', 'defaultInventoryTypes')
});
39 changes: 39 additions & 0 deletions app/models/inventory-invoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import AbstractModel from "hospitalrun/models/abstract";
import Ember from "ember";

/**
* Model to represent a request for inventory items.
*/
export default AbstractModel.extend({

haveInvoiceItems: function() {
var invoiceItems = this.get('invoiceItems');
return (Ember.isEmpty(invoiceItems));
},

validations: {
inventoryItemTypeAhead: {
presence: {
if: function(object) {
return object.haveInvoiceItems();
}
}
},
purchaseCost: {
numericality: {
greaterThan: 0,
if: function(object) {
return object.haveInvoiceItems();
}
}
},
quantity: {
numericality: {
greaterThan: 0,
if: function(object) {
return object.haveInvoiceItems();
}
}
}
}
});
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Router.map(function() {
this.route('barcode', { path: "/barcode/:inventory_id" });
this.route('delivery', { path: "/delivery/:inv-request_id" });
this.route('edit', { path: "/edit/:inventory_id" });
this.route('invoice', { path: "/invoice/:inventory-invoice_id" });
this.route('listing');
this.route('reports');
this.route('request', { path: "/request/:inv-request_id" });
Expand Down
Loading

0 comments on commit 9a9f826

Please sign in to comment.