diff --git a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml index 431abf2..7bc3f7f 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml @@ -647,7 +647,7 @@ }, computed: { groupedItems() { - return this.items.reduce((acc, movement) => { + let grouped = this.items.reduce((acc, movement) => { if (!acc[movement.itemId]) { acc[movement.itemId] = { uniqueID: movement.uniqueID, @@ -657,6 +657,35 @@ acc[movement.itemId].movements.push(movement); return acc; }, {}); + + // Sort items from newest to oldest & filter them + for (let itemId in grouped) { + let movements = grouped[itemId].movements + .sort((a, b) => b.id - a.id); // Newest to oldest + + // console.log(movements); + // let stopIndex = movements.findIndex(m => + // m.toOther === 'Return' && m.movementComplete == 1 + // ); + + // if (stopIndex !== -1) { + // movements = movements.slice(0, stopIndex + 1); + // } + + // Ensure at least 3 movements before stopping + let stopIndex = movements.slice(3).findIndex(m => + m.toOther === 'Return' && m.movementComplete == 1 + ); + + if (stopIndex !== -1) { + stopIndex += 3; // Adjust index since we sliced after the first 3 + movements = movements.slice(0, stopIndex + 1); // Keep at least 3 + the "Return" row + } + + grouped[itemId].movements = movements; + } + + return grouped; }, groupedByStation() { @@ -725,18 +754,19 @@ // return sortedGrouped; +// <----UPDATE RETURN ITEM ONCE ----> let grouped = {}; - // Process each movement and store only the latest assigned station + // Process each movement and store only the latest assigned station this.items.forEach((movement) => { let station = null; if (movement.lastStation !== null) { - station = movement.lastStationName; // Latest assigned station + station = movement.lastStationName;// Latest assigned station } else if (movement.toStation !== null) { - station = movement.toStationName; // If no new station, use last known station + station = movement.toStationName;// If no new station, use last known station } else { - station = "Self Assigned"; // No station history + station = "Self Assigned";// No station history } let itemId = movement.uniqueID; @@ -773,6 +803,8 @@ }); return sortedGrouped; + + }, filteredItems() { if (!this.searchQuery.trim()) { diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml index 91256bf..39b2a41 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml @@ -303,6 +303,37 @@ { "title": "Product Name", "data": "productName", + "render": function (data, type, full, meta) { + if (!data) { + return "No Document"; + } + + var imageSrc = full.productImage; + // Check if the document is an image based on file extension + var isImage = /\.(jpeg|jpg|png|gif)$/i.test(imageSrc); + var isPdf = /\.pdf$/i.test(imageSrc); + // var imageSrc = full.productImage; Fallback to data if imgsrc is unavailable + console.log(full); + + if (isImage) { + return `
${data}
+ + Image + `; + } + else if (isPdf) { + return `
${data}
+ + PDF Document +
View PDF +
`; + } + // else { + // return `Download File`; + // } + }, }, { "title": "Requested by User", @@ -427,6 +458,37 @@ { "title": "Product Name", "data": "productName", + "render": function (data, type, full, meta) { + if (!data) { + return "No Document"; + } + + var imageSrc = full.productImage; + // Check if the document is an image based on file extension + var isImage = /\.(jpeg|jpg|png|gif)$/i.test(imageSrc); + var isPdf = /\.pdf$/i.test(imageSrc); + // var imageSrc = full.productImage; Fallback to data if imgsrc is unavailable + console.log(full); + + if (isImage) { + return `
${data}
+ + Image + `; + } + else if (isPdf) { + return `
${data}
+ + PDF Document +
View PDF +
`; + } + // else { + // return `Download File`; + // } + }, }, { "title": "Requested by User",