Item Movement User
This commit is contained in:
parent
e78e1c979e
commit
a3dc02fb80
@ -609,67 +609,55 @@
|
||||
},
|
||||
|
||||
groupedByStation() {
|
||||
let grouped = {};
|
||||
this.itemMovements.forEach((movement) => {
|
||||
let groupedByItem = this.itemMovements.reduce((acc, movement) => {
|
||||
if (!acc[movement.uniqueID]) {
|
||||
acc[movement.uniqueID] = {
|
||||
uniqueID: movement.uniqueID,
|
||||
movements: [],
|
||||
};
|
||||
}
|
||||
acc[movement.uniqueID].movements.push(movement);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
if (movement.toStation !== null) {
|
||||
let station = movement.toStationName;
|
||||
let itemId = movement.uniqueID;
|
||||
let groupedByStation = {};
|
||||
|
||||
if (!grouped[station]) {
|
||||
grouped[station] = {};
|
||||
Object.keys(groupedByItem).forEach(itemId => {
|
||||
let movements = groupedByItem[itemId].movements
|
||||
.sort((a, b) => b.id - a.id); // Newest → Oldest
|
||||
|
||||
// Find first occurrence of 'Return' complete
|
||||
let stopIndex = movements.findIndex(m =>
|
||||
m.toOther === 'Return' && m.movementComplete == 1
|
||||
);
|
||||
|
||||
// Remove older movements
|
||||
if (stopIndex !== -1) {
|
||||
movements = movements.slice(0, stopIndex);
|
||||
}
|
||||
|
||||
if (!grouped[station][itemId]) {
|
||||
grouped[station][itemId] = { uniqueID: itemId, movements: [] };
|
||||
if (movements.length > 0) {
|
||||
let latestMovement = movements[0];
|
||||
let station = latestMovement.lastStationName || latestMovement.toStationName || "Self Assigned";
|
||||
|
||||
if (!groupedByStation[station]) {
|
||||
groupedByStation[station] = {};
|
||||
}
|
||||
|
||||
grouped[station][itemId].movements.push(movement);
|
||||
groupedByStation[station][itemId] = { uniqueID: itemId, movements };
|
||||
}
|
||||
|
||||
if (movement.lastStation !== null) {
|
||||
let station = movement.lastStationName;
|
||||
let itemId = movement.uniqueID;
|
||||
|
||||
if (!grouped[station]) {
|
||||
grouped[station] = {};
|
||||
}
|
||||
|
||||
if (!grouped[station][itemId]) {
|
||||
grouped[station][itemId] = { uniqueID: itemId, movements: [] };
|
||||
}
|
||||
|
||||
grouped[station][itemId].movements.push(movement);
|
||||
}
|
||||
|
||||
if (movement.lastStation == null && movement.toStation == null) {
|
||||
|
||||
let station = "Self Assigned";
|
||||
let itemId = movement.uniqueID;
|
||||
|
||||
if (!grouped[station]) {
|
||||
grouped[station] = {};
|
||||
}
|
||||
|
||||
if (!grouped[station][itemId]) {
|
||||
grouped[station][itemId] = { uniqueID: itemId, movements: [] };
|
||||
}
|
||||
|
||||
grouped[station][itemId].movements.push(movement);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Sort stations and move "Unassign Station" to the last position
|
||||
let sortedKeys = Object.keys(grouped).sort((a, b) => {
|
||||
// 4️⃣ **Sort stations & move 'Unassign Station' to last**
|
||||
let sortedKeys = Object.keys(groupedByStation).sort((a, b) => {
|
||||
if (a === "Unassign Station") return 1;
|
||||
if (b === "Unassign Station") return -1;
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
let sortedGrouped = {};
|
||||
sortedKeys.forEach((key) => {
|
||||
sortedGrouped[key] = grouped[key];
|
||||
sortedKeys.forEach(key => {
|
||||
sortedGrouped[key] = groupedByStation[key];
|
||||
});
|
||||
|
||||
return sortedGrouped;
|
||||
@ -746,8 +734,6 @@
|
||||
showDetails: false,
|
||||
}));
|
||||
|
||||
console.log(this.itemMovements);
|
||||
|
||||
this.renderTables();
|
||||
} catch (error) {
|
||||
console.error("Error fetching item:", error);
|
||||
@ -771,131 +757,110 @@
|
||||
this.stationDatatable.destroy();
|
||||
}
|
||||
|
||||
// Get latest movement per uniqueID
|
||||
function getLatestMovements(data) {
|
||||
let latestMovements = {};
|
||||
data.forEach(movement => {
|
||||
let id = movement.uniqueID;
|
||||
if (!latestMovements[id] || latestMovements[id].id < movement.id) {
|
||||
latestMovements[id] = movement;
|
||||
}
|
||||
});
|
||||
return Object.values(latestMovements);
|
||||
}
|
||||
|
||||
// Distribute items based on priority
|
||||
let latestMovements = getLatestMovements(this.itemMovements);
|
||||
let notCompleteData = [];
|
||||
let completeData = [];
|
||||
let assignedData = [];
|
||||
|
||||
latestMovements.forEach(movement => {
|
||||
if (movement.movementComplete == 0) {
|
||||
notCompleteData.push(movement);
|
||||
} else if (movement.movementComplete == 1 && movement.action !== "Assign") {
|
||||
completeData.push(movement);
|
||||
} else if (movement.movementComplete == 1 && movement.action == "Assign") {
|
||||
assignedData.push(movement);
|
||||
}
|
||||
});
|
||||
|
||||
// Table 1: Not Complete Movements
|
||||
this.itemMovementNotCompleteDatatable = $("#itemMovementNotCompleteDatatable").DataTable({
|
||||
data: this.itemMovements.filter((m) => m.movementComplete == 0),
|
||||
data: notCompleteData,
|
||||
columns: [
|
||||
{ title: "Unique Id", data: "id" },
|
||||
{ title: "Product Name", data: "productName" },
|
||||
{ title: "Product Code", data: "uniqueID" },
|
||||
{ title: "Action", data: "action" },
|
||||
{ title: "Send Date", data: "sendDate" },
|
||||
{ title: "Start Status", data: "toOther" },
|
||||
{ title: "From User", data: "toUserName" },
|
||||
{ title: "Last User", data: "lastUserName" },
|
||||
{ title: "From Station", data: "toStationName" },
|
||||
{ title: "From Store", data: "toStoreName" },
|
||||
{ title: "Start Status", data: "toOther" },
|
||||
{ title: "Quantity", data: "quantity" },
|
||||
{
|
||||
title: "Note",
|
||||
data: "consignmentNote",
|
||||
render: function (data, type, full, meta) {
|
||||
if (!data) {
|
||||
return "No Document";
|
||||
}
|
||||
|
||||
// Check if the document is an image based on file extension
|
||||
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
|
||||
var isPdf = /\.pdf$/i.test(data);
|
||||
|
||||
if (isImage) {
|
||||
return `<a href="${data}" target="_blank" data-lightbox="image-1">
|
||||
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
|
||||
</a>`;
|
||||
}
|
||||
else if (isPdf) {
|
||||
return `<a href="${data}" 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="${data}" target="_blank">Download File</a>`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||
{ title: "Remark", data: "remark" },
|
||||
],
|
||||
responsive: true,
|
||||
});
|
||||
|
||||
// Table 2: Completed Movements
|
||||
this.itemMovementCompleteDatatable = $("#itemMovementCompleteDatatable").DataTable({
|
||||
data: this.itemMovements.filter((m) => m.movementComplete == 1 && m.action !== "Assign"),
|
||||
data: completeData,
|
||||
columns: [
|
||||
{ title: "Unique Id", data: "id" },
|
||||
{ title: "Product Name", data: "productName" },
|
||||
{ title: "Product Code", data: "uniqueID" },
|
||||
{ title: "Send Date", data: "sendDate" },
|
||||
{ title: "Receive Date", data: "receiveDate" },
|
||||
{ title: "Action", data: "action" },
|
||||
{ title: "Start Status", data: "toOther" },
|
||||
{ title: "Latest Status", data: "latestStatus" },
|
||||
{ title: "From User", data: "toUserName" },
|
||||
{ title: "Last User", data: "lastUserName" },
|
||||
{ title: "From Station", data: "toStationName" },
|
||||
{ title: "Last Station", data: "lastStationName" },
|
||||
{ title: "From Store", data: "toStoreName" },
|
||||
{ title: "Last Store", data: "lastStoreName" },
|
||||
{ title: "Start Status", data: "toOther" },
|
||||
{ title: "Latest Status", data: "latestStatus" },
|
||||
{ title: "Qty", data: "quantity" },
|
||||
{ title: "Note",
|
||||
data: "consignmentNote",
|
||||
render: function (data, type, full, meta) {
|
||||
if (!data) {
|
||||
return "No Document";
|
||||
}
|
||||
|
||||
// Check if the document is an image based on file extension
|
||||
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
|
||||
var isPdf = /\.pdf$/i.test(data);
|
||||
|
||||
if (isImage) {
|
||||
return `<a href="${data}" target="_blank" data-lightbox="image-1">
|
||||
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
|
||||
</a>`;
|
||||
}
|
||||
else if (isPdf) {
|
||||
return `<a href="${data}" 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="${data}" target="_blank">Download File</a>`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||
{ title: "Remark", data: "remark" },
|
||||
],
|
||||
responsive: true,
|
||||
});
|
||||
|
||||
// Table 3: Assigned Movements
|
||||
this.stationDatatable = $("#stationDatatable").DataTable({
|
||||
data: this.itemMovements.filter((m) => m.action === "Assign" ),
|
||||
data: assignedData,
|
||||
columns: [
|
||||
{ title: "Unique Id", data: "id" },
|
||||
{ title: "Product Name", data: "productName" },
|
||||
{ title: "Product Code", data: "uniqueID" },
|
||||
{ title: "Assign Date", data: "sendDate" },
|
||||
{ title: "From User", data: "toUserName" },
|
||||
{ title: "From Station", data: "toStationName" },
|
||||
{ title: "Last Station", data: "lastStationName" },
|
||||
{ title: "Qty", data: "quantity" },
|
||||
{
|
||||
title: "Note",
|
||||
data: "consignmentNote",
|
||||
render: function (data, type, full, meta) {
|
||||
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||
{ title: "Remark", data: "remark" },
|
||||
],
|
||||
responsive: true,
|
||||
});
|
||||
|
||||
// Function to render file (image/PDF)
|
||||
function renderFile(data, type, full, meta) {
|
||||
if (!data) {
|
||||
return "No Document";
|
||||
}
|
||||
|
||||
// Check if the document is an image based on file extension
|
||||
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
|
||||
var isPdf = /\.pdf$/i.test(data);
|
||||
|
||||
if (isImage) {
|
||||
return `<a href="${data}" target="_blank" data-lightbox="image-1">
|
||||
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
|
||||
</a>`;
|
||||
}
|
||||
else if (isPdf) {
|
||||
} else if (isPdf) {
|
||||
return `<a href="${data}" target="_blank">
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
|
||||
alt="PDF Document" class="img-thumbnail"
|
||||
@ -905,16 +870,14 @@
|
||||
} else {
|
||||
return `<a href="${data}" target="_blank">Download File</a>`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: "Remark", data: "remark" },
|
||||
],
|
||||
responsive: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
toggleCategory(itemId) {
|
||||
this.categoryVisible[itemId] = !this.categoryVisible[itemId];
|
||||
|
||||
this.detailsVisible = {};
|
||||
this.historyVisible = {};
|
||||
},
|
||||
|
||||
toggleHistory(itemId) {
|
||||
|
||||
@ -462,7 +462,7 @@
|
||||
},
|
||||
},
|
||||
{
|
||||
"title": "Product Id",
|
||||
"title": "Product Name",
|
||||
"data": "productName",
|
||||
},
|
||||
{
|
||||
@ -570,7 +570,7 @@
|
||||
},
|
||||
},
|
||||
{
|
||||
"title": "Product Id",
|
||||
"title": "Product Name",
|
||||
"data": "productName",
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user