Add commodity and quantity to input forms

This commit is contained in:
2016-08-11 09:27:38 -04:00
parent 0b0cb7c73a
commit f4e3ac1cce
11 changed files with 200 additions and 29 deletions
+1 -1
View File
@@ -163,7 +163,7 @@
</site>
<site name="InventoryTraker.Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\poprhythm\Desktop\InventoryTraker\InventoryTraker.Web" />
<virtualDirectory path="/" physicalPath="C:\Users\poprhythm\Documents\code\InventoryTraker\InventoryTraker.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:58446:localhost" />
+1 -1
View File
@@ -7,7 +7,7 @@ namespace InventoryTraker.Web
{
public static void Initialize()
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<AppDbContext>());
Database.SetInitializer(new DropCreateDatabaseAlways<AppDbContext>());
}
}
}
+25 -3
View File
@@ -67,17 +67,39 @@ namespace InventoryTraker.Web
private static void AddInventory(AppDbContext context)
{
var peanutButterSmooth = new InventoryType
{
ContainerType = "18 oz jars",
Name = "Peanut Butter Smth 18",
Id = "100395",
UnitsPerCase = 12,
PricePerCase = 14.55M,
WeightPerCase = 13.5
};
context.InventoryTypes.Add(peanutButterSmooth);
var beanInventoryType = new InventoryType
{
ContainerType = "#300 cans",
Name = "Beans, Green 300",
Name = "Beans, Veg 300",
Id = "100363",
UnitsPerCase = 24,
PricePerCase = 20.42M,
WeightPerCase = 30.2
PricePerCase = 10.18M,
WeightPerCase = 24
};
context.InventoryTypes.Add(beanInventoryType);
var corn = new InventoryType
{
ContainerType = "#300 cans",
Name = "Corn Kernel 300",
Id = "100311",
UnitsPerCase = 24,
PricePerCase = 10.03M,
WeightPerCase = 22.9
};
context.InventoryTypes.Add(corn);
context.Inventories.Add(new Inventory
{
InventoryType = beanInventoryType,
@@ -8,6 +8,25 @@ using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class InventoryTypeController : ControllerBase
{
private readonly AppDbContext _context;
public InventoryTypeController(AppDbContext context)
{
_context = context;
}
public JsonResult All()
{
var viewModels = _context.InventoryTypes
.OrderByDescending(x => x.Name)
.ProjectTo<InventoryTypeViewModel>();
return BetterJson(viewModels.ToArray());
}
}
public class InventoryController : ControllerBase
{
private readonly AppDbContext _context;
@@ -24,20 +43,22 @@ namespace InventoryTraker.Web.Controllers
public JsonResult All()
{
var customerModels = _context.Inventories
var viewModels = _context.Inventories
.OrderByDescending(x => x.InventoryType.Name)
.ProjectTo<InventoryViewModel>();
.ProjectTo<InventoryViewModel>()
.ToArray();
return BetterJson(customerModels.ToArray());
return BetterJson(viewModels);
}
public JsonResult Arrival(AddCustomerForm form)
public JsonResult Add(InventoryAddForm form)
{
var customer = Mapper.Map<Customer>(form);
_context.Customers.Add(customer);
var inventory = Mapper.Map<Inventory>(form);
inventory.InventoryType = _context.InventoryTypes.Find(form.InventoryTypeId);
_context.Inventories.Add(inventory);
_context.SaveChanges();
var model = Mapper.Map<CustomerViewModel>(customer);
var model = Mapper.Map<InventoryViewModel>(inventory);
return BetterJson(model);
}
}
+6
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace InventoryTraker.Web.Core
@@ -11,10 +12,13 @@ namespace InventoryTraker.Web.Core
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int UnitsPerCase { get; set; }
[Required]
public string ContainerType { get; set; }
public double WeightPerCase { get; set; }
@@ -30,8 +34,10 @@ namespace InventoryTraker.Web.Core
public virtual ICollection<Transaction> Transactions { get; set; }
[Required]
public DateTime ExpirationDate { get; set; }
[Required]
public int Quantity { get; set; }
public string Memo { get; set; }
@@ -28,7 +28,6 @@ namespace InventoryTraker.Web.Models
configuration.CreateMap<Inventory, InventoryViewModel>()
.ForMember(d => d.Name, opt => opt.MapFrom(s => s.InventoryType.Name))
.ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.InventoryType.UnitsPerCase))
.ForMember(d => d.ContainerType, opt => opt.MapFrom(s => s.InventoryType.ContainerType))
.ForMember(d => d.WeightPerCase, opt => opt.MapFrom(s => s.InventoryType.WeightPerCase))
.ForMember(d => d.PricePerCase, opt => opt.MapFrom(s => s.InventoryType.PricePerCase));
}
@@ -9,7 +9,7 @@
Inventory
<a class="pull-right" href="" ng-click="vm.add()"><i class="fa fa-plus-circle"></i></a>
</h1>
<div class="customer-list">
<div class="inventory-list">
<inventory-details ng-repeat="inventory in vm.inventories" inventory="inventory"></inventory-details>
</div>
</div>
@@ -11,14 +11,22 @@
}
}
controller.$inject = ['$scope', 'inventorySvc'];
function controller($scope, inventorySvc) {
controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc'];
function controller($scope, inventorySvc, inventoryTypeSvc) {
var vm = this;
vm.add = add;
vm.saving = false;
vm.inventory = {};
vm.inventoryTypes = inventoryTypeSvc.inventoryTypes;
vm.errorMessage = null;
vm.quantity = quantity;
function quantity() {
vm.inventory.quantity =
$scope.palletCount * $scope.casesPerPallet + $scope.caseCount;
return vm.inventory.quantity;
}
function add() {
vm.saving = true;
@@ -34,5 +42,10 @@
vm.saving = false;
});
}
$scope.$watch('commodity', function (newValue, oldValue) {
if (newValue)
vm.inventory.inventoryTypeId = newValue.id;
});
}
})();
@@ -19,7 +19,6 @@
vm.inventory = $scope.inventory;
vm.edit = edit;
vm.inventory = $scope.inventory;
function edit() {
$uibModal.open({
@@ -11,7 +11,7 @@
add: add,
update: update,
inventories: inventories,
getInventory: getInventory
getInventory: getInventory,
};
return svc;
@@ -42,6 +42,56 @@
if (inventories[i].Id == id) return inventories[i];
}
return null;
}
}
})();
(function () {
window.app.factory('inventoryTypeSvc', inventoryTypeSvc);
inventoryTypeSvc.$inject = ['$http'];
function inventoryTypeSvc($http) {
var inventoryTypes = [];
loadInventoryTypes();
var svc = {
add: add,
update: update,
inventoryTypes: inventoryTypes,
getInventoryType: getInventoryType
};
return svc;
function loadInventoryTypes() {
$http.post('/InventoryType/All')
.success(function (data) {
inventoryTypes.addRange(data);
});
}
function add(inventoryType) {
return $http.post('/InventoryType/Add', inventoryType)
.success(function (inventoryType) {
inventoryTypes.unshift(inventoryType);
});
}
function update(existingInventory, updatedInventory) {
return $http.post('/InventoryType/Update', updatedInventory)
.success(function (inventory) {
angular.extend(existingInventory, inventory);
});
}
function getInventoryType(id) {
for (var i = 0; i < inventoryTypes.length; i++) {
if (inventoryTypes[i].Id == id) return inventoryTypes[i];
}
return null;
}
}
@@ -17,20 +17,81 @@
<div class="alert alert-info" ng-hide="vm.errorMessage != null">
Enter details for the inventory arrival below.
</div>
<div class="alert alert-danger" ng-show="vm.errorMessage != null">
{{vm.errorMessage}}
</div>
<div class="alert alert-danger" ng-show="vm.errorMessage != null">
{{vm.errorMessage}}
</div>
@inventory.FormGroupFor(m => m.ExpirationDate)
@inventory.FormGroupFor(m => m.AddedDate)
@inventory.FormGroupFor(m => m.Memo)
<script type="text/ng-template" id="commodityTypeahead.html">
<a>
<span ng-bind-html="match.label.name | uibTypeaheadHighlight:query"></span>
</a>
</script>
</div>
<div class="form-group has-feedback" ng-class="vm.getValidationClass()" form-group-validation="Commodity">
<label for="Commodity" class="control-label">Commodity</label>
<input name="Commodity" type="text"
ng-model="commodity"
required
uib-typeahead="inventoryType as inventoryType.name for inventoryType in vm.inventoryTypes | filter:{name:$viewValue} | limitTo:8"
typeahead-editable='false'
class="form-control">
<i class="fa fa-search form-control-feedback"></i>
<div class="panel panel-default" ng-show="commodity.id">
<div class="panel-heading">Selected Commodity</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>Commodity ID</dt>
<dd>{{commodity.id}}</dd>
<dt>Name</dt>
<dd>{{commodity.name}}</dd>
<dt>Units per Case</dt>
<dd>{{commodity.unitsPerCase}} / {{commodity.containerType}}</dd>
</dl>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success">Add</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div>
@inventory.FormGroupFor(m => m.ExpirationDate)
<div class="form-group has-feedback panel panel-default">
<div class="panel-heading"><label>Quantity</label></div>
<div class="panel-body container-fluid">
<div class="row">
<div class="col-sm-5">Pallets</div>
<div class="col-sm-3">
<input type="number" class="form-control" ng-model="palletCount" />
</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-offset-1">Cases per Pallet</div>
<div class="col-sm-3">
<input type="number" class="form-control" ng-model="casesPerPallet" />
</div>
</div>
<hr />
<div class="row">
<div class="col-sm-5">Individual Cases</div>
<div class="col-sm-3">
<input type="number" class="form-control" ng-model="caseCount" />
</div>
</div>
<hr />
<div class="row">
<div class="col-sm-5">Total Units</div>
<div class="col-sm-3">{{vm.quantity()}}</div>
</div>
</div>
</div>
@inventory.FormGroupFor(m => m.AddedDate)
@inventory.FormGroupFor(m => m.Memo)
</div>
<div class="modal-footer">
<button class="btn btn-success">Add</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div>
</fieldset>
</form>