diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml
index 90cb1b6..f09dee1 100644
--- a/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml
+++ b/Areas/Inventory/Views/InventoryMaster/ItemRegistration.cshtml
@@ -614,7 +614,7 @@
},
{
"title": "Price(RM)",
- "data": "convertPrice",
+ "data": (row) => parseFloat(row.convertPrice).toFixed(2),
},
{
"title": "Register Date",
diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml
index e154879..86a7560 100644
--- a/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml
+++ b/Areas/Inventory/Views/InventoryMaster/ItemRequestMaster.cshtml
@@ -65,8 +65,8 @@
@@ -122,6 +217,8 @@
const app = Vue.createApp({
data() {
return {
+ editSection: null,
+ productId: null,
addSection: false,
productName: null,
manufacturer: '',
@@ -165,7 +262,7 @@
},
{ "title": "Product Stock",
"data": "quantityProduct",
- },
+ },
{ "title": "Image",
"data": "imageProduct",
"render": function (data, type, full, meta) {
@@ -175,6 +272,14 @@
return image;
},
},
+ {
+ "title": "Edit",
+ "data": "productId",
+ "render": function (data) {
+ var editButton = `
`;
+ return editButton;
+ },
+ },
{
"title": "Delete",
"data": "productId",
@@ -188,6 +293,13 @@
responsive:true,
})
self = this;
+
+ // Attach click event listener to the edit buttons
+ $('#productDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () {
+ const productId = $(this).data('id');
+ self.editProduct(productId);
+ });
+
// Attach click event listener to the delete buttons
$('#productDatatable tbody').on('click', '.delete-btn', function () {
const productId = $(this).data('id'); // Get the manufacturer ID from the button
@@ -227,6 +339,75 @@
console.error('Error fetching products:', error);
}
},
+ async editProduct(productId) {
+ // Find the selected station data
+ const product = this.products.find(s => s.productId === productId);
+ if (!product) {
+ alert('Error', 'Product not found!', 'warning');
+ return;
+ }
+
+ // Populate form fields
+ this.productId = productId;
+ this.productName = product.productName;
+ this.stationName = product.stationName;
+ this.productShortName = product.productShortName;
+ this.manufacturers = product.manufacturer;
+ this.category = product.category;
+ this.modelNo = product.modelNo;
+ console.log(this.manufactures);
+ // Show the edit form and hide the add form
+ this.addSection = false;
+ this.editSection = true;
+ },
+
+ async submitEditProduct() {
+ const formData = {
+ ProductId: this.productId,
+ productName: this.stationName,
+ ProductShortName: this.productShortName,
+ ManufacturerId: this.manufacturer,
+ category: this.category,
+ ModelNo: this.modelNo,
+ ImageProduct: this.imageProduct
+ };
+
+ try {
+ // List of required fields
+ const requiredFields = ['productName', 'manufacturer', 'category', 'modelNo', 'imageProduct'];
+
+ // 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');
+ return; // Exit early if validation fails
+ }
+ }
+ const response = await fetch('/InvMainAPI/EditProduct', {
+ 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
+ await this.fetchProducts();
+ this.resetForm();
+ this.editSection = false;
+ } catch (error) {
+ console.error('Error editing station:', error);
+ this.errorMessage = 'Error: ' + error.message;
+ }
+ },
+
async addProduct() {
// const existingProduct = this.products.find(p => p.modelNo === this.modelNo);
// if (existingProduct) {
diff --git a/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml
index 9b49354..480d85f 100644
--- a/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml
+++ b/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml
@@ -51,6 +51,66 @@
+
+