This commit is contained in:
MOHD ARIFF 2026-02-13 16:05:12 +08:00
parent 58b06df1c1
commit b8540d6f0b

View File

@ -33,6 +33,14 @@ namespace PSTW_CentralSystem.Controllers.API
public int Quantity { get; set; } public int Quantity { get; set; }
} }
public class ReportQuery
{
string? FormDate { get; set; }
string? DeptId { get; set; }
int ToUser { get; set; }
int ToStation { get; set; }
int ToStore { get; set; }
}
#region ItemReport #region ItemReport
[HttpPost("GetInventoryReport/{deptId}")] [HttpPost("GetInventoryReport/{deptId}")]
@ -127,7 +135,7 @@ namespace PSTW_CentralSystem.Controllers.API
#region Monthly Report #region Monthly Report
[HttpPost("GetMonthlyReport")] [HttpPost("GetMonthlyReport")]
public async Task<IActionResult> GetMonthlyReport([FromBody] string FormDate = "2026/1/31", string DeptId = "PA") public async Task<IActionResult> GetMonthlyReport([FromBody] string FormDate = "2026/1/31", string DeptId = "PA", int ToUser = 1, int ToStation = 0, int ToStore = 0)
{ {
try try
{ {
@ -199,10 +207,12 @@ namespace PSTW_CentralSystem.Controllers.API
.Include(u => u.Department) .Include(u => u.Department)
.Where(u => u.Department!.DepartmentCode == DeptId) .Where(u => u.Department!.DepartmentCode == DeptId)
.ToListAsync(); .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.NextUser) .Include(m => m.NextUser)
.Where(m => m.ItemId != null && m.ToUser != null) .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))
.GroupBy(m => m.ItemId) .GroupBy(m => m.ItemId)
.Select(g => g .Select(g => g
.OrderByDescending(m => m.Date) .OrderByDescending(m => m.Date)
@ -210,7 +220,31 @@ namespace PSTW_CentralSystem.Controllers.API
.FirstOrDefault()) .FirstOrDefault())
.ToListAsync(); .ToListAsync();
return Json(currentProductBalance); var usersItemMovements = departmentUsers
.Select(u => new
{
UserId = u.Id,
UserName = u.UserName,
UserFullName = u.FullName,
Items = latestItemMovements
.Where(m => m.ToUser == u.Id)
.Select(m => new
{
ItemId = m.ItemId,
ItemName = m.Item!.Product!.ProductName,
Quantity = m.Quantity,
})
.ToList()
})
.Where(u => u.Items.Count > 0).ToList();
var report = new
{
allProductInStore = currentProductBalance,
userItemBalance = usersItemMovements
};
return Json(report);
} }
catch (Exception ex) catch (Exception ex)
{ {