@@ -288,7 +288,7 @@
@@ -296,7 +296,7 @@
@@ -304,7 +304,7 @@
@@ -320,7 +320,7 @@
@@ -328,7 +328,7 @@
@@ -367,6 +367,8 @@
$('#addItemBtn').on('click', function () {
// Show the modal with the ID 'addManufacturerModal'.
$('#registerItemModal').modal('show');
+ this.addSection = true;
+ this.editSection = false;
});
$('.closeModal').on('click', function () {
// Show the modal with the ID 'addManufacturerModal'.
@@ -394,19 +396,22 @@
teamType: "",
productName: null,
imageProduct: null,
+ addSection: false,
+ editSection: false,
productCategory: null,
+ itemID: null,
serialNumber: "",
quantity: 1,
supplierName: null,
purchaseDate: null,
PO: null,
currency: "MYR",
- DefaultPrice: 0.01,
+ DefaultPrice: null,
currencyRate: 1,
convertPrice: 0.01,
DONo: null,
DODate: null,
- warranty: 0,
+ warranty: null,
EndWDate: null,
invoiceNo: null,
invoiceDate: null,
@@ -450,6 +455,19 @@
this.fetchCompanies();
this.fetchProducts();
this.fetchSuppliers();
+
+ document.getElementById('addItemBtn').addEventListener('click', () => {
+ this.resetForm();
+ this.addSection = true;
+ this.editSection = false;
+ $('#registerItemModal').modal('show');
+ });
+
+ document.querySelectorAll('.closeModal').forEach(btn => {
+ btn.addEventListener('click', () => {
+ $('.modal').modal('hide');
+ });
+ });
},
computed: {
filteredDepartments() {
@@ -462,7 +480,7 @@
},
showProduct() {
if (!this.selectedProduct) {
- return []; // No company selected, return empty list
+ return []; // No company selected, return empty listx`
}
const product = this.products.find(c => c.productId === this.selectedProduct);
return product ? product : {};
@@ -473,6 +491,18 @@
},
methods: {
async addItem() {
+
+ // List of required fields
+ const requiredFields = ['DefaultPrice', 'DONo', 'DODate', 'warranty', 'invoiceNo', 'invoiceDate'];
+
+ // Loop through required fields and check if any are null or empty
+ for (let field of requiredFields) {
+ if (this[field] === null || this[field] === '') {
+ alert('Item Error', `Please fill in required fields: ${field}.`, 'warning');
+ return;
+ }
+ }
+
if (this.showProduct.category == "Disposable") {
this.serialNumber = "";
}
@@ -489,9 +519,11 @@
DefaultPrice: this.DefaultPrice,
CurrencyRate: this.currencyRate,
ConvertPrice: this.convertPrice,
+ DONo: this.DONo,
DODate: this.DODate,
Warranty: this.warranty,
EndWDate: this.EndWDate,
+ InvoiceNo: this.invoiceNo,
InvoiceDate: this.invoiceDate,
CreatedByUserId: this.currentUser.id,
TeamType: this.selectedTeamType,
@@ -600,7 +632,7 @@
},
{
"title": "Price(RM)",
- "data": "convertPrice",
+ "data": (row) => parseFloat(row.convertPrice).toFixed(2),
},
{
"title": "Register Date",
@@ -626,6 +658,15 @@
Station: ${currentStation}`
}
},
+ {
+ "title": "Edit",
+ "data": "itemID",
+ "render": function (data) {
+ var editButton = `
`;
+ return editButton;
+ },
+ "className": "align-middle",
+ },
{
"title": "Delete",
"data": "itemID",
@@ -671,6 +712,12 @@
}
})
+ // Attach click event listener to the edit buttons
+ $('#itemDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () {
+ const itemId = $(this).data('id');
+ self.editItem(itemId);
+ });
+
// Attach click event listener to the delete buttons
$('#itemDatatable tbody').off('click', '.delete-btn').on('click', '.delete-btn', function () {
const itemId = $(this).data('id');
@@ -796,48 +843,6 @@
console.error('Error fetching currency data:', error);
}
},
- convertCurrency() {
- // Your currency conversion logic here
- console.log('Selected currency:', this.currency);
- },
- resetForm() {
- this.company = '';
- this.Dept = null;
- this.productName = null;
- this.imageProduct = null;
- this.serialNumber = '';
- this.quantity = 1;
- this.supplierName = null;
- this.purchaseDate = null;
- this.PO = null;
- this.currency = 'MYR';
- this.DefaultPrice = 0.01;
- this.currencyRate = 1;
- this.convertPrice = 0.01;
- this.DODate = null;
- this.warranty = 0;
- this.EndWDate = null;
- this.invoiceDate = null;
- this.selectedProduct = '';
- this.selectedSupplier = '';
- this.selectedCompany = this.currentUserCompanyDept.companyId;
- this.selectedDepartment = '';
- this.selectedTeamType = '';
- this.partNumber = null;
- },
-
- // FRONT END FUNCTIONS
- //----------------------//
- //Calculate Total Price
- convertCurrency() {
- const total = this.DefaultPrice * this.currencyRate;
- this.convertPrice = total.toFixed(2);
- this.DefaultPrice = this.DefaultPrice
- // .replace(/[^0-9.]/g, '') // Remove non-numeric characters except decimal points
- // .replace(/(\..*)\..*/g, '$1') // Allow only one decimal point
- // .replace(/^(\d*\.\d{0,2})\d*$/, '$1'); // Limit to two decimal places
-
- },
calculateWarrantyEndDate() {
// Check if DODate and warranty are valid
if (!this.DODate || isNaN(Date.parse(this.DODate))) {
@@ -856,6 +861,51 @@
this.EndWDate = null;
}
},
+ convertCurrency() {
+ // Your currency conversion logic here
+ console.log('Selected currency:', this.currency);
+ },
+ resetForm() {
+ this.company = '';
+ this.Dept = null;
+ this.productName = null;
+ this.imageProduct = null;
+ this.serialNumber = '';
+ this.quantity = 1;
+ this.supplierName = null;
+ this.purchaseDate = null;
+ this.PO = null;
+ this.currency = 'MYR';
+ this.DefaultPrice = null;
+ this.currencyRate = 1;
+ this.convertPrice = 0.01;
+ this.DODate = null;
+ this.warranty = null;
+ this.DONo = null;
+ this.invoiceNo = null;
+ this.EndWDate = null;
+ this.invoiceDate = null;
+ this.selectedProduct = '';
+ this.selectedSupplier = '';
+ // this.selectedCompany = this.currentUserCompanyDept.companyId;
+ // this.selectedDepartment = '';
+ this.selectedTeamType = '';
+ this.partNumber = null;
+ },
+
+ // FRONT END FUNCTIONS
+ //----------------------//
+ //Calculate Total Price
+ convertCurrency() {
+ const total = this.DefaultPrice * this.currencyRate;
+ this.convertPrice = total.toFixed(2);
+ this.DefaultPrice = this.DefaultPrice
+ // .replace(/[^0-9.]/g, '') // Remove non-numeric characters except decimal points
+ // .replace(/(\..*)\..*/g, '$1') // Allow only one decimal point
+ // .replace(/^(\d*\.\d{0,2})\d*$/, '$1'); // Limit to two decimal places
+
+ },
+
async deleteItem(itemId) {
if (!confirm("Are you sure you want to delete this item?")) {
return;
@@ -886,6 +936,127 @@
this.loading = false;
}
},
+
+ async editItem(itemID) {
+ // Cari data item yang dipilih
+ const item = this.items.find(s => s.itemID === itemID);
+ if (!item) {
+ alert('Error', 'Item not found!', 'warning');
+ return;
+ }
+
+ // Populate form fields
+ this.itemID = itemID;
+ this.selectedCompany = item.companyId;
+ this.selectedDepartment = item.departmentId;
+ this.selectedProduct = item.productId;
+ this.serialNumber = item.serialNumber;
+ this.quantity = item.quantity;
+ this.selectedSupplier = item.supplier;
+ this.purchaseDate = item.purchaseDate.split('/').reverse().join('-');
+ this.PO = item.poNo;
+ this.currency = item.currency;
+ this.DefaultPrice = item.defaultPrice;
+ this.currencyRate = item.currencyRate;
+ this.convertPrice = item.convertPrice;
+ this.DONo = item.doNo;
+ this.DODate = item.doDate ? item.doDate.split('T')[0] : null;
+ this.warranty = item.warranty;
+ this.EndWDate = item.endWDate.split('/').reverse().join('-');
+ this.invoiceNo = item.invoiceNo;
+ this.invoiceDate = item.invoiceDate.split('/').reverse().join('-');
+ this.selectedTeamType = item.teamType;
+ this.partNumber = item.partNumber;
+ // Tunjukkan modal edit
+ $('#registerItemModal').modal('show');
+ this.addSection = false;
+ this.editSection = true;
+ },
+
+ async submitEditItem() {
+
+ // List of required fields
+ const requiredFields = ['DefaultPrice', 'DONo', 'DODate', 'warranty', 'invoiceNo', 'invoiceDate'];
+
+ // Loop through required fields and check if any are null or empty
+ for (let field of requiredFields) {
+ if (this[field] === null || this[field] === '') {
+ alert('Item Error', `Please fill in required fields: ${field}.`, 'warning');
+ return;
+ }
+ }
+
+ if (this.showProduct.category == "Disposable") {
+ this.serialNumber = "";
+ }
+ const formData = {
+ itemId : this.itemID,
+ CompanyId: this.selectedCompany,
+ DepartmentId: this.selectedDepartment,
+ ProductId: this.selectedProduct,
+ SerialNumber: this.serialNumber,
+ Quantity: this.quantity,
+ Supplier: this.selectedSupplier,
+ PurchaseDate: this.purchaseDate,
+ PONo: this.PO,
+ Currency: this.currency,
+ DefaultPrice: this.DefaultPrice,
+ CurrencyRate: this.currencyRate,
+ ConvertPrice: this.convertPrice,
+ DONo: this.DONo,
+ DODate: this.DODate,
+ Warranty: this.warranty,
+ EndWDate: this.EndWDate,
+ InvoiceNo: this.invoiceNo,
+ InvoiceDate: this.invoiceDate,
+ TeamType: this.selectedTeamType,
+ PartNumber: this.partNumber,
+ };
+
+ try {
+
+ // Additional specific checks
+ if (this.showSerialNumber) {
+ this.quantity = 0;
+ if (this.serialNumber === null || this.serialNumber === '') {
+ alert('Serial Number Error', 'Serial Number must be filled when selecting Item or Part.', 'warning');
+ return;
+ }
+ }
+ else {
+ this.serialNumber = null;
+ if (this.quantity === 0 || this.quantity === null || this.quantity === '') {
+ alert('quantity Error', 'Quantity is required when selecting Disposable.', 'warning');
+ return;
+ }
+ }
+ const response = await fetch('/InvMainAPI/EditItem', {
+ 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!', 'Item form has been successfully submitted.', 'success');
+ this.fetchItem();
+ this.resetForm();
+ this.editSection = false;
+ this.addSection = false;
+ $('.modal').modal('hide');
+ } catch (error) {
+ console.error('Error editing Item:', error);
+ this.errorMessage = 'Error: ' + error.message;
+ }
+ },
async printItem(itemId, imgSrc) {
try {
this.thisQRInfo.uniqueID = itemId;
@@ -960,7 +1131,7 @@
// Populate the virtual DOM with content
virtualElement.innerHTML = `
-
+
-
+
${this.thisQRInfo.departmentName}
${this.thisQRInfo.productShortName}
${this.thisQRInfo.serialNumber ?? "-"}