diff --git a/Controllers/API/ReportingAPI.cs b/Controllers/API/ReportingAPI.cs index c88a48c..bcfa336 100644 --- a/Controllers/API/ReportingAPI.cs +++ b/Controllers/API/ReportingAPI.cs @@ -33,6 +33,14 @@ namespace PSTW_CentralSystem.Controllers.API 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 [HttpPost("GetInventoryReport/{deptId}")] @@ -127,7 +135,7 @@ namespace PSTW_CentralSystem.Controllers.API #region Monthly Report [HttpPost("GetMonthlyReport")] - public async Task GetMonthlyReport([FromBody] string FormDate = "2026/1/31", string DeptId = "PA") + public async Task GetMonthlyReport([FromBody] string FormDate = "2026/1/31", string DeptId = "PA", int ToUser = 1, int ToStation = 0, int ToStore = 0) { try { @@ -199,10 +207,12 @@ namespace PSTW_CentralSystem.Controllers.API .Include(u => u.Department) .Where(u => u.Department!.DepartmentCode == DeptId) .ToListAsync(); + var latestItemMovements = await _centralDbContext.ItemMovements - .Include(m => m.Item) + //.Include(m => m.Item) + //.Include(m => m.Item!.Product) .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) .Select(g => g .OrderByDescending(m => m.Date) @@ -210,7 +220,31 @@ namespace PSTW_CentralSystem.Controllers.API .FirstOrDefault()) .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) {