@@ -288,7 +288,7 @@
@@ -296,7 +296,7 @@
@@ -304,7 +304,7 @@
@@ -320,7 +320,7 @@
@@ -328,7 +328,7 @@
@@ -367,8 +367,6 @@
$('#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'.
@@ -396,22 +394,19 @@
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: null,
+ DefaultPrice: 0.01,
currencyRate: 1,
convertPrice: 0.01,
DONo: null,
DODate: null,
- warranty: null,
+ warranty: 0,
EndWDate: null,
invoiceNo: null,
invoiceDate: null,
@@ -455,19 +450,6 @@
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() {
@@ -480,7 +462,7 @@
},
showProduct() {
if (!this.selectedProduct) {
- return []; // No company selected, return empty listx`
+ return []; // No company selected, return empty list
}
const product = this.products.find(c => c.productId === this.selectedProduct);
return product ? product : {};
@@ -491,18 +473,6 @@
},
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 = "";
}
@@ -519,11 +489,9 @@
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,
@@ -632,7 +600,7 @@
},
{
"title": "Price(RM)",
- "data": (row) => parseFloat(row.convertPrice).toFixed(2),
+ "data": "convertPrice",
},
{
"title": "Register Date",
@@ -658,15 +626,6 @@
Station: ${currentStation}`
}
},
- {
- "title": "Edit",
- "data": "itemID",
- "render": function (data) {
- var editButton = `
`;
- return editButton;
- },
- "className": "align-middle",
- },
{
"title": "Delete",
"data": "itemID",
@@ -690,8 +649,8 @@
return;
}
- container.innerHTML = "";
- container.append(data.uniqueID);
+ container.innerHTML = "";
+ container.append(data.uniqueID);
// Ensure qrString is valid before generating QR code
if (!data.qrString) {
@@ -712,12 +671,6 @@
}
})
- // 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');
@@ -843,6 +796,48 @@
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))) {
@@ -861,51 +856,6 @@
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;
@@ -926,7 +876,7 @@
.row($(`.delete-btn[data-id="${itemId}"]`).closest('tr'))
.remove()
.draw();
- }
+ }
}
catch (error) {
console.error("Error deleting item:", error);
@@ -936,127 +886,6 @@
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;
@@ -1069,7 +898,7 @@
// Safely set image content
const sanitizedImgSrc = encodeURI(imgSrc); // Sanitize the URL
- container.innerHTML = `

`;
+ container.innerHTML = `

`;
// Fetch QR information
const qrInfo = this.getPrintedQR(uniqueQR);
@@ -1123,26 +952,26 @@
printQRInfo() {
// Create a virtual DOM element
const virtualElement = document.createElement('div');
- virtualElement.style.width = '330px '; // Match label size for 2 inches at 203 DPI
- virtualElement.style.height = '160px';
+ virtualElement.style.width = '360px '; // Match label size for 2 inches at 203 DPI
+ virtualElement.style.height = '180px';
virtualElement.style.position = 'absolute';
virtualElement.style.left = '-9999px'; // Position offscreen to avoid rendering on the main UI
// virtualElement.style.border = '1px solid #000'; // Optional: Add a border for debugging dimensions
// Populate the virtual DOM with content
virtualElement.innerHTML = `
-
-
+
+
${this.thisQRInfo.imgContainer}
-
${this.thisQRInfo.uniqueID}
+
${this.thisQRInfo.uniqueID}
-
+
${this.thisQRInfo.departmentName}
${this.thisQRInfo.productShortName}
${this.thisQRInfo.serialNumber ?? "-"}
@@ -1176,7 +1005,7 @@
style: `
@@media print {
@@page {
- margin: 5px 5px 0px 5px;
+ margin: 0px 0px 0px 0px;
}
body { margin: 0; }
}