Add transaction type

This commit is contained in:
2016-08-31 12:08:22 -04:00
parent c86d7fb1ed
commit f5e438e994
8 changed files with 95 additions and 38 deletions
+46 -16
View File
@@ -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;
@@ -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,
+10
View File
@@ -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
}
}
@@ -240,6 +240,7 @@
<Content Include="js\transaction\transactionSvc.js" />
<Content Include="js\utility\ArrayExtensions.js" />
<Content Include="js\utility\FormGroupValidationDirective.js" />
<Content Include="js\utility\HideZeroFilter.js" />
<Content Include="js\utility\InputValidationIconsDirective.js" />
<Content Include="js\utility\MvcGridDirective.js" />
<Content Include="js\utility\ParseDateFilter.js" />
@@ -17,21 +17,20 @@ 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)
@@ -46,7 +45,11 @@ namespace InventoryTraker.Web.Models
.ForMember(d => d.UnitsPerCase,
opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase))
.ForMember(d => d.ContainerType,
opt => opt.MapFrom(s => s.Inventory.InventoryType.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));
}
}
}
@@ -26,7 +26,7 @@
<table class="table" ng-class="vm.getValidationClass()">
<thead>
<tr>
<th>Name<br />Units per Case</th>
<th>Name<br/>Units per Case<br/>Expiration Date</th>
<th>Available Case Qty</th>
<th>Distribute Case Qty</th>
</tr>
@@ -34,14 +34,13 @@
<tbody>
<tr ng-repeat="inventory in vm.quantities" inventory="inventory">
<td>
<label class="control-label" for="DistributeQuantity{{inventory.name}}">
{{inventory.name}}<br />
{{inventory.unitsPerCase}} / {{inventory.containerType}}
</label>
{{inventory.name}}<br />
{{inventory.unitsPerCase}} / {{inventory.containerType}}<br/>
Exp: {{inventory.expirationDate | date:'shortDate'}}
</td>
<td>{{inventory.quantity}}</td>
<td>
<div class="form-group" form-group-validation="DistributeQuantity{{inventory.name}}">
<div class="form-group col-sm-7" form-group-validation="DistributeQuantity{{inventory.name}}">
<input name="DistributeQuantity{{inventory.name}}" type="number"
class="form-control"
ng-model="inventory.distributeQuantity"
@@ -28,15 +28,17 @@
cellTemplate: '<div class="ui-grid-cell-contents" ' +
'title="{{row.entity.name}}' +
'\r{{row.entity.unitsPerCase}} / {{row.entity.containerType}}' +
'\rExp Date: {{row.entity.expirationDate | date:shortDate}}' +
'\rAdd Date: {{row.entity.addedDate | date:shortDate}}">' +
'\rExp Date: {{row.entity.expirationDate | date:\'shortDate\'}}' +
'\rAdd Date: {{row.entity.addedDate | date:\'shortDate\'}}">' +
'<a href="" ng-click="vm.edit()"><i class="fa fa-edit"></i></a> ' +
'{{row.entity.name}}</div>'
},
{ 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) {
@@ -0,0 +1,10 @@
(function () {
window.app.filter('hideZero', hideZero);
function hideZero() {
return function (input) {
return input > 0 ? input : '';
}
}
})();