diff --git a/Areas/Inventory/Models/ItemModel.cs b/Areas/Inventory/Models/ItemModel.cs index a9c4a4a..6bfb6ac 100644 --- a/Areas/Inventory/Models/ItemModel.cs +++ b/Areas/Inventory/Models/ItemModel.cs @@ -45,6 +45,6 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models public virtual ProductModel? Product { get; set; } [ForeignKey("MovementId")] public virtual ItemMovementModel? Movement { get; set; } - + } } diff --git a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml index 870299c..4b08c9b 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemMovement.cshtml @@ -158,7 +158,7 @@
-

Complete Item Movessment

+

Complete Item Movement

All Item Movement

@@ -884,7 +884,7 @@ return this.groupedByStation; } - let searchQueryStation = this.toLowerCase(); + let searchQueryStation = String(this.searchQueryStation).toLowerCase(); let grouped = this.groupedByStation; let filtered = {}; diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml index 86a7560..bd7362f 100644 --- a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml @@ -626,6 +626,25 @@ initiateTable() { self = this; + function formatDateTime(dateString) { + if (!dateString) { + return ""; // Return empty string if date is null or undefined + } + const date = new Date(dateString); + // Add 8 hours for GMT+8, as DateTime.UtcNow is used on the backend. + // If the backend stores dates in a specific timezone and you want to display them + // in the client's local timezone, you might need a different approach or + // ensure the backend sends timezone information. + // For now, assuming backend's UtcNow and client display in GMT+8. + date.setHours(date.getHours()); // Adjust for local time if needed. + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + const seconds = String(date.getSeconds()).padStart(2, '0'); + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; + } function renderActionButtons(data, type, row) { var actiontButtons = `
`; return actiontButtons; @@ -671,8 +690,8 @@ { "title": "Document/Picture", "data": "document", "render": renderDocument }, { "title": "User Remark", "data": "remarkUser" }, { "title": "Status", "data": "status" }, - { "title": "Request Date", "data": "requestDate" }, - { "title": "Approval Date", "data": "approvalDate" } + { "title": "Request Date", "data": "requestDate", "render": formatDateTime }, // Apply formatDateTime + { "title": "Approval Date", "data": "approvalDate", "render": formatDateTime } // Apply formatDateTime ], responsive: true, drawCallback: function (settings) { } @@ -691,8 +710,8 @@ { "title": "User Remark", "data": "remarkUser" }, { "title": "InvMaster Remark", "data": "remarkMasterInv" }, { "title": "Status", "data": "status" }, - { "title": "Request Date", "data": "requestDate" }, - { "title": "Approval Date", "data": "approvalDate" } + { "title": "Request Date", "data": "requestDate", "render": formatDateTime }, // Apply formatDateTime + { "title": "Approval Date", "data": "approvalDate", "render": formatDateTime } // Apply formatDateTime ], responsive: true }); @@ -708,8 +727,8 @@ { "title": "Document/Picture", "data": "document", "render": renderDocument }, { "title": "Remark", "data": "remarkUser" }, { "title": "Status", "data": "status" }, - { "title": "Request Date", "data": "requestDate" }, - { "title": "Approval Date", "data": "approvalDate" }, + { "title": "Request Date", "data": "requestDate", "render": formatDateTime }, // Apply formatDateTime + { "title": "Approval Date", "data": "approvalDate", "render": formatDateTime }, // Apply formatDateTime { "title": "Delete", "data": "requestID", "render": function (data) { @@ -736,8 +755,8 @@ { "title": "Document/Picture", "data": "document", "render": renderDocument }, { "title": "User Remark", "data": "remarkUser" }, { "title": "Status", "data": "status" }, - { "title": "Request Date", "data": "requestDate" }, - { "title": "Approval Date", "data": "approvalDate" } + { "title": "Request Date", "data": "requestDate", "render": formatDateTime }, // Apply formatDateTime + { "title": "Approval Date", "data": "approvalDate", "render": formatDateTime } // Apply formatDateTime ], responsive: true }); @@ -754,8 +773,8 @@ { "title": "Document/Picture", "data": "document", "render": renderDocument }, { "title": "User Remark", "data": "remarkUser" }, { "title": "Status", "data": "status" }, - { "title": "Request Date", "data": "requestDate" }, - { "title": "Approval Date", "data": "approvalDate" } + { "title": "Request Date", "data": "requestDate", "render": formatDateTime }, // Apply formatDateTime + { "title": "Approval Date", "data": "approvalDate", "render": formatDateTime } // Apply formatDateTime ], responsive: true }); diff --git a/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml index 2b43e03..6a7f51a 100644 --- a/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml @@ -34,6 +34,30 @@
+ + + + + + @section Scripts { @{ @@ -57,6 +82,11 @@ manufacturerName: null, }, loading: true, + editManufacturer: { + manufacturerId: null, + manufacturerName: null, + }, + } }, @@ -88,27 +118,54 @@ }, async initiateTable() { + // Clear any existing DataTable instance before re-initializing + if (this.manufacturerDatatable) { + this.manufacturerDatatable.destroy(); + } + this.manufacturerDatatable = $('#manufacturerTable').DataTable({ "data": this.manufacturer, "columns": [ - { "title": "Manufacturer Name", + { + "title": "Manufacturer Name", "data": "manufacturerName", }, - { "title": "Delete", - "data": "manufacturerName", - "render": function (data, type, full, meta) { - var deleteButton = ``; + { + "title": "Edit", + "data": "manufacturerId", // Use manufacturerId for the data attribute + "render": (data, type, row) => { // Use arrow function to preserve 'this' context + // 'this' inside this arrow function will refer to the Vue instance + var editButton = ``; + return editButton; + }, + }, + { + "title": "Delete", + "data": "manufacturerId", // Use manufacturerId for the data attribute + "render": (data, type, row) => { // Use arrow function to preserve 'this' context + var deleteButton = ``; return deleteButton; }, "width": '10%', }, ], - }) - self = this; + }); + + // Use a variable to store the Vue instance for consistent access + const vueInstance = this; + + // Attach click event listener to the edit buttons + $('#manufacturerTable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () { + const manufacturerId = $(this).data('id'); + // Call the method on the stored Vue instance + vueInstance.openEditManufacturerModal(manufacturerId); + $('#editManufacturerModal').modal('show'); // Ensure the modal is shown here + }); + // Attach click event listener to the delete buttons - $('#manufacturerTable tbody').on('click', '.delete-btn', function () { - const manufacturerId = $(this).data('id'); // Get the manufacturer ID from the button - self.deleteManufacturer(manufacturerId); // Call the Vue method + $('#manufacturerTable tbody').off('click', '.delete-btn').on('click', '.delete-btn', function () { + const manufacturerId = $(this).data('id'); + vueInstance.deleteManufacturer(manufacturerId); }); this.loading = false; @@ -153,6 +210,43 @@ this.newManufacturer.manufacturerName = null; }); }, + openEditManufacturerModal(manufacturerId) { + const selected = this.manufacturer.find(m => m.manufacturerId === manufacturerId); + if (!selected) { + alert('Manufacturer not found'); + return; + } + + this.editManufacturer.manufacturerId = selected.manufacturerId; + this.editManufacturer.manufacturerName = selected.manufacturerName; + + $('#editManufacturerModal').modal('show'); + }, + async updateManufacturer() { + try { + const response = await fetch('/InvMainAPI/EditManufacturer', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(this.editManufacturer) + }); + + const data = await response.json(); + + if (data && data.success) { + alert('Manufacturer updated successfully'); + this.fetchManufactures(); // Refresh list + $('#editManufacturerModal').modal('hide'); + } else { + alert(data.message || 'Failed to update manufacturer'); + } + } catch (error) { + console.error('Error updating manufacturer:', error); + alert('Error occurred while updating'); + } + }, + async deleteManufacturer(manufacturerId) { if (!confirm("Are you sure you want to delete this manufacturer?")) { return; @@ -201,6 +295,14 @@ // Show the modal with the ID 'addManufacturerModal'. $('#addManufacturerModal').modal('hide'); }); + $('#editManufacturerBtn').on('click', function () { + // Show the modal with the ID 'editManufacturerModal'. + $('#editManufacturerModal').modal('show'); + }); + $('.closeModal').on('click', function () { + // Show the modal with the ID 'editManufacturerModal'. + $('#editManufacturerModal').modal('hide'); + }); }); } diff --git a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml index 9ce62fd..2eceda0 100644 --- a/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/QrMaster.cshtml @@ -145,29 +145,27 @@
-
-

Item is on Delivery

-
-
- -
- -
- -
- -
-
- -
- +
+

Item is on Delivery

+
+
+ +
+
+ +
+
- -
+
+ +
+
+
+

Receive Item

@@ -257,24 +255,19 @@
-
-

Add Item Movement

-
-
- +
@@ -620,6 +613,7 @@ currentUser: null, currentUserCompanyDept: null, itemlateststatus: "", + isCancelled: false, //QR VARIABLE qrCodeResult: null, @@ -662,9 +656,21 @@ }, computed: { selectedStationPicName() { - const selectedStationObj = this.stationlist.find(station => station.stationId === this.selectedStation); - return selectedStationObj ? selectedStationObj.stationPic.fullName : ""; + const selectedStationObj = this.stationlist.find( + station => station.stationId === this.selectedStation + ); + + if ( + selectedStationObj && + selectedStationObj.stationPic && + selectedStationObj.stationPic.fullName + ) { + return selectedStationObj.stationPic.fullName; + } + + return ""; }, + filteredDepartments() { if (!this.selectedCompany) { return []; // No company selected, return empty list @@ -802,10 +808,11 @@ ctx.stroke(); } }, - resetScanner(){ - this.thisItem = null; - this.resetForm(); - }, + resetScanner() { + this.thisItem = null; + this.isCancelled = false; // Add this + this.resetForm(); + }, handleFileUpload(event) { const file = event.target.files[0]; @@ -875,98 +882,75 @@ } }, - async receiveItemMovement() { - - if (this.showProduct.category == "Disposable") { - this.serialNumber = ""; - } + async receiveItemMovement() { + if (this.showProduct.category == "Disposable") { + this.serialNumber = ""; + } - if(this.thisItem.toOther === "On Delivery" && this.thisItem.toUser == this.currentUser.id){ - if(!window.confirm("Are you sure you want to cancel item delivery?")){ - return; - } - } + if(this.thisItem.toOther === "On Delivery" && this.thisItem.toUser == this.currentUser.id){ + if(!window.confirm("Are you sure you want to cancel item delivery?")){ + return; + } + } - const now = new Date(); - console.log('currentuser'+this.currentUser.id); - console.log('lastuser'+this.thisItem.lastuser); - - const formData = { + const now = new Date(); + try { + // First, update the current movement to mark it as complete + const updateResponse = await fetch('/InvMainAPI/UpdateItemMovementMaster', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ Id: this.thisItem.movementId, ReceiveDate: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), - Remark: this.thisItem.toOther === "On Delivery" && this.thisItem.toUser == this.currentUser.id ? this.thisItem.remark + ". Inventory Master cancelled delivery with remark: " + this.remark : this.thisItem.remark, + Remark: this.thisItem.toOther === "On Delivery" && this.thisItem.toUser == this.currentUser.id ? + this.thisItem.remark + ". Inventory Master cancelled delivery with remark: " + this.remark : + this.thisItem.remark, LastUser: this.thisItem.lastuser == null ? this.currentUser.id : this.thisItem.lastuser, - LatestStatus: this.thisItem.toOther === "Return" ? "Faulty" : (this.thisItem.toOther === "Calibration" || this.thisItem.toOther === "Repair" || this.thisItem.toOther === "On Delivery" ) ? "Ready To Deploy" : (this.itemlateststatus == 'On Delivery' && this.thisItem.lastStore == this.currentUser.store ? "Delivered" : "") - }; + LatestStatus: "Ready To Deploy", // Set status to Ready To Deploy + MovementComplete: true + }) + }); + if (!updateResponse.ok) { + throw new Error('Failed to update current movement'); + } + // Set cancelled flag and reset form + this.isCancelled = true; + this.resetForm(); - try { + // Show the movement form by setting selectedAction + this.selectedAction = "user"; // Default to assign to user - // 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); + } catch (error) { + console.error('Error:', error); + alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error'); + } + }, + async fetchItem(itemid) { + try { + const response = await fetch('/InvMainAPI/GetItem/' + itemid, { + method: 'POST', + }); - // Reset the form - this.resetForm(); - window.location.href = '/Inventory/InventoryMaster/ItemMovement'; + if (response.ok) { + this.thisItem = await response.json(); + this.itemlateststatus = this.thisItem.latestStatus ? this.thisItem.latestStatus : this.thisItem.toOther; + this.itemassignedtouser = (this.thisItem.toUser === this.currentUser.id || this.thisItem.lastUser === this.currentUser.id) && this.thisItem.lastStore === this.currentUser.store; - } 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'); + // Reset cancellation flag when scanning + this.isCancelled = false; + } else { + console.error('Failed to fetch item information'); + this.responseMessage = await response.text(); } - - }, - async fetchItem(itemid) { - try { - const response = await fetch('/InvMainAPI/GetItem/' + itemid, { - method: 'POST',} - ); - if (response.ok) { - // this.thisItem = await response.json(); - - this.thisItem = await response.json(); - console.log('last store'+this.thisItem.lastStore); - - this.itemlateststatus = this.thisItem.latestStatus ? this.thisItem.latestStatus : this.thisItem.toOther; - this.itemassignedtouser = (this.thisItem.toUser === this.currentUser.id || this.thisItem.lastUser === this.currentUser.id ) && this.thisItem.lastStore === this.currentUser.store ? true : false; - // console.log(this.thisItem); - // console.log(this.itemassignedtouser); - console.log(this.thisItem.lastStore); - console.log( this.thisItem.lastStore == this.currentUser.store? true : false); - console.log(this.thisItem.toUser == this.currentUser.id? true : false); - console.log( this.thisItem.lastUser == this.currentUser.id ? true : false); - console.log(((this.thisItem.toUser == this.currentUser.id) || ( this.thisItem.lastUser == this.currentUser.id)) ? true : false); - console.log('currentuser store'+this.currentUser.store); - - - } else { - console.error('Failed to fetch item information'); - this.responseMessage = await response.text(); - } - } catch (error) { - console.error('Error fetching item information:', error); - } - }, + } catch (error) { + console.error('Error fetching item information:', error); + } + }, async fetchSuppliers() { try { const response = await fetch('/InvMainAPI/SupplierList', { diff --git a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml index 4763b05..de8c89a 100644 --- a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml @@ -5,64 +5,66 @@ @await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
-
-
-
- @*Right Side*@ -
-
-
-

REGISTRATION SUPPLIER

-
-
+
+ +
+
+ @*Right Side*@ +
+
+
+

REGISTRATION SUPPLIER

+
+
- @* Supplier Name *@ -
- -
- -
-
- - @* Supplier Gender *@ -
- -
- - @* Supplier PIC *@ -
- -
- + @* Supplier Gender *@ +
+ +
+ +
-
- @* Supplier Email *@ -
- -
- + @* Supplier PIC *@ +
+ +
+ +
-
- @* Supplier Number Phone *@ -
- -
- + @* Supplier Email *@ +
+ +
+ +
-
-
-
-
- - + @* Supplier Number Phone *@ +
+ +
+ +
+
+ +
+
+
+ + +
@@ -70,11 +72,99 @@
+ +
+
- + +
+
+
+
+
+ @*Right Side*@ +
+
+
+

EDIT SUPPLIER

+
+
+ + @* Supplier Name *@ +
+ +
+ +
+
+ + @* Supplier Gender *@ +
+ +
+ +
+
+ + @* Supplier PIC *@ +
+ +
+ +
+
+ + @* Supplier Email *@ +
+ +
+ +
+
+ + @* Supplier Number Phone *@ +
+ +
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+ +
+
- +
+ +
@@ -110,7 +200,10 @@ suppliers: null, supplierDatatable: null, gender: ["Male", "Female", "Helicopter"], - registerSupplierForm: false + registerSupplierForm: false, + editSection: false, + supplierId: null, + addSection: false, } }, mounted(){ @@ -151,11 +244,12 @@ $('#loadingModal').modal('show'); // Create the payload const formData = { + supplierId: this.supplierId, supplierCompName: this.supplierCompName, - supplierAddress: this.supplierAddress, - supplierPIC: this.supplierPIC, supplierEmail: this.supplierEmail, - supplierPhoneNo: this.supplierPhoneNo, + supplierPIC: this.supplierPIC, + supplierAddress: this.supplierAddress, + supplierPhoneNo: this.supplierPhoneNo }; try { @@ -165,7 +259,7 @@ // Loop through required fields and check if any are null or empty for (let field of requiredFields) { if (this[field] === null || this[field] === '') { - alert('Product Error', `Please fill in required fields: ${field}.`, 'warning'); + alert('Supplier Error', `Please fill in required fields: ${field}.`, 'warning'); return; // Exit early if validation fails } } @@ -193,7 +287,7 @@ } catch (error) { console.error('Error:', error); - alert('Product Error', `An error occurred: ${error.message}`, 'error'); + alert('Supplier Error', `An error occurred: ${error.message}`, 'error'); } finally { await new Promise(resolve => { @@ -234,6 +328,14 @@ "title": "Supplier Phone No", "data": "supplierPhoneNo", }, + { + "title": "Edit", + "data": "supplierId", + "render": function (data) { + var editButton = ``; + return editButton; + }, + }, { "title": "Delete", "data": "supplierId", @@ -247,6 +349,12 @@ }) + // Attach click event listener to the edit buttons + $('#supplierDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () { + const supplierId = $(this).data('id'); + self.editSupplier(supplierId); + }); + // Attach click event listener to the delete buttons $('#supplierDatatable tbody').on('click', '.delete-btn', function () { const supplierId = $(this).data('id'); @@ -255,6 +363,75 @@ this.loading = false; }, + async editSupplier(supplierId) { + + const supplier = this.suppliers.find(s => s.supplierId === supplierId); + if (!supplier) { + alert('Error', 'Supplier not found!', 'warning'); + return; + } + + // Populate form fields + this.supplierId = supplierId; + this.supplierCompName = supplier.supplierCompName; + this.supplierEmail = supplier.supplierEmail; + this.supplierAddress = supplier.supplierAddress; + this.supplierPhoneNo = supplier.supplierPhoneNo; + this.supplierPIC = supplier.supplierPIC; + + // Show the edit form and hide the add form + this.addSection = false; + this.editSection = true; + + }, + async submitEditSupplier() { + const formData = { + supplierId: this.supplierId, + SupplierCompName: this.supplierCompName, + supplierEmail: this.supplierEmail, + SupplierPIC: this.supplierPIC, + SupplierAddress: this.supplierAddress, + SupplierPhoneNo: this.supplierPhoneNo + }; + + try { + // List of required fields + const requiredFields = ['supplierCompName', 'supplierAddress', 'supplierPIC', 'supplierEmail', 'supplierPhoneNo']; + + // Loop through required fields and check if any are null or empty + for (let field of requiredFields) { + if (this[field] === null || this[field] === '') { + alert('Supplier Error', `Please fill in required fields: ${field}.`, 'warning'); + return; // Exit early if validation fails + } + } + + // Edit supplier detail + const response = await fetch('/InvMainAPI/EditSupplier', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(formData) + }); + + if (!response.ok) { + const errorData = await response.json(); + console.error('Error response:', errorData); + this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error'); + return; + } + + // Refresh station list and reset form + alert('Success!', 'Supplier form has been successfully submitted.', 'success'); + this.fetchSuppliers(); + this.resetForm(); + this.editSection = false; + } catch (error) { + console.error('Error editing Supplier:', error); + this.errorMessage = 'Error: ' + error.message; + } + }, async deleteSupplier(supplierId) { if (!confirm("Are you sure you want to delete this supplier?")) { return; @@ -280,6 +457,17 @@ console.error('Error deleting supplier:', error); this.errorMessage = 'Error: ' + error.message; } + }, + hideEditSection() { + this.resetForm(); + this.editSection = false; + this.addSection = false; + }, + toggleAddSupplier() { + this.resetForm(); + this.editSection = false; + this.addSection = !this.addSection; + this.registerSupplierForm = this.addSection; } } }); diff --git a/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml b/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml index efe64a4..0559026 100644 --- a/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml +++ b/Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml @@ -138,7 +138,7 @@
+
@@ -373,14 +374,14 @@ // Loop through required fields and check if any are null or empty for (let field of requiredFields) { if (!this[field]) { - alert('Request Error', `Please fill in required fields: ${field}.`, 'warning'); + alert(`Please fill in required fields: ${field}.`, 'warning'); return; } } if (this.assign === "Station"){ if (this.stationId == null) { - alert('Request Error', `Please fill in required fields : Station.`, 'warning'); + alert( `Please fill in required fields : Station.`, 'warning'); return; } } @@ -511,10 +512,9 @@ }); this.loading = false; - } - - - async fetchRequest() { + }, + + async fetchRequest() { try { const response = await fetch(`/InvMainAPI/ItemRequestListEachUser/${this.userId}`, diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index f05edf5..d0f7655 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -111,6 +111,41 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory } } + [HttpPost("EditManufacturer")] + public async Task EditManufacturer([FromBody] ManufacturerModel updatedManufacturer) + { + if (updatedManufacturer == null || updatedManufacturer.ManufacturerId == 0) + { + return BadRequest(new { success = false, message = "Invalid manufacturer data." }); + } + + try + { + // Find the existing manufacturer + var manufacturer = await _centralDbContext.Manufacturers + .FirstOrDefaultAsync(m => m.ManufacturerId == updatedManufacturer.ManufacturerId); + + if (manufacturer == null) + { + return NotFound(new { success = false, message = "Manufacturer not found." }); + } + + // Update fields + manufacturer.ManufacturerName = updatedManufacturer.ManufacturerName; + + // Save changes + await _centralDbContext.SaveChangesAsync(); + + return Ok(new { success = true, message = "Manufacturer updated successfully." }); + } + catch (Exception ex) + { + // Optional: Log the error + return StatusCode(500, new { success = false, message = "Internal server error: " + ex.Message }); + } + } + + [HttpDelete("DeleteManufacturer/{id}")] public async Task DeleteManufacturer(int id) { @@ -274,6 +309,40 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory } } + [HttpPost("EditSupplier")] + public async Task EditSupplier([FromBody] SupplierModel editedSupplier) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + var supplier = await _centralDbContext.Suppliers.FindAsync(editedSupplier.SupplierId); + if (supplier == null) + { + return NotFound("Supplier is null"); + } + + try + { + supplier.SupplierCompName = editedSupplier.SupplierCompName; + supplier.SupplierAddress = editedSupplier.SupplierAddress; + supplier.SupplierPIC = editedSupplier.SupplierPIC; + supplier.SupplierEmail = editedSupplier.SupplierEmail; + supplier.SupplierPhoneNo = editedSupplier.SupplierPhoneNo; + + + + _centralDbContext.Suppliers.Update(supplier); + await _centralDbContext.SaveChangesAsync(); + + return Json(supplier); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpDelete("DeleteSupplier/{id}")] public async Task DeleteSupplier(int id) { @@ -1263,7 +1332,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory Request.status = "Approved"; Request.remarkMasterInv = request.remarkMasterInv; - Request.approvalDate = DateTime.UtcNow; + Request.approvalDate = DateTime.Now; _centralDbContext.SaveChanges(); return Ok(new { success = true, message = "Request Approved Successfully", data = Request }); @@ -1282,7 +1351,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory Request.status = "Rejected"; Request.remarkMasterInv = request.remarkMasterInv; - Request.approvalDate = DateTime.UtcNow; + Request.approvalDate = DateTime.Now; _centralDbContext.SaveChanges(); return Ok(new { success = true, message="Request Rejected Successfully", data=Request }); diff --git a/wwwroot/Media/Inventory/itemmovement/59_5e5d351f-5f4b-4d63-8297-54b46af308eb59_Request.jpg b/wwwroot/Media/Inventory/itemmovement/59_5e5d351f-5f4b-4d63-8297-54b46af308eb59_Request.jpg new file mode 100644 index 0000000..f0d11d1 Binary files /dev/null and b/wwwroot/Media/Inventory/itemmovement/59_5e5d351f-5f4b-4d63-8297-54b46af308eb59_Request.jpg differ diff --git a/wwwroot/Media/Inventory/itemmovement/59_9f7fc742-00ac-4bd6-aadc-32a8a5cdba7759_Request.jpg b/wwwroot/Media/Inventory/itemmovement/59_9f7fc742-00ac-4bd6-aadc-32a8a5cdba7759_Request.jpg new file mode 100644 index 0000000..f0d11d1 Binary files /dev/null and b/wwwroot/Media/Inventory/itemmovement/59_9f7fc742-00ac-4bd6-aadc-32a8a5cdba7759_Request.jpg differ diff --git a/wwwroot/Media/Inventory/itemmovement/7_37fbcdc9-60ea-4220-988a-0c25056747377_Request.jpg b/wwwroot/Media/Inventory/itemmovement/7_37fbcdc9-60ea-4220-988a-0c25056747377_Request.jpg new file mode 100644 index 0000000..5e223c8 Binary files /dev/null and b/wwwroot/Media/Inventory/itemmovement/7_37fbcdc9-60ea-4220-988a-0c25056747377_Request.jpg differ diff --git a/wwwroot/Media/Inventory/itemmovement/7_3ab03871-3e26-4e12-857c-8d046f718a067_Request.jpg b/wwwroot/Media/Inventory/itemmovement/7_3ab03871-3e26-4e12-857c-8d046f718a067_Request.jpg new file mode 100644 index 0000000..5e223c8 Binary files /dev/null and b/wwwroot/Media/Inventory/itemmovement/7_3ab03871-3e26-4e12-857c-8d046f718a067_Request.jpg differ diff --git a/wwwroot/Media/Inventory/request/core2user i117(B82KP4HD) Request.jpg b/wwwroot/Media/Inventory/request/core2user i117(B82KP4HD) Request.jpg new file mode 100644 index 0000000..f0d11d1 Binary files /dev/null and b/wwwroot/Media/Inventory/request/core2user i117(B82KP4HD) Request.jpg differ