diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml index 5f0e183..2f41ebb 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml @@ -603,8 +603,8 @@ "data": "convertPrice", }, { - "title": "Invoice Date", - "data": "invoiceDate", + "title": "Register Date", + "data": "createDate", }, { "title": "Warranty Until", @@ -672,11 +672,12 @@ }) // Attach click event listener to the delete buttons - $('#itemDatatable tbody').on('click', '.delete-btn', function () { + $('#itemDatatable tbody').off('click', '.delete-btn').on('click', '.delete-btn', function () { const itemId = $(this).data('id'); self.deleteItem(itemId); }); + $('#itemDatatable tbody').on('click', '.print-btn', function () { const $button = $(this); // The clicked button const $row = $button.closest('tr'); // The parent row of the button @@ -692,9 +693,8 @@ // For expanded view: Find the img in the first column of the current row imageSrc = $row.find('td:nth-child(1) img').attr('src'); } - if (imageSrc) { - self.printItem(itemId, imageSrc); // Call the print function with the itemId and imageSrc + self.printItem(itemId, imageSrc); //\ Call the print function with the itemId and imageSrc } else { console.error("Image source not found."); } @@ -876,9 +876,7 @@ .row($(`.delete-btn[data-id="${itemId}"]`).closest('tr')) .remove() .draw(); - } else { - alert(result.message); - } + } } catch (error) { console.error("Error deleting item:", error); @@ -893,7 +891,6 @@ this.thisQRInfo.uniqueID = itemId; const uniqueQR = itemId; const container = document.getElementById("QrContainer"); - if (!container) { console.error("Container not found."); return; @@ -946,7 +943,11 @@ console.error("Items list is not available or is not an array."); return null; } - return this.items.find(item => item.uniqueID === uniqueID); + + //FIX ERROR + const foundItem = this.items.find(item => String(item.uniqueID).trim() === String(uniqueID).trim()); + + return foundItem ? JSON.parse(JSON.stringify(foundItem)) : null; }, printQRInfo() { // Create a virtual DOM element @@ -1025,7 +1026,6 @@ }); }, - }, }); diff --git a/Areas/Inventory/Views/InventoryMaster/ProductRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/ProductRegistration.cshtml index ae53ba4..0d50396 100644 --- a/Areas/Inventory/Views/InventoryMaster/ProductRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ProductRegistration.cshtml @@ -145,7 +145,6 @@ }, methods: { initiateTable() { - console.log(this.products) this.productDatatable = $('#productDatatable').DataTable({ "data": this.products, "columns": [ @@ -180,7 +179,7 @@ "title": "Delete", "data": "productId", "render": function (data) { - var deleteButton = ``; + var deleteButton = ``; return deleteButton; }, } diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index e374c86..5b7e9c1 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Templates.BlazorIdentity.Pages; using Mono.TextTemplating; using Newtonsoft.Json; using PSTW_CentralSystem.Areas.Inventory.Models; @@ -265,6 +266,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory var userRole = await _userManager.GetRolesAsync(user); var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance"); List itemList = new List(); + List createDate = new List(); // Get the item list if (isAdmin) { @@ -296,14 +298,22 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory .ThenInclude(m => m!.FromUser) .Where(i => i.DepartmentId == user.departmentId) .ToListAsync(); + } + // Get the departments list (DepartmentId references Departments) var departments = await _centralDbContext.Departments.ToListAsync(); + var createDates = await _centralDbContext.ItemMovements.Where(r => r.Action == "Register").ToListAsync(); + + // Buat dictionary agar lebih cepat dicari berdasarkan ItemID + var createDateDict = await _centralDbContext.ItemMovements.Where(r => r.Action == "Register").GroupBy(r => r.ItemId).ToDictionaryAsync(g => g.Key, g => g.Min(m => m.Date)); + // Now join items with users and departments manually var itemListWithDetails = itemList.Select(item => new { + createDate = createDateDict.ContainsKey(item.ItemID) ? createDateDict[item.ItemID].ToString("dd/MM/yyyy HH:mm:ss") : null, item.ItemID, item.UniqueID, item.CompanyId, @@ -324,7 +334,8 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory EndWDate = item.EndWDate.ToString("dd/MM/yyyy"), InvoiceDate = item.InvoiceDate?.ToString("dd/MM/yyyy"), item.Department?.DepartmentName, - CreatedBy=item.CreatedBy!.UserName, + RegisterDate = createDate, + CreatedBy =item.CreatedBy!.UserName, item.Product!.ProductName, item.Product!.ProductShortName, item.Product!.Category, @@ -465,12 +476,26 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory return NotFound(new { success = false, message = "Item not found" }); } + // Get related item movements + var itemMovements = await _centralDbContext.ItemMovements + .Where(i => i.ItemId == item.ItemID) + .ToListAsync(); + + // Remove all related item movements + if (itemMovements.Any()) + { + _centralDbContext.ItemMovements.RemoveRange(itemMovements); + await _centralDbContext.SaveChangesAsync(); + } + + // Remove the item itself _centralDbContext.Items.Remove(item); await _centralDbContext.SaveChangesAsync(); return Ok(new { success = true, message = "Item deleted successfully" }); } + [HttpPost("GetItem/{id}")] // Endpoint to retrieve an item by its ID public async Task GetItem(string id) {