diff --git a/InventoryTraker.Web/App_Start/SeedData.cs b/InventoryTraker.Web/App_Start/SeedData.cs index a91697a..7deb09d 100644 --- a/InventoryTraker.Web/App_Start/SeedData.cs +++ b/InventoryTraker.Web/App_Start/SeedData.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; -using Humanizer; using InventoryTraker.Web.Core; using InventoryTraker.Web.Data; using InventoryTraker.Web.Identity; @@ -77,7 +76,7 @@ namespace InventoryTraker.Web var inventoryTypes = context.InventoryTypes.ToList(); var cityNames = new List {"Maryville", "Wartburg", "Clinton", "Oak Ridge", "Alcoa", "Jellico"}; - for (int i = 0; i < 100; i++) + for (int i = 0; i < 200; i++) { var inventoryType = inventoryTypes.ElementAt(r.Next(0, context.InventoryTypes.Count())); var addedDate = DateTime.Today.AddMonths(-r.Next(1, 24)); @@ -114,6 +113,9 @@ namespace InventoryTraker.Web Transaction transaction; if (transactionDate >= expiration) { + if (r.Next(1, 3) == 1) + break; + transaction = new Transaction { TransactionType = TransactionType.Expired, diff --git a/InventoryTraker.Web/Controllers/InventoryController.cs b/InventoryTraker.Web/Controllers/InventoryController.cs index 36c0f70..6fcb78c 100644 --- a/InventoryTraker.Web/Controllers/InventoryController.cs +++ b/InventoryTraker.Web/Controllers/InventoryController.cs @@ -35,6 +35,13 @@ namespace InventoryTraker.Web.Controllers return BetterJson(viewModels); } + public JsonResult Find(int id) + { + var inventory = _context.Inventories.Find(id); + var viewModel = Mapper.Map(inventory); + return BetterJson(viewModel); + } + private IQueryable AllInventory() { return _context diff --git a/InventoryTraker.Web/Controllers/TransactionController.cs b/InventoryTraker.Web/Controllers/TransactionController.cs index 2f13e53..725c08b 100644 --- a/InventoryTraker.Web/Controllers/TransactionController.cs +++ b/InventoryTraker.Web/Controllers/TransactionController.cs @@ -35,18 +35,26 @@ namespace InventoryTraker.Web.Controllers return BetterJson(viewModels); } - public JsonResult GetTransactions(int pageNumber, int pageSize) + public JsonResult GetTransactions(int? pageNumber, int? pageSize, int? inventoryId) { - var viewModels = + IQueryable query = _context.Transactions - .OrderByDescending(t => t.Timestamp) - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) - .ProjectTo() - .ToArray(); + .OrderByDescending(t => t.Timestamp); - var count = _context.Transactions.Count(); - return BetterJson(new {totalItems = count, transactions = viewModels}); + if (inventoryId.HasValue) + query = + query.Where(t => t.Inventory.Id == inventoryId.Value); + + if (pageNumber.HasValue && pageSize.HasValue) + query = query + .Skip((pageNumber.Value - 1) * pageSize.Value) + .Take(pageSize.Value); + + var totalItems = _context.Transactions.Count(); + var transactions = query + .ProjectTo() + .ToArray(); + return BetterJson(new { totalItems, transactions }); } } } \ No newline at end of file diff --git a/InventoryTraker.Web/InventoryTraker.Web.csproj b/InventoryTraker.Web/InventoryTraker.Web.csproj index 91d8024..9ca85bf 100644 --- a/InventoryTraker.Web/InventoryTraker.Web.csproj +++ b/InventoryTraker.Web/InventoryTraker.Web.csproj @@ -229,7 +229,7 @@ - + @@ -345,7 +345,7 @@ - + diff --git a/InventoryTraker.Web/Models/InventoryViewModel.cs b/InventoryTraker.Web/Models/InventoryViewModel.cs index 14ed27f..3b54a72 100644 --- a/InventoryTraker.Web/Models/InventoryViewModel.cs +++ b/InventoryTraker.Web/Models/InventoryViewModel.cs @@ -27,6 +27,8 @@ namespace InventoryTraker.Web.Models public string Memo { get; set; } + public bool IsExpired => ExpirationDate < DateTime.Today; + public void CreateMappings(IMapperConfiguration configuration) { configuration.CreateMap() diff --git a/InventoryTraker.Web/Models/TransactionViewModel.cs b/InventoryTraker.Web/Models/TransactionViewModel.cs index 94ec525..7b1af06 100644 --- a/InventoryTraker.Web/Models/TransactionViewModel.cs +++ b/InventoryTraker.Web/Models/TransactionViewModel.cs @@ -10,6 +10,7 @@ namespace InventoryTraker.Web.Models { [Required] public int Id { get; set; } + public int InventoryId { get; set; } public string Name { get; set; } public int UnitsPerCase { get; set; } @@ -36,6 +37,8 @@ namespace InventoryTraker.Web.Models public void CreateMappings(IMapperConfiguration configuration) { configuration.CreateMap() + .ForMember(d => d.InventoryId, + opt => opt.MapFrom(s => s.Inventory.Id)) .ForMember(d => d.Name, opt => opt.MapFrom(s => s.Inventory.InventoryType.Name)) .ForMember(d => d.ExpirationDate, diff --git a/InventoryTraker.Web/Views/Inventory/Index.cshtml b/InventoryTraker.Web/Views/Inventory/Index.cshtml index a6c7651..e7f2063 100644 --- a/InventoryTraker.Web/Views/Inventory/Index.cshtml +++ b/InventoryTraker.Web/Views/Inventory/Index.cshtml @@ -1,7 +1,12 @@ -
+@{ + ViewBag.Title = "Inventory"; +} + +

Inventory

+

Current inventory

- +
\ No newline at end of file diff --git a/InventoryTraker.Web/css/layout.css b/InventoryTraker.Web/css/layout.css index f027360..7c5561f 100644 --- a/InventoryTraker.Web/css/layout.css +++ b/InventoryTraker.Web/css/layout.css @@ -47,38 +47,6 @@ textarea { min-height: 90px; } -/* Customer List */ -.customer-list .panel-heading { - font-size: 1.4em; -} - -.customer-list .panel-heading .btn { - margin-top: -5px; -} - -.customer-list th { - width: 100px; -} - -.customer-list table { - font-size: 1em; -} - -.customer-list .panel > .table + .panel-body { - border-top: none; -} - -.opportunity-list h3, .risk-list h3 { - margin-top: 0; -} - -.opportunity-list .add-btn, -.risk-list .add-btn { - display: inline-block; - font-size: 0.9em; - margin-top: 1.5em; -} - .ng-hide-remove { -webkit-transition:0.3s linear opacity; transition:0.3s linear opacity; @@ -101,6 +69,10 @@ textarea { height: 70vh; } +th.control-column { + width: 1%; +} + /*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback { top: 26px; }*/ \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/InventoryEditDirective.js b/InventoryTraker.Web/js/inventory/InventoryEditDirective.js index 8b8d519..f7c5c52 100644 --- a/InventoryTraker.Web/js/inventory/InventoryEditDirective.js +++ b/InventoryTraker.Web/js/inventory/InventoryEditDirective.js @@ -14,13 +14,24 @@ } } - controller.$inject = ['$scope', 'inventorySvc']; - function controller($scope, inventorySvc) { + controller.$inject = ['$scope', 'inventorySvc', 'transactionSvc']; + function controller($scope, inventorySvc, transactionSvc) { var vm = this; - vm.save = save; - - vm.saving = false; vm.inventory = angular.copy($scope.inventory); + vm.transactions = []; + + function loadTransactions() { + transactionSvc + .filterByInventoryId(vm.inventory.id) + .success(function(data) { + angular.merge(vm.transactions, data.transactions); + }); + } + + loadTransactions(); + + vm.save = save; + vm.saving = false; vm.errorMessage = null; function save() { diff --git a/InventoryTraker.Web/js/inventory/InventoryDetailsDirective.js b/InventoryTraker.Web/js/inventory/InventoryListDirective.js similarity index 52% rename from InventoryTraker.Web/js/inventory/InventoryDetailsDirective.js rename to InventoryTraker.Web/js/inventory/InventoryListDirective.js index 784939a..b2ca1e0 100644 --- a/InventoryTraker.Web/js/inventory/InventoryDetailsDirective.js +++ b/InventoryTraker.Web/js/inventory/InventoryListDirective.js @@ -1,11 +1,11 @@ (function() { 'use strict'; - window.app.directive('inventoryDetails', inventoryDetails); - function inventoryDetails() { + window.app.directive('inventoryList', inventoryList); + function inventoryList() { return { scope: {"inventories" : "="}, - templateUrl: '/inventory/template/inventoryDetails.tmpl.cshtml', + templateUrl: '/inventory/template/inventoryList.tmpl.cshtml', controller: controller, controllerAs: 'vm' } @@ -18,10 +18,10 @@ vm.inventories = $scope.inventories; vm.edit = edit; - function edit() { + function edit(inventory) { $uibModal.open({ - template: '', - scope: angular.extend($scope.$new(true), { inventory: vm.inventory }) + template: '', + scope: angular.extend($scope.$new(true), { inventory: inventory }) }); } } diff --git a/InventoryTraker.Web/js/inventory/inventorySvc.js b/InventoryTraker.Web/js/inventory/inventorySvc.js index 7a4a2f1..5a76f6e 100644 --- a/InventoryTraker.Web/js/inventory/inventorySvc.js +++ b/InventoryTraker.Web/js/inventory/inventorySvc.js @@ -46,11 +46,7 @@ } function getInventory(id) { - for (var i = 0; i < inventories.length; i++) { - if (inventories[i].Id == id) return inventories[i]; - } - - return null; + return $http.post('/Inventory/Find', { id: id }); } } })(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryDetails.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryDetails.tmpl.cshtml deleted file mode 100644 index 5ac9eb5..0000000 --- a/InventoryTraker.Web/js/inventory/templates/inventoryDetails.tmpl.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@using InventoryTraker.Web.Helpers -@model InventoryTraker.Web.Models.InventoryViewModel -@{ - var inventory = Html.Angular().ModelFor("inventory"); -} - - - - - - - - - - - - - - - - - - - - - - - - -
NameUnits per CaseCase QtyUnit QtyExp DateAdded DateMemo
@inventory.BindingFor(x => x.Name) @inventory.BindingFor(x => x.UnitsPerCase) / @inventory.BindingFor(x => x.ContainerType)@inventory.BindingFor(x => x.Quantity){{inventory.quantity * inventory.unitsPerCase}}@inventory.BindingFor(x => x.ExpirationDate, "date:'shortDate'")@inventory.BindingFor(x => x.AddedDate, "date:'shortDate'")@inventory.BindingFor(x => x.Memo)
diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml index c8d357a..a33cd8b 100644 --- a/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml +++ b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml @@ -23,10 +23,15 @@ @distribution.FormGroupFor(m => m.Destination) - + @distribution.FormGroupFor(m => m.DistributedDate) + + @distribution.FormGroupFor(m => m.Memo) + +
- + + @@ -34,13 +39,13 @@ +
Name
Units per Case
Expiration Date
Name
Units per Case
Expiration Date Available Case Qty Distribute Case Qty
- {{inventory.name}}
+ {{inventory.name}}
{{inventory.unitsPerCase}} / {{inventory.containerType}}
- Exp: {{inventory.expirationDate | date:'shortDate'}}
{{inventory.expirationDate | date:'shortDate'}} {{inventory.quantity}} -
+
- @distribution.FormGroupFor(m => m.DistributedDate) - - @distribution.FormGroupFor(m => m.Memo) -
diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryList.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryList.tmpl.cshtml new file mode 100644 index 0000000..379cb6b --- /dev/null +++ b/InventoryTraker.Web/js/inventory/templates/inventoryList.tmpl.cshtml @@ -0,0 +1,34 @@ +@using InventoryTraker.Web.Helpers +@model InventoryTraker.Web.Models.InventoryViewModel +@{ + var inventory = Html.Angular().ModelFor("inventory"); +} + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameUnits per CaseCase QtyUnit QtyExp DateAdded DateMemo
@inventory.BindingFor(x => x.Name) @inventory.BindingFor(x => x.UnitsPerCase) / @inventory.BindingFor(x => x.ContainerType)@inventory.BindingFor(x => x.Quantity){{inventory.quantity * inventory.unitsPerCase}} + @inventory.BindingFor(x => x.ExpirationDate, "date:'shortDate'") + @inventory.BindingFor(x => x.AddedDate, "date:'shortDate'")@inventory.BindingFor(x => x.Memo)
diff --git a/InventoryTraker.Web/js/inventoryType/templates/inventoryTypeList.tmpl.cshtml b/InventoryTraker.Web/js/inventoryType/templates/inventoryTypeList.tmpl.cshtml index 17ff6bc..b8b38f7 100644 --- a/InventoryTraker.Web/js/inventoryType/templates/inventoryTypeList.tmpl.cshtml +++ b/InventoryTraker.Web/js/inventoryType/templates/inventoryTypeList.tmpl.cshtml @@ -1,25 +1,24 @@  - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + +
IDNameUnits per CaseContainer TypeWeight Per CasePrice Per Case
IDNameUnits per CaseContainer TypeWeight Per CasePrice Per Case
- - {{inventoryType.identifier}} - {{inventoryType.name}}{{inventoryType.unitsPerCase}}{{inventoryType.containerType}}{{inventoryType.weightPerCase}} lbs{{inventoryType.pricePerCase | currency}}
{{inventoryType.identifier}}{{inventoryType.name}}{{inventoryType.unitsPerCase}}{{inventoryType.containerType}}{{inventoryType.weightPerCase}} lbs{{inventoryType.pricePerCase | currency}}
diff --git a/InventoryTraker.Web/js/transaction/TransactionController.js b/InventoryTraker.Web/js/transaction/TransactionController.js index 40cd979..af582c9 100644 --- a/InventoryTraker.Web/js/transaction/TransactionController.js +++ b/InventoryTraker.Web/js/transaction/TransactionController.js @@ -3,20 +3,21 @@ window.app.controller('TransactionController', TransactionController); - TransactionController.$inject = ['$scope', '$uibModal', 'transactionSvc', 'uiGridConstants']; - function TransactionController($scope, $uibModal, transactionSvc, uiGridConstants) { + TransactionController.$inject = ['$scope', '$uibModal', 'transactionSvc', 'inventorySvc', 'uiGridConstants']; + function TransactionController($scope, $uibModal, transactionSvc, inventorySvc, uiGridConstants) { var vm = this; var paginationOptions = { pageNumber: 1, pageSize: 20, + pageSizes: [20,50,100], sort: null }; - + vm.gridOptions = { enablePaginationControls: true, paginationPageSize: paginationOptions.pageSize, - paginationPageSizes: [20,50,100], + paginationPageSizes: paginationOptions.pageSizes, useExternalPagination: true, enableSorting: false, columnDefs: [ @@ -30,7 +31,7 @@ '\r{{row.entity.unitsPerCase}} / {{row.entity.containerType}}' + '\rExp Date: {{row.entity.expirationDate | date:\'shortDate\'}}' + '\rAdd Date: {{row.entity.addedDate | date:\'shortDate\'}}">' + - ' ' + + ' ' + '{{row.entity.name}}
' }, { field: 'transactionType', name: 'Type', width: "10%" }, @@ -43,33 +44,34 @@ ], onRegisterApi: function(gridApi) { vm.gridApi = gridApi; - //vm.gridApi.core.on.sortChanged($scope, - // function(grid, sortColumns) { - // if (sortColumns.length == 0) { - // paginationOptions.sort = null; - // } else { - // paginationOptions.sort = sortColumns[0].sort.direction; - // } - // getPage(); - // }); - vm.gridApi.pagination.on.paginationChanged($scope, - function(newPage, pageSize) { - paginationOptions.pageNumber = newPage; + vm.gridApi.pagination + .on.paginationChanged($scope, function(pageNumber, pageSize) { + paginationOptions.pageNumber = pageNumber; paginationOptions.pageSize = pageSize; updateData(); }); } }; - var updateData = function () { + function updateData() { transactionSvc - .getTransactions(paginationOptions.pageNumber, paginationOptions.pageSize) - .success(function(data) { - vm.gridOptions.totalItems = data.totalItems; + .filterByPage(paginationOptions.pageNumber, paginationOptions.pageSize) + .success(function (data) { vm.gridOptions.data = data.transactions; + vm.gridOptions.totalItems = data.totalItems; }); - }; + } updateData(); + + $scope.editInventory = function (inventoryId) { + inventorySvc.getInventory(inventoryId) + .success(function(inventory) { + $uibModal.open({ + template: '', + scope: angular.extend($scope.$new(true), { inventory: inventory }) + }); + }); + } } })(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/transaction/transactionSvc.js b/InventoryTraker.Web/js/transaction/transactionSvc.js index 7f9f0eb..a93c4a8 100644 --- a/InventoryTraker.Web/js/transaction/transactionSvc.js +++ b/InventoryTraker.Web/js/transaction/transactionSvc.js @@ -5,33 +5,25 @@ function transactionSvc($http) { var svc = { - update: update, - getTransactions: getTransactions, - getTransaction: getTransaction + filterByPage: filterByPage, + filterByInventoryId: filterByInventoryId }; return svc; + + function filterByPage(pageNumber, pageSize) { + return getTransactions({ pageNumber: pageNumber, pageSize: pageSize }); + } - function getTransactions(pageNumber, pageSize) { + function filterByInventoryId(inventoryId) { + return getTransactions({ inventoryId: inventoryId }); + } + + function getTransactions(params) { var url = '/Transaction/GetTransactions'; - return $http.post(url, { pageNumber: pageNumber, pageSize: pageSize }); - //.success(function(data) { - // return data.data; - //}); - } - - function update(existingTransaction, updatedTransaction) { - return $http.post('/Transaction/Update', updatedTransaction) - .success(function(transaction) { - angular.extend(existingTransaction, transaction); + return $http.post(url, params) + .success(function (data) { }); } - - function getTransaction(id) { - for (var i = 0; i < transactions.length; i++) { - if (transactions[i].Id == id) return transactions[i]; - } - return null; - } } })(); \ No newline at end of file