diff --git a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml index a53292f..bada624 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml @@ -1044,44 +1044,43 @@ this.loading = true; await this.fetchUser(); try { - // const token = localStorage.getItem('token'); // Get the token from localStorage const response = await fetch('/InvMainAPI/ItemMovementList', { - method: 'POST', // Specify the HTTP method - headers: { - 'Content-Type': 'application/json', // Set content type - // 'Authorization': `Bearer ${token}` // Include the token in the headers - } + method: 'POST', + headers: { 'Content-Type': 'application/json' } }); - if (!response.ok) { - throw new Error('Failed to fetch item'); - } + if (!response.ok) throw new Error('Failed to fetch item'); + + const data = await response.json(); + if(this.currentRole == "Super Admin"){ - this.items = await response.json(); - this.initAllTables(); - + this.items = data; } else { - const data = await response.json(); + + const myStationIds = this.stations + .filter(s => s.stationPicID === this.currentUser.id) + .map(s => s.stationId); + this.items = data.filter(item => - item.lastUser === this.currentUser.id || - item.toUser === this.currentUser.id || - item.lastStore === this.currentUser.store || - item.toStore === this.currentUser.store + item.lastUser === this.currentUser.id || + item.toUser === this.currentUser.id || + (item.lastStation && myStationIds.includes(item.lastStation)) || + (item.toStation && myStationIds.includes(item.toStation)) || + item.lastStore === this.currentUser.store || + item.toStore === this.currentUser.store ); - - this.initAllTables(); - } + this.initAllTables(); + if (this.itemDatatable) { this.itemDatatable.clear().destroy(); } this.initiateTable(); - } + } catch (error) { console.error('Error fetching item:', error); } - this.loading = false; }, async fetchUser() { @@ -1164,10 +1163,10 @@ { title: "Action", data: "action" }, { title: "Send Date", data: "sendDate" , render: this.formatDate.bind(this)}, { title: "From User", data: "lastUserName" }, - { title: "Last User", data: "toUserName" }, { title: "From Station", data: "lastStationName" }, - { title: "Last Station", data: "toStationName" }, { title: "From Store", data: "lastStoreName" }, + { title: "Last User", data: "toUserName" }, + { title: "Last Station", data: "toStationName" }, { title: "Last Store", data: "toStoreName" }, { title: "Start Status", data: "toOther" }, { title: "Product Category", data: "productCategory" }, @@ -1189,10 +1188,10 @@ { title: "Receive Date", data: "receiveDate", render: this.formatDate.bind(this) }, { title: "Action", data: "action" }, { title: "From User", data: "lastUserName" }, - { title: "Last User", data: "toUserName" }, { title: "From Station", data: "lastStationName" }, - { title: "Last Station", data: "toStationName" }, { title: "From Store", data: "lastStoreName" }, + { title: "Last User", data: "toUserName" }, + { title: "Last Station", data: "toStationName" }, { title: "Last Store", data: "toStoreName" }, { title: "Start Status", data: "toOther" }, { title: "Latest Status", data: "latestStatus" }, @@ -1205,12 +1204,16 @@ }); this.assignStationDatatable = $("#assignStationDatatable").DataTable({ - data: this.items.filter((m) => m.action === "Assign" ), + data: this.items.filter((m) => + m.action === "Assign" || + m.action === "Change" || + m.toStation !== null + ), columns: [ { title: "Unique Id", data: "id" }, { title: "Product Name", data: "productName", render: (data, type, full) => { return `${data}
${renderFile(full.productImage)}`; } }, { title: "Product Code", data: "uniqueID" }, - { title: "Assign Date", data: "sendDate", render: this.formatDate.bind(this) }, + { title: "Assign Date", data: "sendDate", render: this.formatDate.bind(this) }, { title: "Action", data: "action" }, { title: "Station User PIC", data: "lastUserName" }, { title: "From Station", data: "lastStationName" }, diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml index bd7362f..92e899b 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml @@ -337,7 +337,7 @@
- +
@@ -426,11 +426,11 @@ // Show the modal $('.modal').modal('hide'); }); - $('.submit-button').on('click', function () { - // Show the modal - $('#rejectModal').modal('hide'); - $('#approveModal').modal('hide'); - }); + // $('.submit-button').on('click', function () { + // Show the modal + // $('#rejectModal').modal('hide'); + // $('#approveModal').modal('hide'); + // }); }); const app = Vue.createApp({ data() { @@ -536,7 +536,7 @@ // Prepare data as JSON (No file upload) const requestDatas = { ProductId: this.productId, - StationId: this.stationId, + // StationId: this.stationId, UserId: this.userId, ProductCategory: this.productCategory, RequestQuantity: this.quantity, @@ -720,8 +720,8 @@ "columns": [ { "title": "Request ID", "data": "requestID" }, { "title": "Product", "data": "productName", "render": renderDocument }, - { "title": "From Store", "data": "fromStoreItem" }, - { "title": "Assign Store", "data": "assignStoreItem" }, + { "title": "From Store", "data": "fromStoreName" }, + { "title": "Assign Store", "data": "assignStoreName" }, { "title": "Product Category", "data": "productCategory" }, { "title": "Request Quantity", "data": "requestQuantity" }, { "title": "Document/Picture", "data": "document", "render": renderDocument }, @@ -748,8 +748,8 @@ { "title": "Action", "data": "requestID", "render": renderActionButtons, "className": "align-middle" }, { "title": "Product", "data": "productName", "render": renderDocument }, { "title": "Requested by User", "data": "userName" }, - { "title": "From Store", "data": "fromStoreItem" }, - { "title": "Assign Store", "data": "assignStoreItem" }, + { "title": "From Store", "data": "fromStoreName" }, + { "title": "Assign Store", "data": "assignStoreName" }, { "title": "Product Category", "data": "productCategory" }, { "title": "Request Quantity", "data": "requestQuantity" }, { "title": "Document/Picture", "data": "document", "render": renderDocument }, @@ -766,8 +766,8 @@ { "title": "Request ID", "data": "requestID" }, { "title": "Product", "data": "productName", "render": renderDocument }, { "title": "Requested by User", "data": "userName" }, - { "title": "From Store", "data": "fromStoreItem" }, - { "title": "Assign Store", "data": "assignStoreItem" }, + { "title": "From Store", "data": "fromStoreName" }, + { "title": "Assign Store", "data": "assignStoreName" }, { "title": "Product Category", "data": "productCategory" }, { "title": "Request Quantity", "data": "requestQuantity" }, { "title": "Document/Picture", "data": "document", "render": renderDocument }, @@ -976,107 +976,79 @@ } }, async approveRequest() { - // if (!confirm("Are you sure you want to approve this request?")) { - // return; - // } + + if (!this.approveremark || this.approveremark.trim() === "") { + alert("Please enter a remark before approving this request."); + return; + } const formData = { - RemarkMasterInv: this.rejectremark, + RemarkMasterInv: this.approveremark, + }; - }; + let requestID = this.currentrequestID; + this.loading = true; - let requestID = this.currentrequestID; try { const response = await fetch(`/InvMainAPI/ApproveRequest/${requestID}`, { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) - }); const result = await response.json(); if (result.success) { alert(result.message); - - //static update - const row = $(`.approve-btn[data-id="${requestID}"]`).closest('tr'); - let rowData = this.requestDatatable.row(row).data(); - - // Update the status and remark - rowData.status = "Approved"; - - // Remove row from requestDatatable - this.requestDatatable.row(row).remove().draw(); - - // Add updated row to settledrequestDatatable - this.settledrequestDatatable.row.add(rowData).draw(); - - + this.approveremark = ""; + this.fetchRequest(); } else { alert(result.message); } } catch (error) { console.error("Error approving request:", error); - // alert("An error occurred while approving the request."); } finally { this.loading = false; + $('#approveModal').modal('hide'); } }, async rejectRequest() { + if (!this.rejectremark || this.rejectremark.trim() === "") { + alert("Please enter a remark before rejecting this request."); + return; + } - const formData = { - RemarkMasterInv: this.rejectremark, - - }; + const formData = { + RemarkMasterInv: this.rejectremark, + }; - let requestID = this.currentrequestID; + let requestID = this.currentrequestID; + this.loading = true; try { - const response = await fetch(`/InvMainAPI/RejectRequest/${requestID}`, { method: 'POST', - headers: { - 'Content-Type': 'application/json', - // 'Authorization': `Bearer ${this.token}` - }, + headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) - }); + if (response.ok) { - // If the form submission was successful, display a success message - // alert('Success!', 'Request has been Rejected.', 'success'); - - const row = $(`.approve-btn[data-id="${requestID}"]`).closest('tr'); - let rowData = this.requestDatatable.row(row).data(); - - // Update the status and remark - rowData.status = "Rejected"; - rowData.remarkMasterInv = this.rejectremark; - - // Remove row from requestDatatable - this.requestDatatable.row(row).remove().draw(); - - // Add updated row to settledrequestDatatable - this.settledrequestDatatable.row.add(rowData).draw(); - - + alert('Request has been Rejected.'); + this.rejectremark = ""; + this.fetchRequest(); } 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'); } finally { this.loading = false; + $('#rejectModal').modal('hide'); } }, async rejectRequestModal(requestID, remark) { diff --git a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml index e9c2196..3c89e3a 100644 --- a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml @@ -280,8 +280,10 @@ + @@ -353,11 +355,24 @@
-
@@ -411,12 +426,24 @@
-
@@ -538,11 +565,24 @@
-
@@ -664,7 +704,7 @@
- +
@@ -683,43 +723,51 @@
@* Model Deploy to Station *@ -