This commit is contained in:
MOHD ARIFF 2025-03-26 14:24:44 +08:00
parent 6e44454808
commit 304b5e6d94

View File

@ -80,14 +80,14 @@
<div class="modal-dialog modal-dialog-centered modal-xl" role="document"> <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="addItemModalLabel">Add Item</h5> <h5 class="modal-title" id="addItemModalLabel">{{editSection? 'Edit Item' : 'Add Item'}}</h5>
<button type="button" class="closeModal" data-dismiss="modal" aria-label="Close" v-on:click="showItemModal=false"> <button type="button" class="closeModal" data-dismiss="modal" aria-label="Close" v-on:click="showItemModal=false">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="container-fluid"> <div class="container-fluid">
<form v-on:submit.prevent="addItem" data-aos="fade-right"> <form v-on:submit.prevent="editSection ? submitEditItem() : addItem()" data-aos="fade-right">
<div class=" register" data-aos="fade-right"> <div class=" register" data-aos="fade-right">
<div class="row" data-aos="fade-right"> <div class="row" data-aos="fade-right">
@ -95,7 +95,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="tab-content" id="myTabContent"> <div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">REGISTRATION ITEM</h3> <h3 class="register-heading">{{editSection? 'EDIT ITEM' : 'REGISTRATION ITEM'}}</h3>
<div class="row register-form"> <div class="row register-form">
<div class="col-md-6"> <div class="col-md-6">
@ -288,7 +288,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="DONo" class="col-sm-4">Enter DO Number:</label> <label for="DONo" class="col-sm-4">Enter DO Number:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="text" id="DONo" name="DONo" class="form-control" v-model="DONo" placeholder="DO123456"> <input type="text" id="DONo" name="DONo" class="form-control" v-model="DONo" placeholder="DO123456" required>
</div> </div>
</div> </div>
@ -296,7 +296,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="DODate" class="col-sm-4">Enter DO Date:</label> <label for="DODate" class="col-sm-4">Enter DO Date:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="date" id="DODate" name="DODate" class="form-control" v-on:input="calculateWarrantyEndDate()" v-model="DODate"> <input type="date" id="DODate" name="DODate" class="form-control" v-on:input="calculateWarrantyEndDate()" v-model="DODate" required>
</div> </div>
</div> </div>
@ -304,7 +304,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="warranty" class="col-sm-4">Enter Warranty (Months):</label> <label for="warranty" class="col-sm-4">Enter Warranty (Months):</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="number" id="warranty" name="warranty" class="form-control" placeholder="0 , 1 , 2 , 3, ..." step="1" min="0" v-on:input="calculateWarrantyEndDate()" required v-model="warranty"> <input type="number" id="warranty" name="warranty" class="form-control" placeholder="0 , 1 , 2 , 3, ..." step="1" min="0" v-on:input="calculateWarrantyEndDate()" v-model="warranty" required>
</div> </div>
</div> </div>
@ -320,7 +320,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="invoiceNo" class="col-sm-4">Invoice Number:</label> <label for="invoiceNo" class="col-sm-4">Invoice Number:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="text" id="invoiceNo" name="invoiceNo" class="form-control" v-model="invoiceNo" placeholder="Invoice123456"> <input type="text" id="invoiceNo" name="invoiceNo" class="form-control" v-model="invoiceNo" placeholder="Invoice123456" required>
</div> </div>
</div> </div>
@ -328,7 +328,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="invoiceDate" class="col-sm-4">Invoice Date:</label> <label for="invoiceDate" class="col-sm-4">Invoice Date:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="date" id="invoiceDate" name="invoiceDate" class="form-control" v-model="invoiceDate"> <input type="date" id="invoiceDate" name="invoiceDate" class="form-control" v-model="invoiceDate" required>
</div> </div>
</div> </div>
@ -367,6 +367,8 @@
$('#addItemBtn').on('click', function () { $('#addItemBtn').on('click', function () {
// Show the modal with the ID 'addManufacturerModal'. // Show the modal with the ID 'addManufacturerModal'.
$('#registerItemModal').modal('show'); $('#registerItemModal').modal('show');
this.addSection = true;
this.editSection = false;
}); });
$('.closeModal').on('click', function () { $('.closeModal').on('click', function () {
// Show the modal with the ID 'addManufacturerModal'. // Show the modal with the ID 'addManufacturerModal'.
@ -394,19 +396,22 @@
teamType: "", teamType: "",
productName: null, productName: null,
imageProduct: null, imageProduct: null,
addSection: false,
editSection: false,
productCategory: null, productCategory: null,
itemID: null,
serialNumber: "", serialNumber: "",
quantity: 1, quantity: 1,
supplierName: null, supplierName: null,
purchaseDate: null, purchaseDate: null,
PO: null, PO: null,
currency: "MYR", currency: "MYR",
DefaultPrice: 0.01, DefaultPrice: null,
currencyRate: 1, currencyRate: 1,
convertPrice: 0.01, convertPrice: 0.01,
DONo: null, DONo: null,
DODate: null, DODate: null,
warranty: 0, warranty: null,
EndWDate: null, EndWDate: null,
invoiceNo: null, invoiceNo: null,
invoiceDate: null, invoiceDate: null,
@ -450,6 +455,19 @@
this.fetchCompanies(); this.fetchCompanies();
this.fetchProducts(); this.fetchProducts();
this.fetchSuppliers(); 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: { computed: {
filteredDepartments() { filteredDepartments() {
@ -462,7 +480,7 @@
}, },
showProduct() { showProduct() {
if (!this.selectedProduct) { 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); const product = this.products.find(c => c.productId === this.selectedProduct);
return product ? product : {}; return product ? product : {};
@ -473,6 +491,18 @@
}, },
methods: { methods: {
async addItem() { 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") { if (this.showProduct.category == "Disposable") {
this.serialNumber = ""; this.serialNumber = "";
} }
@ -489,9 +519,11 @@
DefaultPrice: this.DefaultPrice, DefaultPrice: this.DefaultPrice,
CurrencyRate: this.currencyRate, CurrencyRate: this.currencyRate,
ConvertPrice: this.convertPrice, ConvertPrice: this.convertPrice,
DONo: this.DONo,
DODate: this.DODate, DODate: this.DODate,
Warranty: this.warranty, Warranty: this.warranty,
EndWDate: this.EndWDate, EndWDate: this.EndWDate,
InvoiceNo: this.invoiceNo,
InvoiceDate: this.invoiceDate, InvoiceDate: this.invoiceDate,
CreatedByUserId: this.currentUser.id, CreatedByUserId: this.currentUser.id,
TeamType: this.selectedTeamType, TeamType: this.selectedTeamType,
@ -600,7 +632,7 @@
}, },
{ {
"title": "Price(RM)", "title": "Price(RM)",
"data": "convertPrice", "data": (row) => parseFloat(row.convertPrice).toFixed(2),
}, },
{ {
"title": "Register Date", "title": "Register Date",
@ -626,6 +658,15 @@
Station: ${currentStation}` Station: ${currentStation}`
} }
}, },
{
"title": "Edit",
"data": "itemID",
"render": function (data) {
var editButton = `<button type="button" class="btn btn-success edit-btn" data-id="${data}">Edit</button>`;
return editButton;
},
"className": "align-middle",
},
{ {
"title": "Delete", "title": "Delete",
"data": "itemID", "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 // Attach click event listener to the delete buttons
$('#itemDatatable tbody').off('click', '.delete-btn').on('click', '.delete-btn', function () { $('#itemDatatable tbody').off('click', '.delete-btn').on('click', '.delete-btn', function () {
const itemId = $(this).data('id'); const itemId = $(this).data('id');
@ -796,48 +843,6 @@
console.error('Error fetching currency data:', error); 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() { calculateWarrantyEndDate() {
// Check if DODate and warranty are valid // Check if DODate and warranty are valid
if (!this.DODate || isNaN(Date.parse(this.DODate))) { if (!this.DODate || isNaN(Date.parse(this.DODate))) {
@ -856,6 +861,51 @@
this.EndWDate = null; 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) { async deleteItem(itemId) {
if (!confirm("Are you sure you want to delete this item?")) { if (!confirm("Are you sure you want to delete this item?")) {
return; return;
@ -886,6 +936,127 @@
this.loading = false; 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) { async printItem(itemId, imgSrc) {
try { try {
this.thisQRInfo.uniqueID = itemId; this.thisQRInfo.uniqueID = itemId;
@ -960,7 +1131,7 @@
// Populate the virtual DOM with content // Populate the virtual DOM with content
virtualElement.innerHTML = ` virtualElement.innerHTML = `
<div class="container my-3 QrPrintFont" style="font-family: 'OCR A', monospace;"> <div class="container my-3 QrPrintFont" style="font-family: 'OCR A', monospace;">
<div class="row"> <div class="row">
<div class="col-5 text-center d-flex align-items-center justify-content-center"> <div class="col-5 text-center d-flex align-items-center justify-content-center">
<div class="row"> <div class="row">
@ -971,7 +1142,7 @@
</div> </div>
</div> </div>
<div class="col-7 d-flex align-items-center justify-content-left"> <div class="col-7 d-flex align-items-center justify-content-left">
<div class="row"> <div class="row-fluid">
<div class="col-12 h3"style="font-family: 'Verdana', monospace;"><b>${this.thisQRInfo.departmentName}</b></div> <div class="col-12 h3"style="font-family: 'Verdana', monospace;"><b>${this.thisQRInfo.departmentName}</b></div>
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.productShortName}</b></div> <div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.productShortName}</b></div>
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.serialNumber ?? "-"}</b></div> <div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.serialNumber ?? "-"}</b></div>