This commit is contained in:
ameerulrasyid 2025-03-07 09:08:48 +08:00
parent e78e1c979e
commit e43205c08e
2 changed files with 99 additions and 5 deletions

View File

@ -647,7 +647,7 @@
}, },
computed: { computed: {
groupedItems() { groupedItems() {
return this.items.reduce((acc, movement) => { let grouped = this.items.reduce((acc, movement) => {
if (!acc[movement.itemId]) { if (!acc[movement.itemId]) {
acc[movement.itemId] = { acc[movement.itemId] = {
uniqueID: movement.uniqueID, uniqueID: movement.uniqueID,
@ -657,6 +657,35 @@
acc[movement.itemId].movements.push(movement); acc[movement.itemId].movements.push(movement);
return acc; 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() { groupedByStation() {
@ -725,18 +754,19 @@
// return sortedGrouped; // return sortedGrouped;
// <----UPDATE RETURN ITEM ONCE ---->
let grouped = {}; 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) => { this.items.forEach((movement) => {
let station = null; let station = null;
if (movement.lastStation !== null) { if (movement.lastStation !== null) {
station = movement.lastStationName; // Latest assigned station station = movement.lastStationName;// Latest assigned station
} else if (movement.toStation !== null) { } 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 { } else {
station = "Self Assigned"; // No station history station = "Self Assigned";// No station history
} }
let itemId = movement.uniqueID; let itemId = movement.uniqueID;
@ -773,6 +803,8 @@
}); });
return sortedGrouped; return sortedGrouped;
}, },
filteredItems() { filteredItems() {
if (!this.searchQuery.trim()) { if (!this.searchQuery.trim()) {

View File

@ -303,6 +303,37 @@
{ {
"title": "Product Name", "title": "Product Name",
"data": "productName", "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 ` <div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank" data-lightbox="image-1">
<img src="${imageSrc}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
</a>`;
}
else if (isPdf) {
return `<div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
alt="PDF Document" class="img-thumbnail"
style="width: 50px; height: 50px;" />
<br>View PDF
</a>`;
}
// else {
// return `<a href="${imageSrc}" target="_blank">Download File</a>`;
// }
},
}, },
{ {
"title": "Requested by User", "title": "Requested by User",
@ -427,6 +458,37 @@
{ {
"title": "Product Name", "title": "Product Name",
"data": "productName", "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 ` <div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank" data-lightbox="image-1">
<img src="${imageSrc}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
</a>`;
}
else if (isPdf) {
return `<div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
alt="PDF Document" class="img-thumbnail"
style="width: 50px; height: 50px;" />
<br>View PDF
</a>`;
}
// else {
// return `<a href="${imageSrc}" target="_blank">Download File</a>`;
// }
},
}, },
{ {
"title": "Requested by User", "title": "Requested by User",