Compare commits

...

2 Commits

Author SHA1 Message Date
d9e67e6139 item request api 2025-02-20 07:42:06 +08:00
5f4e8c6c22 initial itemmovement and initial itemrequest 2025-02-19 14:08:16 +08:00
8 changed files with 2695 additions and 5 deletions

View File

@ -17,6 +17,16 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers.Admin
return View();
}
public IActionResult ItemMovement()
{
return View();
}
public IActionResult ItemRequest()
{
return View();
}
public IActionResult ProductRegistration()
{
return View();

View File

@ -7,10 +7,10 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
{
[Key]
public int requestId { get; set; }
public int DepartmentId { get; set; }
[ForeignKey("DepartmentId")]
public virtual ItemModel? Department { get; set; }
[ForeignKey("ItemID")]
//public int DepartmentId { get; set; }
//[ForeignKey("DepartmentId")]
//public virtual ItemModel? Department { get; set; }
//[ForeignKey("ItemID")]
public string? remark { get; set; }
public string? status { get; set; }
public DateTime requestDate { get; set; }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -48,4 +48,30 @@
</a>
</div>
</div>
<div class="col-6 col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ItemMovement">
<div class="box bg-success text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-checkbox-multiple-blank-circle"></i>
</h1>
<h6 class="text-white">Item Movement</h6>
</div>
</a>
</div>
</div>
<div class="col-6 col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ItemRequest">
<div class="box bg-success text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-checkbox-multiple-blank-circle"></i>
</h1>
<h6 class="text-white">Item Request</h6>
</div>
</a>
</div>
</div>
</div>

View File

@ -518,6 +518,160 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
#endregion Item
#region ItemMovement
[HttpPost("ItemMovementList")]
public async Task<IActionResult> ItemMovementList()
{
var itemMovementList = await _centralDbContext.ItemMovements.ToListAsync();
Console.WriteLine(Json(itemMovementList));
return Json(itemMovementList);
//try
//{
// var user = await _userManager.GetUserAsync(User);
// if (user == null)
// {
// return BadRequest("User not found");
// }
// else
// {
// user.departmentId = user.departmentId != null ? user.departmentId : 0;
// }
// var userRole = await _userManager.GetRolesAsync(user);
// var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance");
// List<ItemModel> itemList = new List<ItemModel>();
// // Get the item list
// if (isAdmin)
// {
// itemList = await _centralDbContext.Items
// .AsNoTracking()
// .Include("CreatedBy")
// .Include("Department")
// .Include("Product")
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromStore)
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromStation)
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromUser)
// .ToListAsync();
// }
// else
// {
// itemList = await _centralDbContext.Items
// .AsNoTracking()
// .Include("CreatedBy")
// .Include("Department")
// .Include("Product")
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromStore)
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromStation)
// .Include(i => i.Movement)
// .ThenInclude(m => m!.FromUser)
// .Where(i => i.DepartmentId == user.departmentId)
// .ToListAsync();
// }
// // Get the departments list (DepartmentId references Departments)
// var departments = await _centralDbContext.Departments.ToListAsync();
// // Now join items with users and departments manually
// var itemListWithDetails = itemList.Select(item => new
// {
// item.ItemID,
// item.UniqueID,
// item.CompanyId,
// item.DepartmentId,
// item.ProductId,
// item.SerialNumber,
// item.Quantity,
// item.Supplier,
// PurchaseDate = item.PurchaseDate.ToString("dd/MM/yyyy"),
// item.PONo,
// item.Currency,
// item.DefaultPrice,
// item.CurrencyRate,
// item.ConvertPrice,
// item.DODate,
// item.Warranty,
// item.PartNumber,
// EndWDate = item.EndWDate.ToString("dd/MM/yyyy"),
// InvoiceDate = item.InvoiceDate?.ToString("dd/MM/yyyy"),
// item.Department?.DepartmentName,
// CreatedBy = item.CreatedBy!.UserName,
// item.Product!.ProductName,
// item.Product!.ProductShortName,
// item.Product!.Category,
// //CurrentUser = item.Movement?.FromUser?.UserName,
// CurrentUser = item.Movement?.FromUser?.UserName,
// CurrentStore = item.Movement?.FromStore?.StoreName,
// CurrentStation = item.Movement?.FromStation?.StationName,
// QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.UniqueID}" // Generate QR String
// }).ToList();
// return Json(itemListWithDetails);
//}
//catch (Exception ex)
//{
// return BadRequest(ex.Message);
//}
}
#endregion ItemMovement
#region ItemRequest
[HttpGet("ItemRequestList")]
public async Task<IActionResult> ItemRequestList()
{
var itemRequestList = await _centralDbContext.Request.ToListAsync();
return Json(itemRequestList);
}
[HttpPost("ApproveRequest/{id}")]
public async Task<IActionResult> ApproveRequest(int id)
{
var Request = await _centralDbContext.Request.FindAsync(id);
if (Request == null)
{
return NotFound(new { success = false, message = "Request not found" });
}
Request.status = "Approved";
Request.approvalDate = DateTime.UtcNow;
_centralDbContext.SaveChanges();
return Ok(new { success = true, message = "Request Approved Successfully", data = Request });
}
[HttpPost("RejectRequest/{id}")]
public async Task<IActionResult> RejectRequest(int id)
{
var Request = await _centralDbContext.Request.FindAsync(id);
if (Request == null)
{
return NotFound(new { success = false, message = "Request not found" });
}
Request.status = "Rejected";
Request.approvalDate = DateTime.UtcNow;
_centralDbContext.SaveChanges();
return Ok(new { success = true, message="Request Rejected Successfully", data=Request });
}
#endregion ItemRequest
#region ItemReport
[HttpPost("GetInventoryReport/{deptId}")]
@ -655,5 +809,29 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
return Ok(new { success = true, message = "Station deleted successfully" });
}
#endregion Station
#region Store
[HttpPost("StoreList")]
public async Task<IActionResult> StoreList()
{
var storeList = await _centralDbContext.Stores.ToListAsync();
return Json(storeList);
}
#endregion Store
#region User
[HttpPost("UserList")]
public async Task<IActionResult> UserList()
{
var userList = await _centralDbContext.Users.ToListAsync();
return Json(userList);
}
#endregion User
}
}

