From f5e438e994e436dae7769767bad54410c64b1191 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Wed, 31 Aug 2016 12:08:22 -0400 Subject: [PATCH] Add transaction type --- InventoryTraker.Web/App_Start/SeedData.cs | 62 ++++++++++++++----- .../Controllers/InventoryController.cs | 2 + InventoryTraker.Web/Core/Transaction.cs | 10 +++ .../InventoryTraker.Web.csproj | 1 + .../Models/TransactionViewModel.cs | 25 ++++---- .../templates/inventoryDistribute.tmpl.cshtml | 11 ++-- .../js/transaction/TransactionController.js | 12 ++-- .../js/utility/HideZeroFilter.js | 10 +++ 8 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 InventoryTraker.Web/js/utility/HideZeroFilter.js diff --git a/InventoryTraker.Web/App_Start/SeedData.cs b/InventoryTraker.Web/App_Start/SeedData.cs index a0ad325..a91697a 100644 --- a/InventoryTraker.Web/App_Start/SeedData.cs +++ b/InventoryTraker.Web/App_Start/SeedData.cs @@ -81,13 +81,18 @@ namespace InventoryTraker.Web { var inventoryType = inventoryTypes.ElementAt(r.Next(0, context.InventoryTypes.Count())); var addedDate = DateTime.Today.AddMonths(-r.Next(1, 24)); - var expiration = addedDate.AddMonths(r.Next(12, 48)); + var expiration = addedDate.AddMonths(r.Next(2, 48)); var memo = "New " + inventoryType.Name; var quantity = r.Next(5, 112); var previousTransaction = new Transaction { - AddedQuantity = quantity, Memo = "Arrival", CurrentQuantity = quantity, TransactionDate = addedDate, Timestamp = addedDate + TransactionType = TransactionType.Added, + AddedQuantity = quantity, + Memo = "Arrival", + CurrentQuantity = quantity, + TransactionDate = addedDate, + Timestamp = addedDate }; var inventory = new Inventory { @@ -106,21 +111,46 @@ namespace InventoryTraker.Web if (transactionDate >= DateTime.Today) break; - var quantityRemoved = r.Next(1, 100); - if (quantityRemoved > previousTransaction.CurrentQuantity) - quantityRemoved = previousTransaction.CurrentQuantity; - - var destCity = cityNames.ElementAt(r.Next(0, cityNames.Count)); - - var transaction = new Transaction + Transaction transaction; + if (transactionDate >= expiration) { - RemovedQuantity = quantityRemoved, - CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved, - Inventory = inventory, - Memo = $"Distributed to {destCity}", - TransactionDate = transactionDate, - Timestamp = transactionDate - }; + transaction = new Transaction + { + TransactionType = TransactionType.Expired, + RemovedQuantity = previousTransaction.CurrentQuantity, + CurrentQuantity = 0, + Inventory = inventory, + Memo = $"Expired on {expiration.ToShortDateString()}", + TransactionDate = transactionDate, + Timestamp = transactionDate + }; + } + else + { + var quantityRemoved = r.Next(1, 100); + if (quantityRemoved > previousTransaction.CurrentQuantity) + quantityRemoved = previousTransaction.CurrentQuantity; + + var transMemo = $"Distributed to {cityNames.ElementAt(r.Next(0, cityNames.Count))}"; + var transType = TransactionType.Distributed; + + if (r.Next(1, 15) == 1) + { + transMemo = "Loss"; + transType = TransactionType.Loss; + } + + transaction = new Transaction + { + TransactionType = transType, + RemovedQuantity = quantityRemoved, + CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved, + Inventory = inventory, + Memo = transMemo, + TransactionDate = transactionDate, + Timestamp = transactionDate + }; + } inventory.Quantity = transaction.CurrentQuantity; diff --git a/InventoryTraker.Web/Controllers/InventoryController.cs b/InventoryTraker.Web/Controllers/InventoryController.cs index 5a59176..36c0f70 100644 --- a/InventoryTraker.Web/Controllers/InventoryController.cs +++ b/InventoryTraker.Web/Controllers/InventoryController.cs @@ -55,6 +55,7 @@ namespace InventoryTraker.Web.Controllers { new Transaction { + TransactionType = TransactionType.Added, AddedQuantity = inventory.Quantity, CurrentQuantity = inventory.Quantity, Memo = "Arrival", @@ -88,6 +89,7 @@ namespace InventoryTraker.Web.Controllers inventory.Transactions.Add(new Transaction { + TransactionType = TransactionType.Distributed, RemovedQuantity = quantityForm.Quantity, CurrentQuantity = inventory.Quantity, Memo = "Distributed to " + form.Destination, diff --git a/InventoryTraker.Web/Core/Transaction.cs b/InventoryTraker.Web/Core/Transaction.cs index 7bc45be..d3551d0 100644 --- a/InventoryTraker.Web/Core/Transaction.cs +++ b/InventoryTraker.Web/Core/Transaction.cs @@ -9,6 +9,8 @@ namespace InventoryTraker.Web.Core public virtual Inventory Inventory { get; set; } + public TransactionType TransactionType { get; set; } + [Required] public int AddedQuantity { get; set; } @@ -26,4 +28,12 @@ namespace InventoryTraker.Web.Core [Required] public DateTime Timestamp { get; set; } } + + public enum TransactionType + { + Added, + Distributed, + Expired, + Loss + } } \ No newline at end of file diff --git a/InventoryTraker.Web/InventoryTraker.Web.csproj b/InventoryTraker.Web/InventoryTraker.Web.csproj index 95bd9fa..91d8024 100644 --- a/InventoryTraker.Web/InventoryTraker.Web.csproj +++ b/InventoryTraker.Web/InventoryTraker.Web.csproj @@ -240,6 +240,7 @@ + diff --git a/InventoryTraker.Web/Models/TransactionViewModel.cs b/InventoryTraker.Web/Models/TransactionViewModel.cs index 500f134..94ec525 100644 --- a/InventoryTraker.Web/Models/TransactionViewModel.cs +++ b/InventoryTraker.Web/Models/TransactionViewModel.cs @@ -17,36 +17,39 @@ namespace InventoryTraker.Web.Models public DateTime ExpirationDate { get; set; } public DateTime AddedDate { get; set; } - [Required] + public string TransactionType { get; set; } + + public int PreviousQuantity { get; set; } + public int AddedQuantity { get; set; } - [Required] public int RemovedQuantity { get; set; } - [Required] public int CurrentQuantity { get; set; } - [Required] public DateTime TransactionDate { get; set; } public string Memo { get; set; } - [Required] public DateTime Timestamp { get; set; } public void CreateMappings(IMapperConfiguration configuration) { configuration.CreateMap() - .ForMember(d => d.Name, + .ForMember(d => d.Name, opt => opt.MapFrom(s => s.Inventory.InventoryType.Name)) - .ForMember(d => d.ExpirationDate, + .ForMember(d => d.ExpirationDate, opt => opt.MapFrom(s => s.Inventory.ExpirationDate)) - .ForMember(d => d.AddedDate, + .ForMember(d => d.AddedDate, opt => opt.MapFrom(s => s.Inventory.AddedDate)) - .ForMember(d => d.UnitsPerCase, + .ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase)) - .ForMember(d => d.ContainerType, - opt => opt.MapFrom(s => s.Inventory.InventoryType.ContainerType)); + .ForMember(d => d.ContainerType, + opt => opt.MapFrom(s => s.Inventory.InventoryType.ContainerType)) + .ForMember(d => d.TransactionType, + opt => opt.MapFrom(s => s.TransactionType.ToString())) + .ForMember(d => d.PreviousQuantity, + opt => opt.MapFrom(s => s.CurrentQuantity - s.AddedQuantity + s.RemovedQuantity)); } } } \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml index 77509fe..c8d357a 100644 --- a/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml +++ b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml @@ -26,7 +26,7 @@ - + @@ -34,14 +34,13 @@
Name
Units per Case
Name
Units per Case
Expiration Date
Available Case Qty Distribute Case Qty
- + {{inventory.name}}
+ {{inventory.unitsPerCase}} / {{inventory.containerType}}
+ Exp: {{inventory.expirationDate | date:'shortDate'}}
{{inventory.quantity}} -
+
' + + '\rExp Date: {{row.entity.expirationDate | date:\'shortDate\'}}' + + '\rAdd Date: {{row.entity.addedDate | date:\'shortDate\'}}">' + ' ' + '{{row.entity.name}}
' }, + { field: 'transactionType', name: 'Type', width: "10%" }, { field: 'memo', cellTooltip: true }, - { field: 'transactionDate', name: 'Transaction Date', cellFilter: "date:MM/dd/yyyy", width: "15%" }, - { field: 'addedQuantity', name: 'Add Qty', width: "10%", enableSorting: false }, - { field: 'removedQuantity', name: 'Remove Qty', width: "10%", enableSorting: false }, + { field: 'transactionDate', name: 'Transaction Date', cellFilter: "date:'shortDate'", width: "15%" }, + { field: 'previousQuantity', name: 'Prev Qty', width: "10%", enableSorting: false }, + { field: 'addedQuantity', name: 'Add Qty', width: "10%", enableSorting: false, cellFilter: "hideZero" }, + { field: 'removedQuantity', name: 'Remove Qty', width: "10%", enableSorting: false, cellFilter: "hideZero" }, { field: 'currentQuantity', name: 'Current Qty', width: "15%", enableSorting: false } ], onRegisterApi: function(gridApi) { diff --git a/InventoryTraker.Web/js/utility/HideZeroFilter.js b/InventoryTraker.Web/js/utility/HideZeroFilter.js new file mode 100644 index 0000000..8ce30a4 --- /dev/null +++ b/InventoryTraker.Web/js/utility/HideZeroFilter.js @@ -0,0 +1,10 @@ +(function () { + window.app.filter('hideZero', hideZero); + + function hideZero() { + return function (input) { + + return input > 0 ? input : ''; + } + } +})(); \ No newline at end of file