diff --git a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml
index b1ac0c2..d38ff16 100644
--- a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml
+++ b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml
@@ -40,6 +40,10 @@
color: brown;
}
+ .text-weird {
+ color: purple;
+ }
+
.ms-auto {
margin-left: auto !important; /* Push Complete/Incomplete to right */
@@ -143,10 +147,11 @@
- {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : 'Assign'))) }}
+ {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : ( movement.action == 'Register' ? 'Register' : 'Assign')))) }}
@@ -180,9 +185,9 @@
-
- {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete')) }}
+ {{ movement.action == 'Register' ? 'Complete' : (movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete'))) }}
@@ -241,11 +246,11 @@
- {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : 'Assign'))) }}
-
+ {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : ( movement.action == 'Register' ? 'Register' : 'Assign')))) }}
@@ -278,9 +283,9 @@
-
- {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete')) }}
+ {{ movement.action == 'Register' ? 'Complete' : (movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete'))) }}
@@ -364,10 +369,11 @@
- {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : 'Assign'))) }}
+ {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : ( movement.action == 'Register' ? 'Register' : 'Assign')))) }}
@@ -401,9 +407,9 @@
-
- {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete')) }}
+ {{ movement.action == 'Register' ? 'Complete' : (movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete'))) }}
@@ -457,10 +463,11 @@
- {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : 'Assign'))) }}
+ {{ movement.toOther === 'Return' ? 'Return' : (movement.toOther === 'On Delivery' ? 'Receive' : ( movement.toStation !== null ? 'Change' : ( movement.toOther == 'Faulty' || movement.toOther == 'Calibration' || movement.toOther == 'Repair' ? movement.toOther : ( movement.action == 'Register' ? 'Register' : 'Assign')))) }}
@@ -494,9 +501,9 @@
-
- {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete')) }}
+ {{ movement.action == 'Register' ? 'Complete' : (movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : ( movement.toOther === 'Repair' || movement.toOther === 'Calibration' && movement.latestStatus === 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete'))) }}
@@ -642,7 +649,6 @@
},
mounted() {
this.fetchItem();
- console.log("Filtered Station:", this.filteredStation);
},
computed: {
@@ -658,6 +664,8 @@
return acc;
}, {});
+ console.log(grouped);
+
// Sort items from newest to oldest & filter them
for (let itemId in grouped) {
let movements = grouped[itemId].movements
@@ -689,120 +697,61 @@
},
groupedByStation() {
- // let grouped = {};
- // this.items.forEach((movement) => {
- // if (movement.toStation !== null) {
- // let station = movement.toStationName;
- // let itemId = movement.uniqueID;
+ let groupedByItem = this.items.reduce((acc, movement) => {
+ if (!acc[movement.uniqueID]) {
+ acc[movement.uniqueID] = {
+ uniqueID: movement.uniqueID,
+ movements: [],
+ };
+ }
+ acc[movement.uniqueID].movements.push(movement);
+ return acc;
+ }, {});
- // if (!grouped[station]) {
- // grouped[station] = {};
- // }
+ let groupedByStation = {};
- // if (!grouped[station][itemId]) {
- // grouped[station][itemId] = { uniqueID: itemId, movements: [] };
- // }
+ Object.keys(groupedByItem).forEach(itemId => {
+ let movements = groupedByItem[itemId].movements
+ .sort((a, b) => b.id - a.id); // Newest → Oldest
- // grouped[station][itemId].movements.push(movement);
- // }
+ // Ensure at least 3 movements before stopping
+ let stopIndex = movements.slice(3).findIndex(m =>
+ m.toOther === 'Return' && m.movementComplete == 1
+ );
- // if (movement.lastStation !== null) {
- // let station = movement.lastStationName;
- // let itemId = movement.uniqueID;
+ // Remove older movements
+ if (stopIndex !== -1) {
+ stopIndex += 3; // Adjust index since we sliced after the first 3
+ movements = movements.slice(0, stopIndex);
+ }
- // if (!grouped[station]) {
- // grouped[station] = {};
- // }
+ if (movements.length > 0) {
+ let latestMovement = movements[0];
+ let station = latestMovement.lastStationName || latestMovement.toStationName || "Not Assigned";
- // if (!grouped[station][itemId]) {
- // grouped[station][itemId] = { uniqueID: itemId, movements: [] };
- // }
+ if (!groupedByStation[station]) {
+ groupedByStation[station] = {};
+ }
- // grouped[station][itemId].movements.push(movement);
- // }
- // if (movement.lastStation == null && movement.toStation == null) {
+ groupedByStation[station][itemId] = { uniqueID: itemId, movements };
+ }
+ });
- // let station = "Self Assigned";
- // let itemId = movement.uniqueID;
+ // 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);
+ });
- // if (!grouped[station]) {
- // grouped[station] = {};
- // }
+ let sortedGrouped = {};
+ sortedKeys.forEach(key => {
+ sortedGrouped[key] = groupedByStation[key];
+ });
- // 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) => {
- // 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];
- // });
-
-
- // return sortedGrouped;
-
-// <----UPDATE RETURN ITEM ONCE ---->
- let grouped = {};
-
- // 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
- } else if (movement.toStation !== null) {
- station = movement.toStationName;// If no new station, use last known station
- } else {
- station = "Self Assigned";// No station history
- }
-
- let itemId = movement.uniqueID;
-
- // Ensure only the latest assigned station keeps the item
- if (!grouped[itemId]) {
- grouped[itemId] = { uniqueID: itemId, station: station, movements: [] };
- }
-
- // Always update the latest station for this item
- grouped[itemId].station = station;
- grouped[itemId].movements.push(movement);
- });
-
- // Convert to station-based grouping
- let stationGrouped = {};
- Object.values(grouped).forEach(({ uniqueID, station, movements }) => {
- if (!stationGrouped[station]) {
- stationGrouped[station] = {};
- }
- stationGrouped[station][uniqueID] = { uniqueID, movements };
- });
-
- // Sort stations and move "Unassign Station" last
- let sortedKeys = Object.keys(stationGrouped).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] = stationGrouped[key];
- });
-
- return sortedGrouped;
+ return sortedGrouped;
+
},
@@ -995,7 +944,7 @@
if(this.currentRole == "Super Admin"){
this.items = await response.json();
- // console.log(this.items);
+ console.log(this.items);
this.initAllTables();
} else {
@@ -1245,7 +1194,6 @@
// },
handleSorting() {
this.renderTables();
- console.log(this.sortBy);
},
renderTables() {
// if (this.sortBy === "logs") {
@@ -1424,8 +1372,9 @@
this.historyVisible = {};
},
toggleHistory(itemId) {
- this.historyVisible = {};
+
this.historyVisible[itemId] = !this.historyVisible[itemId];
+ // this.historyVisible = {};
},