function unlockFormLink(data) { loader = $('#overlay, #loader').css('z-index', 1075); const CanvassSupplierId = data.canvassSupplierId; showConfirmation({ title: 'Unlock Form Link', message: 'Are you sure you want to unlock the form link for this item? This change is irreversible.', type: 'warning', confirmText: 'Unlock', cancelText: 'Cancel' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: endpoint.UnlockFormLink, type: 'POST', data: { CanvassSupplierId }, success: function (response) { if (response.success) { refreshBidTable(); showToast('success', 'Formlink has been unlock successfully!', 'success', 4000); } else { refreshBidTable(); showToast('success', response.response, 'success', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function putSuppUnitPrice() { loader = $('#overlay, #loader').css('z-index', 1075); CanvassDetailId = document.getElementById('canvassDetailId').value; const unitPriceInput = document.getElementById('unitPrice'); unitPriceInput.addEventListener('input', removeErrorClass); const UnitPrice = unitPriceInput.value; if (!UnitPrice || UnitPrice==0) { alert('UnitPrice must not be less than zero (0)!'); if (!UnitPrice) { unitPriceInput.classList.add('error-input'); } return; } const confirmation = confirm('Are you sure you want to proceed?'); if (confirmation) { $.ajax($.extend({ url: '/CanvassMgmt/PutSuppUnitPrice', type: 'POST', data: { CanvassDetailId, UnitPrice }, success: function (response) { if (response.success) { $('#viewSupplierBid').modal('hide'); refreshBidTable(); alert('UnitPrice Updated!'); } else { refreshBidTable(); alert('Failed: ' + response.response); } }, error: errorHandler }, beforeComplete(loader))); } } function putSuppBidDetails(IsReset) { loader = $('#overlay, #loader').css('z-index', 1075); if (!validateParamSuppItem()) { return; } CurrencyId = $('#currencyId').val(); CanvassDetailId = $('#canvassDetailId').val(); let Manufacturer = $('#manufacturer').val(); let Remarks = $('#supplierRemarks').val(); showConfirmation({ title: 'Offer update', message: 'Are you sure you want to update this item? This action cannot be undone.', type: 'warning', confirmText: 'Yes, Update', cancelText: 'Keep Item' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: endpoint.PutSuppBidDetails, type: 'POST', data: { CanvassDetailId, UnitPrice, PRDetailsId, Terms, ItemName, Specification, Qty, CommitmentDate, CurrencyId, Manufacturer, Remarks, UOMName, IsReset }, success: function (response) { if (response.success) { $('#viewSupplierBid').modal('hide'); refreshBidTable(); showToast('success', 'Offer Details Updated!', 'Success', 4000); } else { showToast('error', response.response, 'Offer update failed', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function validateParamSuppItem() { let isValid = true; const termsInput = document.getElementById('terms'); const itemNameInput = document.getElementById('itemName'); const specificationInput = document.getElementById('specification'); const qtyInput = document.getElementById('itemQty'); const commitmentDateInput = document.getElementById('commitmentDate'); const unitPriceInput = document.getElementById('unitPrice'); const uomInput = document.getElementById('uom'); unitPriceInput.addEventListener('input', removeErrorClass); termsInput.addEventListener('input', removeErrorClass); itemNameInput.addEventListener('input', removeErrorClass); specificationInput.addEventListener('input', removeErrorClass); qtyInput.addEventListener('input', removeErrorClass); commitmentDateInput.addEventListener('input', removeErrorClass); uomInput.addEventListener('input', removeErrorClass); UnitPrice = unitPriceInput.value; Terms = termsInput.value; ItemName = itemNameInput.value; Specification = specificationInput.value; Qty = qtyInput.value; UOMName = uomInput.value; if (!UnitPrice || UnitPrice == 0 || !Terms || !ItemName || !Specification || !Qty || !CommitmentDate || !UOMName) { alert('Please fill required fields!'); if (!UnitPrice) { unitPriceInput.classList.add('error-input'); } if (!Terms) { termsInput.classList.add('error-input'); } if (!ItemName) { itemNameInput.classList.add('error-input'); } if (!Specification) { specificationInput.classList.add('error-input'); } if (!Qty) { qtyInput.classList.add('error-input'); } if (!CommitmentDate) { commitmentDateInput.classList.add('error-input'); } if (!UOMName) { uomInput.classList.add('error-input'); } isValid = false; return isValid; } return isValid; } function holdItem(isApprove) { loader = $('#overlay, #loader').css('z-index', 1080); var Remarks = document.getElementById('deniedRemarks').value; if (isApprove === 3 && !Remarks) { showToast('warning', 'Please put remarks!', 'warning', 4000); return; } showConfirmation({ title: 'Denying Item', message: 'Are you sure you want to deny this item? This change is irreversible.', type: 'warning', confirmText: 'Deny', cancelText: 'Keep Item' }).then((confirmed) => { if (confirmed) { ItemNo = document.getElementById("itemNo").value; var Status = isApprove; $.ajax($.extend({ url: '/PRMgmt/PostPRApproveReject', type: 'POST', data: { ItemNo: ItemNo, Status: Status, PRDetailsId: PRDetailsId, Remarks: Remarks }, success: function (response) { if (response.success) { PRItemTable.ajax.reload(null, false); $('#viewPRItemDetails').modal('hide'); $('#addRemarksUpdate').modal('hide'); showToast('success', `${ItemNo} : Item hold successfully!`, 'success', 4000); } else { PRItemTable.ajax.reload(null, false); showToast('error', response.response, 'failed', 4000); } }, }, beforeComplete(loader))); } }); } function deniedItem(isApprove) { loader = $('#overlay, #loader').css('z-index', 1080); const remarksInput = document.getElementById('denied-remarks'); const itemName = $('#itemName').val(); const itemNo = $('#denied-itemNo').val(); const prDetailsId = $('#prDetailsId').val(); remarksInput.removeEventListener('input', removeErrorClass); remarksInput.addEventListener('input', removeErrorClass); const remarks = remarksInput.value.trim(); if (!remarks) { alert('Please put remarks!'); remarksInput.classList.add('error-input'); return; } const confirmation = confirm(`Are you sure you want to deny this item: ${itemName}?`); if (confirmation) { $.ajax($.extend({ url: endpoint.PostPRApproveReject, type: 'POST', data: { ItemNo: itemNo, Status: isApprove, PRDetailsId: prDetailsId, Remarks: remarks }, success: function (response) { if (response.success) { $('#viewDeniedForm').modal('hide'); $('#denied-remarks').val(''); alert(`${itemName}: Item Hold!`); } else { alert('Failed: ' + response.response); } } }, beforeComplete(loader))); } } function postCanvass() { loader = $('#overlay, #loader').css('z-index', 1070); SupplierId = document.getElementById('supplierId').value; const selectedItems = Object.values(selectedProductsMap); if (selectedItems.length === 0) { showToast('warning', 'Please select items for canvass first!', 'Canvass failed', 4000); return; } const CanvassList = selectedItems.map(item => { return { prNo: item.prNo, prDetailsId: item.prDetailsId, itemNo: item.itemNo }; }); const Status = 1; showConfirmation({ title: 'RFQ Submission', message: 'Are you sure you want to submit this request for quotation? This action cannot be undone.', type: 'warning', confirmText: 'Yes, Submit', cancelText: 'No' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: '/CanvassMgmt/PostCanvass', type: 'POST', data: { SupplierId: SupplierId, Status: Status, CanvassList: CanvassList }, success: function (response) { if (response.success) { $('#viewItemSuppliers').modal('hide'); $('#viewItemList').modal('hide'); canvassTable.ajax.reload(null, false); showToast('success', 'RFQ Successfully Sent!', 'success!', 4000); } else { refreshCanvasTable(); showToast('error', response.response, 'Submission of canvass failed!', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function postPutSupplier(isNew) { var loader = $('#overlay, #loader').css('z-index', 1065); if (isNew != 1) { var SupplierId = document.getElementById("supplierId").value; } var Address = document.getElementById("address").value; var ContactNo = document.getElementById("contactNo").value; var ContactPerson = document.getElementById("contactPerson").value; const supplierNameInput = document.getElementById('supplierName'); const emailAddressInput = document.getElementById('emailAddress'); supplierNameInput.addEventListener('input', removeErrorClass); emailAddressInput.addEventListener('input', removeErrorClass); const SupplierName = supplierNameInput.value; const EmailAddress = emailAddressInput.value; if (!validateEmailAddress(EmailAddress)) { alert('Please input a valid email address!'); emailAddressInput.classList.add('error-input'); return; } var IsActive = document.getElementById("isActive").value === "true"; if (!EmailAddress || !SupplierName) { alert('Please fill the required fields !'); if (!EmailAddress) { emailAddressInput.classList.add('error-input'); } if (!SupplierName) { supplierNameInput.classList.add('error-input'); } return; } const confirmation = confirm('Are you sure you want to proceed?'); if (confirmation) { $.ajax($.extend({ url: '/CanvassMgmt/PostPutSupplier', type: 'POST', data: { SupplierId, SupplierName, EmailAddress, IsActive, ItemNo, Address, ContactNo, ContactPerson }, success: function (response) { if (response.success) { if (response.success) { $('#addNewEditSupplier').modal('hide'); supplierDataTable.ajax.reload(null, false); alert(isNew == 1 ? 'Supplier Successfully Added!' : 'Supplier Successfully Updated!'); } else { alert('Failed: ' + response.response); } } else { refreshCanvasTable(); alert('Failed: ' + response.response); } }, error: errorHandler }, beforeComplete(loader))); } } function postPutMySupplier(isNew) { loader = $('#overlay, #loader').css('z-index', 1065); var Address = document.getElementById("address").value; var ContactNo = document.getElementById("contactNo").value; var ContactPerson = document.getElementById("contactPerson").value; const supplierNameInput = document.getElementById('supplierName'); const emailAddressInput = document.getElementById('emailAddress'); supplierNameInput.addEventListener('input', removeErrorClass); emailAddressInput.addEventListener('input', removeErrorClass); const SupplierName = supplierNameInput.value; const EmailAddress = emailAddressInput.value; if (!validateEmailAddress(EmailAddress)) { showToast('error', 'Please input a valid email address!', 'Updating failed!', 4000); emailAddressInput.classList.add('error-input'); return; } var TinNo = $('#tinNo').val(); var LeadTime = $('#leadTime').val(); var CurrencyId = $('#currencyId').val(); var VatInc = $('#vatInc').prop('checked'); var PaymentTermsId = $('#C-paymentTermsId').val(); var IsActive = document.getElementById("isActive").value === "true"; if (!EmailAddress || !SupplierName) {; showToast('error', 'Please fill the required fields!', 'Tagging failed!', 4000); if (!EmailAddress) { emailAddressInput.classList.add('error-input'); } if (!SupplierName) { supplierNameInput.classList.add('error-input'); } return; } showConfirmation({ title: 'Item Tagging', message: 'Are you sure you want to tag this item? This action cannot be undone.', type: 'warning', confirmText: 'Yes, Submit', cancelText: 'No' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: '/CanvassMgmt/PostPutMySupplier', type: 'POST', data: { SupplierId, SupplierName, EmailAddress, IsActive, ItemNo, Address, ContactNo, ContactPerson, TinNo, LeadTime, CurrencyId, VatInc, PaymentTermsId }, success: function (response) { if (response.success) { if (response.success) { $('#addNewEditSupplier').modal('hide'); supplierDataTable.ajax.reload(null, false); showToast('success', isNew == 1 ? 'Supplier Successfully Added!' : 'Supplier Successfully Updated!', 'success!', 4000); } else { showToast('error', response.response, 'Submission of canvass failed!', 4000); } } else { supplierDataTable.ajax.reload(null, false); showToast('error', response.response, 'Submission of canvass failed!', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function postTaggingSupplier() { loader = $('#overlay, #loader').css('z-index', 1070); const selectedItems = Object.values(selectedProductsMap); if (selectedItems.length === 0) { showToast('error', 'No selected supplier!', 'Tagging failed!', 4000); return; } const SupplierList = selectedItems.map(item => { return { SupplierId: item.supplierId }; }); showConfirmation({ title: 'Item Tagging', message: 'Are you sure you want to tag this item? This action cannot be undone.', type: 'warning', confirmText: 'Yes, Submit', cancelText: 'No' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: '/CanvassMgmt/PostTaggingSupplier', type: 'POST', data: { SupplierList, ItemNo }, success: function (response) { if (response.success) { reloadAllTables(); showToast('success', 'Tagging Successfully!', 'success!', 4000); } else { supplierDataTable.ajax.reload(null, false); showToast('error', response.response, 'Submission of canvass failed!', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function safeReload(tableId) { if ($.fn.DataTable.isDataTable(tableId)) { $(tableId).DataTable().ajax.reload(null, false); } } function reloadAllTables() { ['#SupplierDataTable', '#prWOEDataTable', '#PRTable', '#ItemDataTable'] .forEach(safeReload); } function postPutItemTagging() { loader = $('#overlay, #loader').css('z-index', 1070); let IsActive = $('#isActive-status').val(); const selectedItems = Object.values(selectedProductsMap); if (selectedItems.length === 0) { showToast('error', 'No selected item!', 'Tagging failed!', 4000); return; } const ItemList = selectedItems.map(item => { return { ItemNo: item.itemNo }; }); SupplierId = $('#supplierId').val(); showConfirmation({ title: 'Item Tagging', message: 'Are you sure you want to tag this item? This action cannot be undone.', type: 'warning', confirmText: 'Yes, Submit', cancelText: 'No' }).then((confirmed) => { if (confirmed) { $.ajax($.extend({ url: endpoint.PostPutItemTagging, type: 'POST', data: { ItemList, SupplierId, IsActive }, success: function (response) { if (response.success) { supplierDataTable.ajax.reload(null, false); let query = $('#filterType').val(); viewPRForTagging('data', query); document.getElementById('totalSelTag').innerHTML = 0; if (IsActive == 'true') { showToast('success', 'Tagged Successfully!', 'success!', 4000); } else { showToast('success', 'Un-Tagged Successfully!', 'success!', 4000); } } else { supplierDataTable.ajax.reload(null, false); showToast('error', response.response, 'Submission of canvass failed!', 4000); } }, error: errorHandler }, beforeComplete(loader))); } }); } function postApprovedSupp() { var loader = $('#overlay, #loader').css('z-index', 1070); var CanvassId = document.getElementById('canvassId').value; const confirmation = confirm('Are you sure you want to proceed?'); if (confirmation) { $.ajax($.extend({ url: endpoint.PostApprovedSupp, type: 'POST', data: { CanvassId, ItemNo }, success: function (response) { if (response.success) { $('#viewSupplierBid').modal('hide'); $('#viewByItemSupplier').modal('hide'); refreshBidTable(); alert('Canvass Forwarded!'); } else { refreshBidTable(); alert('Failed: ' + response.response); } }, error: errorHandler }, beforeComplete(loader))); } } function postSuggestedSupp() { var loader = $('#overlay, #loader').css('z-index', 1070); CanvassDetailId = document.getElementById('canvassDetailId').value; ItemNo = document.getElementById('itemNo').value; SupplierId = document.getElementById('supplierId').value; const confirmation = confirm('Are you sure you want to proceed?'); if (confirmation) { $.ajax($.extend({ url: endpoint.PostSuggestedSupp, type: 'POST', data: { CanvassDetailId, ItemNo, SupplierId, CanvassId }, success: function (response) { if (response.success) { $('#viewSupplierBid').modal('hide'); refreshBidTable(); alert('Suggested Supplier Updated!'); } else { refreshBidTable(); alert('Failed: ' + response.response); } }, error: errorHandler }, beforeComplete(loader))); } } function clearTextModal() { $('#supplierName').val(""); $('#emailAddress').val(""); $('#contactPerson').val(""); $('#contactNo').val(""); $('#address').val(""); $('#tinNo').val(""); $('#leadTime').val(""); $('#C-paymentTerms').val(""); SupplierId = 0; } function refreshCanvasTable() { if ($.fn.dataTable.isDataTable('#supplierTable')) { $('#supplierTable').DataTable().ajax.reload(null, false); } if ($.fn.dataTable.isDataTable('#prTable')) { $('#prTable').DataTable().ajax.reload(null, false); } } function refreshSupplierTable() { supplierDataTable.ajax.reload(null, false); }