Add transaction list
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using Heroic.AutoMapper;
|
||||
using InventoryTraker.Web.Controllers;
|
||||
using InventoryTraker.Web.Core;
|
||||
using InventoryTraker.Web.Models;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace InventoryTraker.Web
|
||||
{
|
||||
var r = new Random(1);
|
||||
var inventoryTypes = context.InventoryTypes.ToList();
|
||||
var cityNames = new List<string> {"Maryville", "Wartburg", "Clinton", "Oak Ridge", "Alcoa", "Jellico"};
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
@@ -109,12 +110,14 @@ namespace InventoryTraker.Web
|
||||
if (quantityRemoved > previousTransaction.CurrentQuantity)
|
||||
quantityRemoved = previousTransaction.CurrentQuantity;
|
||||
|
||||
var destCity = cityNames.ElementAt(r.Next(0, cityNames.Count));
|
||||
|
||||
var transaction = new Transaction
|
||||
{
|
||||
RemovedQuantity = quantityRemoved,
|
||||
CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved,
|
||||
Inventory = inventory,
|
||||
Memo = "Distributed",
|
||||
Memo = $"Distributed to {destCity}",
|
||||
TransactionDate = transactionDate,
|
||||
Timestamp = transactionDate
|
||||
};
|
||||
|
||||
@@ -34,5 +34,19 @@ namespace InventoryTraker.Web.Controllers
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,15 @@ namespace InventoryTraker.Web.Helpers
|
||||
|
||||
public void Add<TProp>(Expression<Func<T, TProp>> property,
|
||||
string columnHeader = null,
|
||||
string cellFilter = null)
|
||||
string cellFilter = null,
|
||||
bool cellToolTipContents = false)
|
||||
{
|
||||
_tag._columns.Add(new ColumnDefinition
|
||||
{
|
||||
Field = property.ToCamelCaseName(),
|
||||
Name = columnHeader,
|
||||
CellFilter = cellFilter
|
||||
CellFilter = cellFilter,
|
||||
CellToolTip = cellToolTipContents
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -39,6 +41,8 @@ namespace InventoryTraker.Web.Helpers
|
||||
public string Name { get; set; }
|
||||
|
||||
public string CellFilter { get; set; }
|
||||
|
||||
public bool CellToolTip { get; set; }
|
||||
}
|
||||
|
||||
private readonly List<ColumnDefinition> _columns = new List<ColumnDefinition>();
|
||||
|
||||
@@ -232,6 +232,7 @@
|
||||
<Content Include="js\inventory\InventoryEditDirective.js" />
|
||||
<Content Include="js\inventory\InventoryDistributeDirective.js" />
|
||||
<Content Include="js\profile\EditProfileController.js" />
|
||||
<Content Include="js\transaction\TransactionController.js" />
|
||||
<Content Include="js\transaction\transactionSvc.js" />
|
||||
<Content Include="js\utility\ArrayExtensions.js" />
|
||||
<Content Include="js\utility\FormGroupValidationDirective.js" />
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace InventoryTraker.Web.Models
|
||||
public string Name { get; set; }
|
||||
public int UnitsPerCase { get; set; }
|
||||
public string ContainerType { get; set; }
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
public DateTime AddedDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public int AddedQuantity { get; set; }
|
||||
@@ -37,6 +39,10 @@ namespace InventoryTraker.Web.Models
|
||||
configuration.CreateMap<Transaction, TransactionViewModel>()
|
||||
.ForMember(d => d.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,
|
||||
opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase))
|
||||
.ForMember(d => d.ContainerType,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
ViewBag.Title = "Inventory";
|
||||
}
|
||||
|
||||
<div ng-controller="InventoryListController as vm">
|
||||
<div ng-controller="TransactionController as vm">
|
||||
<h1 class="page-header">
|
||||
Transactions
|
||||
</h1>
|
||||
@@ -15,15 +15,6 @@
|
||||
<a class="btn btn-default" href="" ng-click="vm.distribute()"><i class="fa fa-share-square"></i> Distribute</a>*@
|
||||
</div>
|
||||
|
||||
@(Html.Angular().GridFor<TransactionController>(c => c.All())
|
||||
.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 class="grid-fullpage" ui-grid-pagination ui-grid="vm.gridOptions"></div>
|
||||
|
||||
</div>
|
||||
@@ -97,6 +97,10 @@ textarea {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.grid-fullpage {
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
/*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback {
|
||||
top: 26px;
|
||||
}*/
|
||||
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
'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'];
|
||||
function transactionSvc($http) {
|
||||
var transactions = [];
|
||||
|
||||
loadTransactions();
|
||||
|
||||
var svc = {
|
||||
add: add,
|
||||
update: update,
|
||||
transactions: transactions,
|
||||
getTransactions: getTransactions,
|
||||
getTransaction: getTransaction
|
||||
};
|
||||
|
||||
return svc;
|
||||
|
||||
function loadTransactions() {
|
||||
$http.post('/Transaction/All')
|
||||
.success(function(data) {
|
||||
angular.copy(data, transactions);
|
||||
function getTransactions(pageNumber, pageSize) {
|
||||
var url = '/Transaction/GetTransactions';
|
||||
return $http.post(url, {pageNumber: pageNumber, pageSize: pageSize})
|
||||
.then(function(data) {
|
||||
return data.data;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user