diff --git a/Areas/Inventory/Views/ItemMovement/ItemMovementUser.cshtml b/Areas/Inventory/Views/ItemMovement/ItemMovementUser.cshtml index 52216f1..2b526f9 100644 --- a/Areas/Inventory/Views/ItemMovement/ItemMovementUser.cshtml +++ b/Areas/Inventory/Views/ItemMovement/ItemMovementUser.cshtml @@ -36,27 +36,37 @@ .ms-auto { margin-left: auto !important; /* Push Complete/Incomplete to right */ } + + @await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartialUser.cshtml")
-

Sort by:

+

Sort by:

-

Search Item:

+

Search Item:

+
+

Search Station:

+
+ +
+
+
@@ -77,6 +87,7 @@
+
@@ -94,10 +105,15 @@ Latest Movement
-

- {{ movement.toOther === 'On Delivery' ? 'Receive' : 'Return' }} +

+ + {{ movement.action === 'Assign' ? 'Assign' : (movement.toOther === 'On Delivery' ? 'Receive' : 'Return') }} +

+
@@ -143,33 +159,34 @@

Start

-

User: {{ movement.toUserName }}

-

Station: {{ movement.toStationName }}

-

Store: {{ movement.toStoreName }}

+

User: {{ movement.toUserName }}

+

Station: {{ movement.toStationName }}

+

Store: {{ movement.toStoreName }}

{{ movement.latestStatus || movement.toOther }}

-

-

- + +

End

-

User: {{ movement.lastUserName }}

-

Station: {{ movement.lastStationName }}

-

Store: {{ movement.lastStoreName }}

+

User: {{ movement.lastUserName }}

+

Station: {{ movement.lastStationName }}

+

Store: {{ movement.lastStoreName }}

@@ -186,9 +203,13 @@
-

- {{ movement.toOther === 'On Delivery' ? 'Receive' : 'Return' }} +

+ + {{ movement.action === 'Assign' ? 'Assign' : (movement.toOther === 'On Delivery' ? 'Receive' : 'Return') }} +

@@ -236,33 +257,34 @@

Start

-

User: {{ movement.toUserName }}

-

Station: {{ movement.toStationName }}

-

Store: {{ movement.toStoreName }}

+

User: {{ movement.toUserName }}

+

Station: {{ movement.toStationName }}

+

Store: {{ movement.toStoreName }}

{{ movement.latestStatus || movement.toOther }}

-

-

- + +

End

-

User: {{ movement.lastUserName }}

-

Station: {{ movement.lastStationName }}

-

Store: {{ movement.lastStoreName }}

+

User: {{ movement.lastUserName }}

+

Station: {{ movement.lastStationName }}

+

Store: {{ movement.lastStoreName }}

@@ -272,41 +294,245 @@
- - - -
+ + +
+
+ +
+

{{ station }}

+ +
+ + +
+
+ +
+

Item : {{ group.uniqueID }}

+ +
+ + +
+
+
+ Latest Movement +
+

+ + {{ movement.action === 'Assign' ? 'Assign' : (movement.toOther === 'On Delivery' ? 'Receive' : 'Return') }} + +

+ +
+

Send Date:

+ {{ movement.sendDate }} +
+ +
+

Receive Date:

+ {{ movement.receiveDate || 'Not arrive' }} +
+ +
+

Action:

+ {{ movement.action }} +
+ +
+

Status:

+ {{ movement.latestStatus || movement.toOther }} +
+ + + +

