Add transaction list

This commit is contained in:
2016-08-29 14:43:26 -04:00
parent b57c5ae41c
commit 016f031664
11 changed files with 124 additions and 26 deletions
@@ -1,7 +1,6 @@
using System; using System;
using AutoMapper; using AutoMapper;
using Heroic.AutoMapper; using Heroic.AutoMapper;
using InventoryTraker.Web.Controllers;
using InventoryTraker.Web.Core; using InventoryTraker.Web.Core;
using InventoryTraker.Web.Models; using InventoryTraker.Web.Models;
using NUnit.Framework; using NUnit.Framework;
+4 -1
View File
@@ -75,6 +75,7 @@ namespace InventoryTraker.Web
{ {
var r = new Random(1); var r = new Random(1);
var inventoryTypes = context.InventoryTypes.ToList(); var inventoryTypes = context.InventoryTypes.ToList();
var cityNames = new List<string> {"Maryville", "Wartburg", "Clinton", "Oak Ridge", "Alcoa", "Jellico"};
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@@ -109,12 +110,14 @@ namespace InventoryTraker.Web
if (quantityRemoved > previousTransaction.CurrentQuantity) if (quantityRemoved > previousTransaction.CurrentQuantity)
quantityRemoved = previousTransaction.CurrentQuantity; quantityRemoved = previousTransaction.CurrentQuantity;
var destCity = cityNames.ElementAt(r.Next(0, cityNames.Count));
var transaction = new Transaction var transaction = new Transaction
{ {
RemovedQuantity = quantityRemoved, RemovedQuantity = quantityRemoved,
CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved, CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved,
Inventory = inventory, Inventory = inventory,
Memo = "Distributed", Memo = $"Distributed to {destCity}",
TransactionDate = transactionDate, TransactionDate = transactionDate,
Timestamp = transactionDate Timestamp = transactionDate
}; };
@@ -34,5 +34,19 @@ namespace InventoryTraker.Web.Controllers
return BetterJson(viewModels); return BetterJson(viewModels);
} }
public JsonResult GetTransactions(int pageNumber, int pageSize)
{
var viewModels =
_context.Transactions
.OrderByDescending(t => t.Timestamp)
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ProjectTo<TransactionViewModel>()
.ToArray();
var count = _context.Transactions.Count();
return BetterJson(new {totalItems = count, transactions = viewModels});
}
} }
} }
+6 -2
View File
@@ -21,13 +21,15 @@ namespace InventoryTraker.Web.Helpers
public void Add<TProp>(Expression<Func<T, TProp>> property, public void Add<TProp>(Expression<Func<T, TProp>> property,
string columnHeader = null, string columnHeader = null,
string cellFilter = null) string cellFilter = null,
bool cellToolTipContents = false)
{ {
_tag._columns.Add(new ColumnDefinition _tag._columns.Add(new ColumnDefinition
{ {
Field = property.ToCamelCaseName(), Field = property.ToCamelCaseName(),
Name = columnHeader, Name = columnHeader,
CellFilter = cellFilter CellFilter = cellFilter,
CellToolTip = cellToolTipContents
}); });
} }
} }
@@ -39,6 +41,8 @@ namespace InventoryTraker.Web.Helpers
public string Name { get; set; } public string Name { get; set; }
public string CellFilter { get; set; } public string CellFilter { get; set; }
public bool CellToolTip { get; set; }
} }
private readonly List<ColumnDefinition> _columns = new List<ColumnDefinition>(); private readonly List<ColumnDefinition> _columns = new List<ColumnDefinition>();
@@ -232,6 +232,7 @@
<Content Include="js\inventory\InventoryEditDirective.js" /> <Content Include="js\inventory\InventoryEditDirective.js" />
<Content Include="js\inventory\InventoryDistributeDirective.js" /> <Content Include="js\inventory\InventoryDistributeDirective.js" />
<Content Include="js\profile\EditProfileController.js" /> <Content Include="js\profile\EditProfileController.js" />
<Content Include="js\transaction\TransactionController.js" />
<Content Include="js\transaction\transactionSvc.js" /> <Content Include="js\transaction\transactionSvc.js" />
<Content Include="js\utility\ArrayExtensions.js" /> <Content Include="js\utility\ArrayExtensions.js" />
<Content Include="js\utility\FormGroupValidationDirective.js" /> <Content Include="js\utility\FormGroupValidationDirective.js" />
@@ -14,6 +14,8 @@ namespace InventoryTraker.Web.Models
public string Name { get; set; } public string Name { get; set; }
public int UnitsPerCase { get; set; } public int UnitsPerCase { get; set; }
public string ContainerType { get; set; } public string ContainerType { get; set; }
public DateTime ExpirationDate { get; set; }
public DateTime AddedDate { get; set; }
[Required] [Required]
public int AddedQuantity { get; set; } public int AddedQuantity { get; set; }
@@ -37,6 +39,10 @@ namespace InventoryTraker.Web.Models
configuration.CreateMap<Transaction, TransactionViewModel>() configuration.CreateMap<Transaction, TransactionViewModel>()
.ForMember(d => d.Name, .ForMember(d => d.Name,
opt => opt.MapFrom(s => s.Inventory.InventoryType.Name)) opt => opt.MapFrom(s => s.Inventory.InventoryType.Name))
.ForMember(d => d.ExpirationDate,
opt => opt.MapFrom(s => s.Inventory.ExpirationDate))
.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)) opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase))
.ForMember(d => d.ContainerType, .ForMember(d => d.ContainerType,
@@ -6,7 +6,7 @@
ViewBag.Title = "Inventory"; ViewBag.Title = "Inventory";
} }
<div ng-controller="InventoryListController as vm"> <div ng-controller="TransactionController as vm">
<h1 class="page-header"> <h1 class="page-header">
Transactions Transactions
</h1> </h1>
@@ -15,15 +15,6 @@
<a class="btn btn-default" href="" ng-click="vm.distribute()"><i class="fa fa-share-square"></i> Distribute</a>*@ <a class="btn btn-default" href="" ng-click="vm.distribute()"><i class="fa fa-share-square"></i> Distribute</a>*@
</div> </div>
@(Html.Angular().GridFor<TransactionController>(c => c.All()) <div class="grid-fullpage" ui-grid-pagination ui-grid="vm.gridOptions"></div>
.Title("Transactions")
.Columns<TransactionViewModel>(config =>
{
config.Add(x => x.Name);
config.Add(x => x.Memo);
config.Add(x => x.TransactionDate, "Transaction Date", "date: 'MM/dd/yyyy'");
config.Add(x => x.AddedQuantity, "Add Qty");
config.Add(x => x.RemovedQuantity, "Remove Qty");
config.Add(x => x.CurrentQuantity);
}))
</div> </div>
+4
View File
@@ -97,6 +97,10 @@ textarea {
border-radius: 50%; border-radius: 50%;
} }
.grid-fullpage {
height: 70vh;
}
/*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback { /*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback {
top: 26px; top: 26px;
}*/ }*/
+1 -1
View File
@@ -1,5 +1,5 @@
(function() { (function() {
'use strict'; 'use strict';
window.app = angular.module('InventoryTraker', ['ngAnimate', 'ui.bootstrap', 'ui.grid', 'mgcrea.ngStrap']); window.app = angular.module('InventoryTraker', ['ngAnimate', 'ui.bootstrap', 'ui.grid', 'ui.grid.pagination', 'mgcrea.ngStrap']);
})(); })();
@@ -0,0 +1,79 @@
(function() {
'use strict';
window.app.controller('TransactionController', TransactionController);
TransactionController.$inject = ['$scope', '$uibModal', 'transactionSvc', 'uiGridConstants'];
function TransactionController($scope, $uibModal, transactionSvc, uiGridConstants) {
var vm = this;
var paginationOptions = {
pageNumber: 1,
pageSize: 20,
sort: null
};
vm.gridOptions = {
enablePaginationControls: true,
paginationPageSize: paginationOptions.pageSize,
paginationPageSizes: [20,50,100],
useExternalPagination: true,
enableSorting: false,
columnDefs: [
{
field: 'name',
cellTooltip: function(row) {
return row.entity.name + "\r" + row.entity.unitsPerCase + " / " + row.entity.containerType;
},
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}}">' +
'<a href="#">{{row.entity.name}}</a></div>'
},
{ 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: 'currentQuantity', name: 'Current Qty', width: "15%", enableSorting: false }
],
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;
paginationOptions.pageSize = pageSize;
updateData();
});
}
};
var updateData = function () {
transactionSvc
.getTransactions(paginationOptions.pageNumber, paginationOptions.pageSize)
.then(function(data) {
vm.gridOptions.totalItems = data.totalItems;
vm.gridOptions.data = data.transactions;
});
};
updateData();
function del() {
$uibModal.open({
template: '<inventory-distribute />',
backdrop: 'static'
});
}
}
})();
@@ -3,23 +3,20 @@
transactionSvc.$inject = ['$http']; transactionSvc.$inject = ['$http'];
function transactionSvc($http) { function transactionSvc($http) {
var transactions = [];
loadTransactions();
var svc = { var svc = {
add: add,
update: update, update: update,
transactions: transactions, getTransactions: getTransactions,
getTransaction: getTransaction getTransaction: getTransaction
}; };
return svc; return svc;
function loadTransactions() { function getTransactions(pageNumber, pageSize) {
$http.post('/Transaction/All') var url = '/Transaction/GetTransactions';
.success(function(data) { return $http.post(url, {pageNumber: pageNumber, pageSize: pageSize})
angular.copy(data, transactions); .then(function(data) {
return data.data;
}); });
} }