Update
This commit is contained in:
parent
0a9417aa8a
commit
74119f7222
@ -118,6 +118,7 @@
|
||||
mounted() {
|
||||
this.fetchUser();
|
||||
this.fetchProductList();
|
||||
this.fetchCurrentReport();
|
||||
this.fetchDepartmentsCompaniesList();
|
||||
},
|
||||
watch: {
|
||||
@ -130,6 +131,24 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async fetchCurrentReport(){
|
||||
try {
|
||||
const response = await fetch(`/ReportingAPI/GetMonthlyReport/`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
}
|
||||
else {
|
||||
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
},
|
||||
|
||||
async fetchUser() {
|
||||
try {
|
||||
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using PSTW_CentralSystem.Areas.Inventory.Models;
|
||||
using PSTW_CentralSystem.DBContext;
|
||||
using PSTW_CentralSystem.Models;
|
||||
@ -26,6 +27,12 @@ namespace PSTW_CentralSystem.Controllers.API
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public class ProductReport
|
||||
{
|
||||
public string? ProductName { get; set; } = default!;
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
|
||||
#region ItemReport
|
||||
|
||||
[HttpPost("GetInventoryReport/{deptId}")]
|
||||
@ -118,6 +125,65 @@ namespace PSTW_CentralSystem.Controllers.API
|
||||
|
||||
#endregion
|
||||
|
||||
#region Monthly Report
|
||||
[HttpPost("GetMonthlyReport")]
|
||||
public async Task<IActionResult> GetMonthlyReport([FromBody] string FormDate = "2026/1/31", string DeptId = "PA")
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentProductBalance = new List<ProductReport>();
|
||||
var result = await _centralDbContext.Products
|
||||
.Select(p => new { p.ProductName, p.QuantityJSON })
|
||||
.Where(p => p.QuantityJSON != null)
|
||||
.ToListAsync();
|
||||
var quantityJsonDict = new Dictionary<string, Dictionary<string,int>>();
|
||||
foreach (var item in result)
|
||||
{
|
||||
quantityJsonDict[item.ProductName] = JsonConvert.DeserializeObject<Dictionary<string, int>>(item.QuantityJSON)!;
|
||||
if (!quantityJsonDict.TryGetValue(item.ProductName, out var deptDict))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (deptDict.TryGetValue(DeptId, out var quantity))
|
||||
{
|
||||
currentProductBalance.Add(new ProductReport
|
||||
{
|
||||
ProductName = item.ProductName,
|
||||
Quantity = quantity
|
||||
});
|
||||
}
|
||||
}
|
||||
DateTime parsedDate = DateTime.Parse(FormDate);
|
||||
var thisMonthMovements = 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 Out" || m.Action == "Assign"))
|
||||
.Select(m => new
|
||||
{
|
||||
ProductName = m.Item!.Product!.ProductName,
|
||||
QuantityOut = m.Quantity??0,
|
||||
})
|
||||
.ToListAsync();
|
||||
//value from currentProductBalance - value from thisMonthMovements
|
||||
foreach (var item in currentProductBalance)
|
||||
{
|
||||
var movement = thisMonthMovements.FirstOrDefault(m => m.ProductName == item.ProductName);
|
||||
if (movement != null && item.Quantity > 0)
|
||||
{
|
||||
item.Quantity -= movement.QuantityOut;
|
||||
}
|
||||
}
|
||||
return Json(currentProductBalance);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Report Inventory ii
|
||||
[HttpPost("GetInventoryReport")]
|
||||
public async Task<IActionResult> GetInventoryReport([FromBody] ReportFilterDTO filter)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user