Update
This commit is contained in:
parent
0dacb21f33
commit
8276201e83
@ -204,14 +204,14 @@ namespace PSTW_CentralSystem.Controllers.API
|
|||||||
var movementIn = thisMonthMovementIn.FirstOrDefault(m => m.ProductName == item.ProductName);
|
var movementIn = thisMonthMovementIn.FirstOrDefault(m => m.ProductName == item.ProductName);
|
||||||
if (movementIn != null && item.Quantity > 0)
|
if (movementIn != null && item.Quantity > 0)
|
||||||
{
|
{
|
||||||
item.Quantity += movementIn.QuantityIn;
|
item.Quantity -= movementIn.QuantityIn;
|
||||||
item.TotalPrice += (float)movementIn.PriceIn!;
|
item.TotalPrice -= (float)movementIn.PriceIn!;
|
||||||
}
|
}
|
||||||
var movementOut = thisMonthMovementOut.FirstOrDefault(m => m.ProductName == item.ProductName);
|
var movementOut = thisMonthMovementOut.FirstOrDefault(m => m.ProductName == item.ProductName);
|
||||||
if (movementOut != null && item.Quantity > 0)
|
if (movementOut != null && item.Quantity > 0)
|
||||||
{
|
{
|
||||||
item.Quantity -= movementOut.QuantityOut;
|
item.Quantity += movementOut.QuantityOut;
|
||||||
item.TotalPrice -= (float)movementOut.PriceOut!;
|
item.TotalPrice += (float)movementOut.PriceOut!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,29 +220,46 @@ namespace PSTW_CentralSystem.Controllers.API
|
|||||||
.Where(u => u.Department!.DepartmentCode == DeptId)
|
.Where(u => u.Department!.DepartmentCode == DeptId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
var departmentStations = await _centralDbContext.Stations
|
||||||
|
.Include(s => s.StationPic)
|
||||||
|
.Include(s => s.Department)
|
||||||
|
.Where(s => s.Department!.DepartmentCode == DeptId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var departmentStores = await _centralDbContext.Stores
|
||||||
|
.Include(s => s.Company)
|
||||||
|
.Where(s => s.Department!.DepartmentCode == DeptId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var latestItemMovements = await _centralDbContext.ItemMovements
|
var latestItemMovements = await _centralDbContext.ItemMovements
|
||||||
.Include(m => m.Item)
|
.Include(m => m.Item)
|
||||||
.Include(m => m.Item!.Product)
|
.Include(m => m.Item!.Product)
|
||||||
.Include(m => m.NextUser)
|
.Include(m => m.NextUser)
|
||||||
.Where(m => m.ItemId != null && (ToUser > 0 ? m.ToUser != null : m.ToUser > 0) && (ToStation > 0 ? m.ToStation != null : m.ToStation > 0) && (ToStore > 0 ? m.ToStore != null : m.ToStore > 0))
|
.Include(m => m.NextStation)
|
||||||
|
.Include(m => m.NextStore)
|
||||||
.GroupBy(m => m.ItemId)
|
.GroupBy(m => m.ItemId)
|
||||||
.Select(g => g
|
.Select(g => g
|
||||||
.OrderByDescending(m => m.Date)
|
.Where(m => m.Date <= parsedDate)
|
||||||
.ThenByDescending(m => m.Id)
|
.OrderByDescending(m => m.Id)
|
||||||
.FirstOrDefault())
|
.FirstOrDefault())
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
//select latestItemMovements with the Touser is not null
|
||||||
|
var latestUserItemMovements = latestItemMovements.Where(m => m != null && m.ItemId != null && m.ToUser > 0 ).ToList();
|
||||||
|
var latestStationItemMovements = latestItemMovements.Where(m => m != null && m.ItemId != null && m.ToStation > 0).ToList();
|
||||||
|
var latestStoreItemMovements = latestItemMovements.Where(m => m != null && m.ItemId != null && m.ToStore > 0).ToList();
|
||||||
|
|
||||||
var usersItemMovements = departmentUsers
|
var usersItemMovements = departmentUsers
|
||||||
.Select(u => new
|
.Select(u => new
|
||||||
{
|
{
|
||||||
UserId = u.Id,
|
UserId = u.Id,
|
||||||
UserName = u.UserName,
|
UserName = u.UserName,
|
||||||
UserFullName = u.FullName,
|
UserFullName = u.FullName,
|
||||||
Items = latestItemMovements
|
Items = latestUserItemMovements
|
||||||
.Where(m => m.ToUser == u.Id)
|
.Where(m => m != null && m.ToUser == u.Id)
|
||||||
.Select(m => new
|
.Select(m => new
|
||||||
{
|
{
|
||||||
ItemId = m.ItemId,
|
ItemId = m!.ItemId,
|
||||||
ItemName = m.Item!.Product!.ProductName,
|
ItemName = m.Item!.Product!.ProductName,
|
||||||
Quantity = m.Quantity,
|
Quantity = m.Quantity,
|
||||||
ItemPrice = m.Item!.ConvertPrice,
|
ItemPrice = m.Item!.ConvertPrice,
|
||||||
@ -252,14 +269,38 @@ namespace PSTW_CentralSystem.Controllers.API
|
|||||||
UniqueID = m.Item.UniqueID,
|
UniqueID = m.Item.UniqueID,
|
||||||
})
|
})
|
||||||
.ToList(),
|
.ToList(),
|
||||||
TotalItemPrice = latestItemMovements.Where(m => m.ToUser == u.Id).Sum(m => m!.Item!.ConvertPrice * m.Quantity),
|
TotalItemPrice = latestItemMovements.Where(m => m != null && m.ToUser == u.Id).Sum(m => m!.Item!.ConvertPrice * m.Quantity),
|
||||||
|
})
|
||||||
|
.Where(u => u.Items.Count > 0).ToList();
|
||||||
|
|
||||||
|
var stationItemMovements = departmentStations
|
||||||
|
.Select(u => new
|
||||||
|
{
|
||||||
|
StationName = u.StationName,
|
||||||
|
StationPic = u.StationPic?.FullName,
|
||||||
|
Items = latestStationItemMovements
|
||||||
|
.Where(m => m != null && m.ToStation == u.StationId)
|
||||||
|
.Select(m => new
|
||||||
|
{
|
||||||
|
ItemId = m!.ItemId,
|
||||||
|
ItemName = m.Item!.Product!.ProductName,
|
||||||
|
Quantity = m.Quantity,
|
||||||
|
ItemPrice = m.Item!.ConvertPrice,
|
||||||
|
PO = m.Item!.PONo,
|
||||||
|
DO = m.Item!.DONo,
|
||||||
|
SerialNumber = m.Item.SerialNumber,
|
||||||
|
UniqueID = m.Item.UniqueID,
|
||||||
|
})
|
||||||
|
.ToList(),
|
||||||
|
TotalItemPrice = latestItemMovements.Where(m => m != null && m.ToStation == u.StationId).Sum(m => m!.Item!.ConvertPrice * m.Quantity),
|
||||||
})
|
})
|
||||||
.Where(u => u.Items.Count > 0).ToList();
|
.Where(u => u.Items.Count > 0).ToList();
|
||||||
|
|
||||||
var report = new
|
var report = new
|
||||||
{
|
{
|
||||||
allProductInStore = currentProductBalance,
|
allProductInStore = currentProductBalance,
|
||||||
userItemBalance = usersItemMovements
|
userItemBalance = usersItemMovements,
|
||||||
|
stationItemBalance = stationItemMovements,
|
||||||
};
|
};
|
||||||
|
|
||||||
return Json(report);
|
return Json(report);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user