View File

@ -91,7 +91,7 @@ namespace PSTW_CentralSystem.DBContext
public DbSet<DepartmentModel> Departments { get; set; }
public DbSet<ManufacturerModel> Manufacturers { get; set; }
public DbSet<ItemModel> Items { get; set; }
public DbSet<RequestModel> Requests { get; set; }
public DbSet<RequestModel> Request { get; set; }
public DbSet<ProductModel> Products { get; set; }
public DbSet<SupplierModel> Suppliers { get; set; }
public DbSet<InventoryMasterModel> InventoryMasters { get; set; }

View File

@ -145,6 +145,12 @@
</div>
</div>
</div>
<div>
<p v-if="isAdmin">Welcome, Admin! You have full access.</p>
<p v-else-if="userRole === 'user'">Welcome, User! You have limited access.</p>
<p v-else>Guest View: Please log in.</p>
</div>
</div>
</div>
</div>
@ -187,11 +193,13 @@
return {
thisItem: null,
itemId: '@itemId',
isAdmin: false,
}
},
mounted() {
// Fetch companies, depts, and products from the API
this.fetchItem();
this.fetchUser();
},
methods: {
async fetchItem() {
@ -210,6 +218,35 @@
console.error('Error fetching item information:', error);
}
},
async fetchUser() {
try {
// var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance");
const adminRoles = ["SystemAdmin", "SuperAdmin", "Finance"];
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
method: 'POST',
});
if (response.ok) {
const data = await response.json();
this.currentUser = data?.userInfo || null;
const companyDeptData = await this.currentUser.department;
this.currentUserCompanyDept = companyDeptData;
this.selectedCompany = companyDeptData?.companyId || "";
this.selectedDepartment = companyDeptData?.departmentId || "";
this.isAdmin = adminRoles.some(role => this.currentUser.role.includes(role));
}
else {
console.error(`Failed to fetch user: ${response.statusText}`);
}
}
catch (error) {
console.error('There was a problem with the fetch operation:', error);
}
},
}
});
</script>