Compare commits

..

2 Commits

View File

@ -155,7 +155,20 @@ namespace PSTW_CentralSystem.Controllers.API
} }
} }
DateTime parsedDate = DateTime.Parse(FormDate); DateTime parsedDate = DateTime.Parse(FormDate);
var thisMonthMovements = await _centralDbContext.ItemMovements
var thisMonthMovementIn = await _centralDbContext.ItemMovements
.Include(m => m.Item)
.Include(m => m.Item!.Product)
.Include(m => m.Item!.Department)
.Where(m => m.Date.Month == parsedDate.Month && m.Date.Year == parsedDate.Year && m.Item!.Department!.DepartmentCode == DeptId && (m.Action == "Stock In" || m.Action == "Register"))
.Select(m => new
{
ProductName = m.Item!.Product!.ProductName,
QuantityOut = m.Quantity??0,
})
.ToListAsync();
var thisMonthMovementOut = await _centralDbContext.ItemMovements
.Include(m => m.Item) .Include(m => m.Item)
.Include(m => m.Item!.Product) .Include(m => m.Item!.Product)
.Include(m => m.Item!.Department) .Include(m => m.Item!.Department)
@ -166,13 +179,19 @@ namespace PSTW_CentralSystem.Controllers.API
QuantityOut = m.Quantity??0, QuantityOut = m.Quantity??0,
}) })
.ToListAsync(); .ToListAsync();
//value from currentProductBalance - value from thisMonthMovements
//value from currentProductBalance - value from thisMonthMovementOut + value from thisMonthMovementIn
foreach (var item in currentProductBalance) foreach (var item in currentProductBalance)
{ {
var movement = thisMonthMovements.FirstOrDefault(m => m.ProductName == item.ProductName); var movementIn = thisMonthMovementIn.FirstOrDefault(m => m.ProductName == item.ProductName);
if (movement != null && item.Quantity > 0) if (movementIn != null && item.Quantity > 0)
{ {
item.Quantity -= movement.QuantityOut; item.Quantity += movementIn.QuantityOut;
}
var movementOut = thisMonthMovementOut.FirstOrDefault(m => m.ProductName == item.ProductName);
if (movementOut != null && item.Quantity > 0)
{
item.Quantity -= movementOut.QuantityOut;
} }
} }
return Json(currentProductBalance); return Json(currentProductBalance);