From 85fce16dbef7b7a899ded79b5d2eb48800e65838 Mon Sep 17 00:00:00 2001 From: ameerulrasyid Date: Thu, 20 Feb 2025 16:33:09 +0800 Subject: [PATCH] item movement admin --- .../Admin/InventoryMasterController.cs | 4 + .../Controllers/ItemMovementController.cs | 5 + Areas/Inventory/Models/ItemMovementModel.cs | 4 +- .../Views/InventoryMaster/ItemMovement.cshtml | 420 ++---------------- .../Inventory/Views/_InventoryPartial.cshtml | 13 + Controllers/API/Inventory/InvMainAPI.cs | 12 +- Views/Shared/_Layout.cshtml | 2 +- 7 files changed, 72 insertions(+), 388 deletions(-) diff --git a/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs b/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs index e95a2e1..4fa54ad 100644 --- a/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs +++ b/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs @@ -45,5 +45,9 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers.Admin { return View(); } + public IActionResult QrScanner() + { + return View(); + } } } diff --git a/Areas/Inventory/Controllers/ItemMovementController.cs b/Areas/Inventory/Controllers/ItemMovementController.cs index 2da7e77..69cbe3d 100644 --- a/Areas/Inventory/Controllers/ItemMovementController.cs +++ b/Areas/Inventory/Controllers/ItemMovementController.cs @@ -16,6 +16,11 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers return View(); } + public ActionResult Qr() + { + return View(); + } + [Authorize] [HttpPost("/i/{id}")] public IActionResult ItemRecognization(string id, [FromBody] ItemModel item) diff --git a/Areas/Inventory/Models/ItemMovementModel.cs b/Areas/Inventory/Models/ItemMovementModel.cs index b618169..fb81751 100644 --- a/Areas/Inventory/Models/ItemMovementModel.cs +++ b/Areas/Inventory/Models/ItemMovementModel.cs @@ -26,8 +26,10 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models [Comment("Repair, Calibration, Faulty, Ready To Deploy, On Delivery")] public string? LatestStatus { get; set; } public bool MovementComplete { get; set; } = false; + //public virtual ItemModel? Item { get; set; } + //[ForeignKey("ToStore")] public virtual ItemModel? Item { get; set; } - [ForeignKey("ToStore")] + [ForeignKey("ItemId")] public virtual StoreModel? NextStore { get; set; } [ForeignKey("ToStation")] public virtual StationModel? NextStation { get; set; } diff --git a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml index 48c5027..b090376 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml @@ -20,7 +20,7 @@
- + @* *@
@*
@@ -46,7 +46,7 @@
- {{thisQRInfo.uniqueID}} + {{thisQRInfo.itemId}}
@@ -76,368 +76,6 @@
- @section Scripts { @@ -564,6 +202,7 @@ showSerialNumber() { return this.showProduct.category === 'Asset' || this.showProduct.category === 'Part'; }, + }, methods: { async addItem() { @@ -649,7 +288,7 @@ "columns": [ { "title": "Unique Id", - "data": "itemId", + "data": "id", "createdCell": function (td, cellData, rowData, row, col) { // Assign a unique ID to the element $(td).attr('id', `qr${cellData}`); @@ -657,7 +296,7 @@ }, { "title": "Print", - "data": "itemId", + "data": "item.itemId", "render": function (data, type, full, meta) { var printButton = ``; return printButton; @@ -666,71 +305,71 @@ }, { "title": "To User", - "data": "toUser", + "data": "item.toUser", }, { "title": "Last User", - "data": "lastStore", + "data": "item.lastUser", }, { "title": "Action", - "data": "action", + "data": "item.action", }, { "title": "Latest Status", - "data": "latestStatus", + "data": "item.latestStatus", }, { "title": "Quantity", - "data": "quantity", + "data": "item.quantity", }, { "title": "To Station", - "data": "toStation", + "data": "item.toStation", }, { "title": "To Store", - "data": "toStore", + "data": "item.toStore", }, { "title": "To Other", - "data": "toOther", + "data": "item.toOther", }, { "title": "Remark", - "data": "remark", + "data": "item.remark", }, { "title": "Note", - "data": "consignmentNote", + "data": "item.consignmentNote", }, { "title": "Send Date", - "data": "date", + "data": "item.date", }, { "title": "Last User", - "data": "lastUser", + "data": "item.lastUser", }, { "title": "Last Store", - "data": "lastStore", + "data": "item.lastStore", }, { "title": "Last Station", - "data": "lastStation", + "data": "item.lastStation", }, { "title": "Latest Status", - "data": "latestStatus", + "data": "item.latestStatus", }, { "title": "Receive Date", - "data": "date", + "data": "item.date", }, { "title": "Completion", - "data": "movementComplete", + "data": "item.movementComplete", }, // { @@ -769,10 +408,12 @@ const api = this.api(); api.rows().every(function () { const data = this.data(); // Row data - const containerId = `qr${data.itemId}`; + const containerId = `qr${data.id}`; + const container = $(`#${containerId}`); container.empty(); - container.append(`${data.itemId}`); + container.append(`${data.item.itemId}`); + // console.log(container[0]); if (container) { // Generate QR code only if not already generated @@ -825,6 +466,7 @@ }, async fetchItem() { + await this.fetchUser(); try { // const token = localStorage.getItem('token'); // Get the token from localStorage const response = await fetch('/InvMainAPI/ItemMovementList', { @@ -839,6 +481,13 @@ throw new Error('Failed to fetch item'); } this.items = await response.json(); + // const allowedKeys = ["toUser", "lastUser"]; + // this.items = (await response.json()).filter(item => allowedKeys.some(key => item[key] === this.currentUser.id)); + // this.items = (await response.json()).filter(item => item.lastUser === this.currentUser); + // const allowedKeys = ["toUser", "lastUser"]; + // this.items = (await response.json()).filter(item => + // allowedKeys.some(key => item[key] === this.currentuser.id) + // ); if (this.itemDatatable) { this.itemDatatable.clear().destroy(); @@ -1104,6 +753,7 @@ this.currentUserCompanyDept = companyDeptData; this.selectedCompany = companyDeptData?.companyId || ""; this.selectedDepartment = companyDeptData?.departmentId || ""; + } else { console.error(`Failed to fetch user: ${response.statusText}`); diff --git a/Areas/Inventory/Views/_InventoryPartial.cshtml b/Areas/Inventory/Views/_InventoryPartial.cshtml index 0de8bd5..9dd3383 100644 --- a/Areas/Inventory/Views/_InventoryPartial.cshtml +++ b/Areas/Inventory/Views/_InventoryPartial.cshtml @@ -74,4 +74,17 @@ + +
+ +
\ No newline at end of file diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index 713376b..de7eead 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -525,8 +525,18 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory { var itemMovementList = await _centralDbContext.ItemMovements.ToListAsync(); + //var itemList = await _centralDbContext.Items.ToListAsync(); + + int itemrow = 0; + var itemMovementListWithQR = itemMovementList.Select(item => new + { + id = itemrow++, + item, // Includes all properties of the original item + QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.ItemId}" // Generate QR String + }).ToList(); Console.WriteLine(Json(itemMovementList)); - return Json(itemMovementList); + //return Json(itemMovementList); + return Json(itemMovementListWithQR); //try diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index f9730df..15d2bd3 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -783,7 +783,7 @@ - @await RenderSectionAsync("Scripts", required: false) + @await RenderSectionAsync("Scripts", required: false)z