+ {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete') }} +

+
+ +
+
+
+ + +

Start

+

User: {{ movement.toUserName }}

+

Station: {{ movement.toStationName }}

+

Store: {{ movement.toStoreName }}

+
+
+ +

{{ movement.latestStatus || movement.toOther }}

+

+ +

+

+ +

+
+
+ + + +

End

+

User: {{ movement.lastUserName }}

+

Station: {{ movement.lastStationName }}

+

Store: {{ movement.lastStoreName }}

+
+
+
+
+
+ + + + +
+
+
+ +

+ {{ movement.action === 'Assign' ? 'Assign' : (movement.toOther === 'On Delivery' ? 'Receive' : 'Return') }} +

+ + +
+

Send Date:

+ {{ movement.sendDate }} +
+ + +
+

Receive Date:

+ {{ movement.receiveDate || 'Not arrive' }} +
+ + +
+

Action:

+ {{ movement.action }} +
+ + +
+

Status:

+ {{ movement.latestStatus || movement.toOther }} +
+ + + + + +

+ {{ movement.movementComplete == 1 && movement.latestStatus !== 'Ready To Deploy' ? 'Complete' : (movement.latestStatus === 'Ready To Deploy' ? 'Canceled' : 'Incomplete') }} +

+
+ + + +
+
+
+ + + +

Start

+

User: {{ movement.toUserName }}

+

Station: {{ movement.toStationName }}

+

Store: {{ movement.toStoreName }}

+
+
+

+ +

{{ movement.latestStatus || movement.toOther }}

+

+ +

+

+ +

+
+
+ + + + +

End

+

User: {{ movement.lastUserName }}

+

Station: {{ movement.lastStationName }}

+

Store: {{ movement.lastStoreName }}

+
+
+
+ +
+
+ +
+
+
+
+
+ + + + @section Scripts { @@ -324,11 +550,13 @@ itemMovementCompleteDatatable: null, itemMovementNotCompleteDatatable: null, searchQuery: "", + searchStation: "", sortBy: "all", historyVisible: {}, detailsVisible: {}, categoryVisible: {}, consignmentNoteUrl: "", + stationName: "", }; }, computed: { @@ -344,6 +572,37 @@ return acc; }, {}); }, + groupedByStation() { + let grouped = {}; + this.itemMovements.forEach((movement) => { + let station = movement.toStationName || movement.lastStationName || "Unassign Station"; + 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) => { + if (a === "Unassign Station") return 1; // Move Unassign Station to the end + if (b === "Unassign Station") return -1; + return a.localeCompare(b); // Normal sorting for other stations + }); + + let sortedGrouped = {}; + sortedKeys.forEach((key) => { + sortedGrouped[key] = grouped[key]; + }); + + return sortedGrouped; + }, filteredItems() { if (!this.searchQuery.trim()) { return this.groupedItems; @@ -355,6 +614,23 @@ ) ); }, + filteredStation() { + if (!this.searchStation) { + return this.groupedByStation; + } + + let searchQuery = this.searchStation.toLowerCase(); + let grouped = this.groupedByStation; + let filtered = {}; + + Object.keys(grouped).forEach(station => { + if (station.toLowerCase().includes(searchQuery)) { + filtered[station] = grouped[station]; + } + }); + + return filtered; + }, }, mounted() { this.fetchItemMovement(); @@ -382,7 +658,6 @@ }); }, - async fetchItemMovement() { try { const response = await fetch("/InvMainAPI/ItemMovementUser", { diff --git a/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml b/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml index a68575a..c3af828 100644 --- a/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml +++ b/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml @@ -125,6 +125,7 @@ @@ -371,6 +372,7 @@ consignmentNote: null, receiveReturn: null, UniqueID: null, + InventoryMasterId: null, //QR VARIABLE qrCodeResult: null, @@ -399,10 +401,12 @@ selectedCameraId: null, }; }, - mounted() { + async mounted() { this.trackFunctionSelected.value = this.paintOutline; - this.fetchStation(); - this.fetchUser(); + await this.fetchUser(); + await Promise.all([ + this.fetchStation(), + ]); }, methods: { @@ -435,7 +439,7 @@ const formData = { ItemId: this.thisItem.itemID, ToStation: this.thisItem.currentStationId, - ToStore: this.thisItem.currentStoreId, + ToStore: this.thisItem.toStore, ToUser: this.currentUserId, ToOther: "Delivered", SendDate: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), @@ -461,10 +465,11 @@ }); if (response.ok) { + this.thisItem = await response.json(); + this.fetchItem(this.thisItem.uniqueID); alert('Success! Item assign to the Station.'); $('#stationMessage').modal('hide'); this.displayStatus = "return"; - this.thisItem = await response.json(); } else { throw new Error('Failed to submit form.'); } @@ -488,7 +493,7 @@ Id : this.thisItem.id, LatestStatus: "Delivered", ReceiveDate: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), - MovementComplete: true + MovementComplete: true, }; const response = await fetch('/InvMainAPI/UpdateItemMovementUser', { @@ -520,14 +525,14 @@ async returnItemMovement() { - const requiredFields = ['remark', 'consignmentNote']; + // const requiredFields = ['remark', 'consignmentNote']; - for (let field of requiredFields) { - if (!this[field]) { - alert(`Request Error: Please fill in required field ${field}.`, 'warning'); - return; - } - } + // for (let field of requiredFields) { + // if (!this[field]) { + // alert(`Request Error: Please fill in required field ${field}.`, 'warning'); + // return; + // } + // } if (!confirm("Are you sure you want to return this item?")) { return false; @@ -547,7 +552,7 @@ Remark: this.remark, ConsignmentNote: this.consignmentNote, Date: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), - LastUser: this.thisItem.toUser, + LastUser: this.InventoryMasterId, LastStore: this.thisItem.toStore, LastStation: this.thisItem.toStation, LatestStatus: null, @@ -567,6 +572,7 @@ alert('Success! Item is on the delivery to return to Inventory Master.'); this.thisItem = await response.json(); $('#returnModal').modal('hide'); + $('#returnMessage').modal('hide'); this.displayStatus = "requestAgain"; this.resetForm(); } else { @@ -585,7 +591,9 @@ ); if (response.ok) { + this.thisItem = await response.json(); + this.fetchStore(this.thisItem.toStore); if (this.thisItem.movementId != null && this.thisItem.toOther === "On Delivery" && this.thisItem.latestStatus == null && this.thisItem.currentUserId == this.currentUserId && this.thisItem.movementComplete == 0) { this.displayStatus = "arrived"; @@ -616,7 +624,28 @@ if (!response.ok) { throw new Error('Failed to fetch suppliers'); } - this.stationList = await response.json(); // Get the full response object + + const data = await response.json(); + this.stationList = data.filter(station => station.stationPicID === this.currentUserId); + } catch (error) { + console.error('Error fetching suppliers:', error); + } + }, + + async fetchStore(storeId) { + try { + const response = await fetch('/InvMainAPI/StoreSpecificMaster/' + storeId, { + method: 'POST', // Specify the HTTP method + headers: { + 'Content-Type': 'application/json' + } + }); + if (!response.ok) { + throw new Error('Failed to fetch Store'); + } + + const data = await response.json(); + this.InventoryMasterId = data.userId; } catch (error) { console.error('Error fetching suppliers:', error); diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index acccd7e..19b1a52 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -1171,6 +1171,12 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory return Json(storeList); } + [HttpPost("StoreSpecificMaster/{storeId}")] + public async Task StoreSpecificMaster(int storeId) + { + var storeList = await _centralDbContext.InventoryMasters.Where(i => i.StoreId == storeId).FirstOrDefaultAsync(); + return Json(storeList); + } #endregion Store @@ -1280,10 +1286,20 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory returnItems.ItemStatus = 2; _centralDbContext.Items.Update(returnItems); - await _centralDbContext.SaveChangesAsync(); // Simpan perubahan } } + //4. Update Assign Row (Untuk ToStore = Ada value , kepada , ToStore = null) + var updateToStoreAssignStation = await _centralDbContext.ItemMovements.Where(i => i.Action == "Assign").ToListAsync(); + + foreach (var item in updateToStoreAssignStation) + { + item.ToStore = null; // Set ToStore to null for each matching row + _centralDbContext.ItemMovements.Update(item); + } + + await _centralDbContext.SaveChangesAsync(); // Simpan perubahan + return Json(new { updateItemIdMovement.Id, @@ -1353,7 +1369,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory await _centralDbContext.SaveChangesAsync(); // 2. Cari item movement yang ada ItemId & MovementComplete = false - var updateItemIdMovement = await _centralDbContext.ItemMovements + var updateItemIdMovement = await _centralDbContext.ItemMovements.Include(i => i.Item) .FirstOrDefaultAsync(m => m.Id == stationMovement.Id); @@ -1366,9 +1382,9 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory { returnItems.MovementId = updateItemIdMovement.Id; returnItems.ItemStatus = 3; - _centralDbContext.Items.Update(returnItems); - await _centralDbContext.SaveChangesAsync(); // Simpan perubahan + _centralDbContext.Items.Update(returnItems); // Simpan perubahan + await _centralDbContext.SaveChangesAsync(); } } @@ -1376,6 +1392,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory { updateItemIdMovement.Id, updateItemIdMovement.ItemId, + updateItemIdMovement.Item?.UniqueID, updateItemIdMovement.ToStation, updateItemIdMovement.ToStore, updateItemIdMovement.ToUser,