Update
This commit is contained in:
parent
6e44454808
commit
304b5e6d94
@ -80,14 +80,14 @@
|
||||
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
|
||||
<div class="modal-content">
|
||||
<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">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<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="row" data-aos="fade-right">
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
<div class="col-md-12">
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<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="col-md-6">
|
||||
|
||||
@ -288,7 +288,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="DONo" class="col-sm-4">Enter DO Number:</label>
|
||||
<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>
|
||||
|
||||
@ -296,7 +296,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="DODate" class="col-sm-4">Enter DO Date:</label>
|
||||
<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>
|
||||
|
||||
@ -304,7 +304,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="warranty" class="col-sm-4">Enter Warranty (Months):</label>
|
||||
<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>
|
||||
|
||||
@ -320,7 +320,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="invoiceNo" class="col-sm-4">Invoice Number:</label>
|
||||
<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>
|
||||
|
||||
@ -328,7 +328,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="invoiceDate" class="col-sm-4">Invoice Date:</label>
|
||||
<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>
|
||||
|
||||
@ -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 = `<button type="button" class="btn btn-success edit-btn" data-id="${data}">Edit</button>`;
|
||||
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;
|
||||
@ -971,7 +1142,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<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 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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user