diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml index 3b5aa32..777447f 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml @@ -227,6 +227,11 @@ "title": "Product Name", "data": "productName", }, + { + "title": "User ID", + "data": "userName", + }, + { "title": "Product Category", "data": "productCategory", @@ -268,10 +273,10 @@ "title": "User Remark", "data": "remarkUser", }, - { - "title": "InvMaster Remark", - "data": "remarkMasterInv", - }, + // { + // "title": "InvMaster Remark", + // "data": "remarkMasterInv", + // }, { "title": "Status", "data": "status", diff --git a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml index 0fedbe9..32cc2fa 100644 --- a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml @@ -128,6 +128,7 @@ + @@ -301,10 +302,28 @@ + + + +
+
+
+ +
+ +
+ + + +
+
+
@@ -374,7 +393,7 @@ this.startScanner(); this.fetchUsers(); this.fetchStores(); - // this.fetchItem('ARA00500008'); for testing only. clear this + //this.fetchItem('ARA00500008'); // for testing only. clear this }, computed: { filteredDepartments() { @@ -397,19 +416,19 @@ }, }, methods: { - handleFileUpload(event) { - const file = event.target.files[0]; + handleFileUpload(event) { + const file = event.target.files[0]; - if (file) { - const reader = new FileReader(); - reader.onload = (e) => { - this.document = e.target.result.split(',')[1]; // Get Base64 string (remove metadata) - }; - reader.readAsDataURL(file); - } else { - this.document = null; - } - }, + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + this.document = e.target.result.split(',')[1]; // Get Base64 string (remove metadata) + }; + reader.readAsDataURL(file); + } else { + this.document = null; + } + }, async addItemMovement() { if (this.showProduct.category == "Disposable") { @@ -419,18 +438,18 @@ const now = new Date(); const formData = { - ...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, MovementComplete: false, } : {}), - ...(this.selectedAction === 'store' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedStore, MovementComplete: false,} : {}), - ...(this.selectedAction === 'supplier' ? { toUser: this.currentUser.id, toOther: this.selectedOther, SendDate: this.assigndate, Remark: this.remark + '. Item sent to ' + this.selectedSupplier + ' for ' + this.selectedOther,lastUser: this.currentUser.id, MovementComplete: false, } : {}), - ...(this.selectedAction === 'faulty' ? { toUser: this.currentUser.id,toOther: 'Faulty', Date: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), Remark: this.remark, ConsignmentNote: this.document, MovementComplete: true, } : {}), - - ItemId: this.thisItem.itemID, - Action: 'Stock Out', - Quantity: 1, - + ...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, MovementComplete: false,} : {}), + ...(this.selectedAction === 'store' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedStore, MovementComplete: false, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1,} : {}), + ...(this.selectedAction === 'supplier' ? { toUser: this.currentUser.id, toOther: this.selectedOther, SendDate: this.assigndate, Remark: this.remark + '. Item sent to ' + this.selectedSupplier + ' for ' + this.selectedOther,lastUser: this.currentUser.id, MovementComplete: false, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1, } : {}), + ...(this.selectedAction === 'faulty' ? { toUser: this.currentUser.id,toOther: 'Faulty', Date: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), Remark: this.remark, ConsignmentNote: this.document, MovementComplete: true, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1,} : {}), + ItemId: this.thisItem.itemID, + Action: 'Stock Out', + Quantity: 1, }; + + try { // Proceed to send the data to the API @@ -464,11 +483,61 @@ alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error'); } + }, + async receiveItemMovement() { + + if (this.showProduct.category == "Disposable") { + this.serialNumber = ""; + } + + const now = new Date(); + const formData = { + + Id: this.thisItem.movementId, + ReceiveDate: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), + + }; + + + + try { + + // Proceed to send the data to the API + const response = await fetch('/InvMainAPI/UpdateItemMovementMaster', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + // 'Authorization': `Bearer ${this.token}` + }, + body: JSON.stringify(formData) + }); + if (response.ok) { + // If the form submission was successful, display a success message + alert('Success!', 'Item form has been successfully submitted.', 'success'); + const updatedItem = await response.json(); + // this.items.push(updatedItem); + console.log(updatedItem); + + // Reset the form + this.resetForm(); + window.location.href = '/Inventory/InventoryMaster/ItemMovement'; + + } else { + throw new Error('Failed to submit form.'); + } + + } catch (error) { + console.error('Error:', error); + + // Displaying error message + alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error'); + } + }, startScanner() { const config = { fps: 60, - qrbox: 200 + qrbox: 400 }; navigator.mediaDevices.getUserMedia({ @@ -505,7 +574,13 @@ method: 'POST',} ); if (response.ok) { + // this.thisItem = await response.json(); + this.thisItem = await response.json(); + console.log(this.thisItem); + if (this.thisItem.toOther === "Return" && this.thisItem.lastUser == this.currentUserId) { + this.selectedAction = "receive"; + } } else { diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index 6e0d2a7..1db3eeb 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -548,7 +548,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory public async Task ItemMovementList() { - var itemMovementList = await _centralDbContext.ItemMovements.ToListAsync(); + var itemMovementList = await _centralDbContext.ItemMovements.Include(i => i.NextUser).ToListAsync(); //var itemList = await _centralDbContext.Items.ToListAsync(); int itemrow = 0; @@ -556,9 +556,12 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory { id = itemrow++, item, // Includes all properties of the original item - QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.ItemId}" // Generate QR String + QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.ItemId}", // Generate QR String + userName = item.NextUser?.FullName }).ToList(); - Console.WriteLine(Json(itemMovementList)); + //Console.WriteLine(Json(itemMovementList)); + + //return Json(itemMovementList); return Json(itemMovementListWithQR); } @@ -574,13 +577,13 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory try { - if (itemmovement.ToUser == null) - { - throw new Exception("itemmovement.ToUser is null"); - } + //if (itemmovement.ToUser == null) + //{ + // throw new Exception("itemmovement.ToUser is null"); + //} //var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser) ?? new InventoryMasterModel { UserId = itemmovement.ToUser }; - var inventoryMaster = await _centralDbContext.InventoryMasters.FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser); + var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser); if (inventoryMaster != null) { itemmovement.ToStore = inventoryMaster.StoreId; @@ -633,17 +636,41 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory updateItem.ItemStatus = 8; } - Console.WriteLine("updateItem.MovementId" + updateItem.MovementId); - Console.WriteLine("itemmovement.Id" + itemmovement.Id); - + //Console.WriteLine("updateItem.MovementId" + updateItem.MovementId); + //Console.WriteLine("itemmovement.Id" + itemmovement.Id); + updateItem.MovementId = itemmovement.Id; _centralDbContext.Items.Update(updateItem); - + await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid + + } + return Json(new + { + itemmovement.Id, + itemmovement.ItemId, + itemmovement.ToStation, + itemmovement.ToStore, + itemmovement.ToUser, + itemmovement.ToOther, + itemmovement.sendDate, + itemmovement.Action, + itemmovement.Quantity, + itemmovement.Remark, + itemmovement.ConsignmentNote, + itemmovement.Date, + itemmovement.LastUser, + itemmovement.LastStore, + itemmovement.LastStation, + itemmovement.LatestStatus, + itemmovement.receiveDate, + itemmovement.MovementComplete + }); - await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid - return Json(itemmovement); + + + //return Json(itemmovement); } catch (Exception ex) { @@ -652,6 +679,45 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory } + [HttpPost("UpdateItemMovementMaster")] + public async Task UpdateItemMovementMaster([FromBody] ItemMovementModel receiveMovement) + { + + try + { + + var updatedList = await _centralDbContext.ItemMovements.FindAsync(receiveMovement.Id); + + if (updatedList == null) + { + return NotFound("Item movement record not found."); + } + + updatedList.LatestStatus = "Delivered"; + updatedList.receiveDate = receiveMovement.receiveDate; + updatedList.MovementComplete = true; + + _centralDbContext.ItemMovements.Update(updatedList); + await _centralDbContext.SaveChangesAsync(); + + //var receiveItems = await _centralDbContext.Items.FindAsync(receiveMovement.ItemId); + + //if (receiveItems != null) + //{ + // receiveItems.ItemStatus = 3; + // _centralDbContext.Items.Update(receiveItems); + + // await _centralDbContext.SaveChangesAsync(); // Simpan perubahan + //} + + return Json(updatedList); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + #endregion ItemMovement #region ItemMovementUser @@ -835,13 +901,13 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory public async Task ItemRequestList() { - var itemRequestList = await _centralDbContext.Requests.Include(i => i.Product).ToListAsync(); + var itemRequestList = await _centralDbContext.Requests.Include(i => i.Product).Include(i => i.User).ToListAsync(); return Json(itemRequestList.Select(i => new { i.requestId, productName = i.Product?.ProductName, i.ProductId, - i.UserId, + userName = i.User?.FullName, i.status, i.StationId, i.RequestQuantity, diff --git a/wwwroot/Media/Inventory/request/2_37610af7-037e-4158-8e99-1a73e85cc21111_Request.jpg b/wwwroot/Media/Inventory/request/2_37610af7-037e-4158-8e99-1a73e85cc21111_Request.jpg new file mode 100644 index 0000000..5e223c8 Binary files /dev/null and b/wwwroot/Media/Inventory/request/2_37610af7-037e-4158-8e99-1a73e85cc21111_Request.jpg differ