Item Movement User
This commit is contained in:
parent
e78e1c979e
commit
a3dc02fb80
@ -609,67 +609,55 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
groupedByStation() {
|
groupedByStation() {
|
||||||
let grouped = {};
|
let groupedByItem = this.itemMovements.reduce((acc, movement) => {
|
||||||
this.itemMovements.forEach((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 groupedByStation = {};
|
||||||
let station = movement.toStationName;
|
|
||||||
let itemId = movement.uniqueID;
|
|
||||||
|
|
||||||
if (!grouped[station]) {
|
Object.keys(groupedByItem).forEach(itemId => {
|
||||||
grouped[station] = {};
|
let movements = groupedByItem[itemId].movements
|
||||||
}
|
.sort((a, b) => b.id - a.id); // Newest → Oldest
|
||||||
|
|
||||||
if (!grouped[station][itemId]) {
|
// Find first occurrence of 'Return' complete
|
||||||
grouped[station][itemId] = { uniqueID: itemId, movements: [] };
|
let stopIndex = movements.findIndex(m =>
|
||||||
}
|
m.toOther === 'Return' && m.movementComplete == 1
|
||||||
|
);
|
||||||
|
|
||||||
grouped[station][itemId].movements.push(movement);
|
// Remove older movements
|
||||||
|
if (stopIndex !== -1) {
|
||||||
|
movements = movements.slice(0, stopIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (movement.lastStation !== null) {
|
if (movements.length > 0) {
|
||||||
let station = movement.lastStationName;
|
let latestMovement = movements[0];
|
||||||
let itemId = movement.uniqueID;
|
let station = latestMovement.lastStationName || latestMovement.toStationName || "Self Assigned";
|
||||||
|
|
||||||
if (!grouped[station]) {
|
if (!groupedByStation[station]) {
|
||||||
grouped[station] = {};
|
groupedByStation[station] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!grouped[station][itemId]) {
|
groupedByStation[station][itemId] = { uniqueID: itemId, movements };
|
||||||
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
|
// 4️⃣ **Sort stations & move 'Unassign Station' to last**
|
||||||
let sortedKeys = Object.keys(grouped).sort((a, b) => {
|
let sortedKeys = Object.keys(groupedByStation).sort((a, b) => {
|
||||||
if (a === "Unassign Station") return 1;
|
if (a === "Unassign Station") return 1;
|
||||||
if (b === "Unassign Station") return -1;
|
if (b === "Unassign Station") return -1;
|
||||||
return a.localeCompare(b);
|
return a.localeCompare(b);
|
||||||
});
|
});
|
||||||
|
|
||||||
let sortedGrouped = {};
|
let sortedGrouped = {};
|
||||||
sortedKeys.forEach((key) => {
|
sortedKeys.forEach(key => {
|
||||||
sortedGrouped[key] = grouped[key];
|
sortedGrouped[key] = groupedByStation[key];
|
||||||
});
|
});
|
||||||
|
|
||||||
return sortedGrouped;
|
return sortedGrouped;
|
||||||
@ -746,8 +734,6 @@
|
|||||||
showDetails: false,
|
showDetails: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log(this.itemMovements);
|
|
||||||
|
|
||||||
this.renderTables();
|
this.renderTables();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching item:", error);
|
console.error("Error fetching item:", error);
|
||||||
@ -767,154 +753,131 @@
|
|||||||
if (this.itemMovementCompleteDatatable) {
|
if (this.itemMovementCompleteDatatable) {
|
||||||
this.itemMovementCompleteDatatable.destroy();
|
this.itemMovementCompleteDatatable.destroy();
|
||||||
}
|
}
|
||||||
if(this.stationDatatable) {
|
if (this.stationDatatable) {
|
||||||
this.stationDatatable.destroy();
|
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({
|
this.itemMovementNotCompleteDatatable = $("#itemMovementNotCompleteDatatable").DataTable({
|
||||||
data: this.itemMovements.filter((m) => m.movementComplete == 0),
|
data: notCompleteData,
|
||||||
columns: [
|
columns: [
|
||||||
{ title: "Unique Id", data: "id" },
|
{ title: "Unique Id", data: "id" },
|
||||||
|
{ title: "Product Name", data: "productName" },
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Action", data: "action" },
|
{ title: "Action", data: "action" },
|
||||||
{ title: "Send Date", data: "sendDate" },
|
{ title: "Send Date", data: "sendDate" },
|
||||||
|
{ title: "Start Status", data: "toOther" },
|
||||||
{ title: "From User", data: "toUserName" },
|
{ title: "From User", data: "toUserName" },
|
||||||
{ title: "Last User", data: "lastUserName" },
|
{ title: "Last User", data: "lastUserName" },
|
||||||
{ title: "From Station", data: "toStationName" },
|
{ title: "From Station", data: "toStationName" },
|
||||||
{ title: "From Store", data: "toStoreName" },
|
{ title: "From Store", data: "toStoreName" },
|
||||||
{ title: "Start Status", data: "toOther" },
|
|
||||||
{ title: "Quantity", data: "quantity" },
|
{ title: "Quantity", data: "quantity" },
|
||||||
{
|
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||||
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: "Remark", data: "remark" },
|
{ title: "Remark", data: "remark" },
|
||||||
],
|
],
|
||||||
responsive: true,
|
responsive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Table 2: Completed Movements
|
||||||
this.itemMovementCompleteDatatable = $("#itemMovementCompleteDatatable").DataTable({
|
this.itemMovementCompleteDatatable = $("#itemMovementCompleteDatatable").DataTable({
|
||||||
data: this.itemMovements.filter((m) => m.movementComplete == 1 && m.action !== "Assign"),
|
data: completeData,
|
||||||
columns: [
|
columns: [
|
||||||
{ title: "Unique Id", data: "id" },
|
{ title: "Unique Id", data: "id" },
|
||||||
|
{ title: "Product Name", data: "productName" },
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Send Date", data: "sendDate" },
|
{ title: "Send Date", data: "sendDate" },
|
||||||
{ title: "Receive Date", data: "receiveDate" },
|
{ title: "Receive Date", data: "receiveDate" },
|
||||||
{ title: "Action", data: "action" },
|
{ title: "Action", data: "action" },
|
||||||
|
{ title: "Start Status", data: "toOther" },
|
||||||
|
{ title: "Latest Status", data: "latestStatus" },
|
||||||
{ title: "From User", data: "toUserName" },
|
{ title: "From User", data: "toUserName" },
|
||||||
{ title: "Last User", data: "lastUserName" },
|
{ title: "Last User", data: "lastUserName" },
|
||||||
{ title: "From Station", data: "toStationName" },
|
{ title: "From Station", data: "toStationName" },
|
||||||
{ title: "Last Station", data: "lastStationName" },
|
{ title: "Last Station", data: "lastStationName" },
|
||||||
{ title: "From Store", data: "toStoreName" },
|
{ title: "From Store", data: "toStoreName" },
|
||||||
{ title: "Last Store", data: "lastStoreName" },
|
{ title: "Last Store", data: "lastStoreName" },
|
||||||
{ title: "Start Status", data: "toOther" },
|
|
||||||
{ title: "Latest Status", data: "latestStatus" },
|
|
||||||
{ title: "Qty", data: "quantity" },
|
{ title: "Qty", data: "quantity" },
|
||||||
{ title: "Note",
|
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||||
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: "Remark", data: "remark" },
|
{ title: "Remark", data: "remark" },
|
||||||
],
|
],
|
||||||
responsive: true,
|
responsive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Table 3: Assigned Movements
|
||||||
this.stationDatatable = $("#stationDatatable").DataTable({
|
this.stationDatatable = $("#stationDatatable").DataTable({
|
||||||
data: this.itemMovements.filter((m) => m.action === "Assign" ),
|
data: assignedData,
|
||||||
columns: [
|
columns: [
|
||||||
{ title: "Unique Id", data: "id" },
|
{ title: "Unique Id", data: "id" },
|
||||||
|
{ title: "Product Name", data: "productName" },
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Assign Date", data: "sendDate" },
|
{ title: "Assign Date", data: "sendDate" },
|
||||||
{ title: "From User", data: "toUserName" },
|
{ title: "From User", data: "toUserName" },
|
||||||
{ title: "From Station", data: "toStationName" },
|
{ title: "From Station", data: "toStationName" },
|
||||||
{ title: "Last Station", data: "lastStationName" },
|
{ title: "Last Station", data: "lastStationName" },
|
||||||
{ title: "Qty", data: "quantity" },
|
{ title: "Qty", data: "quantity" },
|
||||||
{
|
{ title: "Note", data: "consignmentNote", render: renderFile },
|
||||||
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: "Remark", data: "remark" },
|
{ title: "Remark", data: "remark" },
|
||||||
],
|
],
|
||||||
responsive: true,
|
responsive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Function to render file (image/PDF)
|
||||||
|
function renderFile(data, type, full, meta) {
|
||||||
|
if (!data) {
|
||||||
|
return "No Document";
|
||||||
|
}
|
||||||
|
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>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleCategory(itemId) {
|
toggleCategory(itemId) {
|
||||||
this.categoryVisible[itemId] = !this.categoryVisible[itemId];
|
this.categoryVisible[itemId] = !this.categoryVisible[itemId];
|
||||||
|
|
||||||
|
this.detailsVisible = {};
|
||||||
|
this.historyVisible = {};
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleHistory(itemId) {
|
toggleHistory(itemId) {
|
||||||
|
|||||||
@ -462,7 +462,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Product Id",
|
"title": "Product Name",
|
||||||
"data": "productName",
|
"data": "productName",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -570,7 +570,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Product Id",
|
"title": "Product Name",
|
||||||
"data": "productName",
|
"data": "productName",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user