function populatePONoElem(id) { loader = $('#overlay, #loader').css('z-index', 1060); $.ajax($.extend({ url: endpoint.GetLatestPO2, type: 'POST', success: function (data) { if (data && data.data && data.data.length > 0) { var item = data.data[0]; $('#si-poNo').val('00' + (parseFloat(item.poNoVatInc) + 1)); $('#dr-poNo').val(parseFloat(item.poNoVatEx) + 1); $('#si-ImportPoNo').val('10-' + (parseFloat(item.ipoNoVatInc) + 1)); $('#dr-ImportPoNo').val(item.ipoNoVatEx); getPONoType(id); } else { console.log('Data is null or undefined'); } }, error: errorHandler }, beforeComplete(loader))); } function populatePOElem(id) { loader = $('#overlay, #loader').css('z-index', 1060); $.ajax($.extend({ url: endpoint.GetLatestPO2, type: 'POST', success: function (data) { if (data && data.data && data.data.length > 0) { var item = data.data[0]; $('#si-poNo').val('00' + (parseFloat(item.poNoVatInc) + 1)); $('#dr-poNo').val(parseFloat(item.poNoVatEx) + 1); $('#si-ImportPoNo').val('10-' + (parseFloat(item.ipoNoVatInc) + 1)); $('#dr-ImportPoNo').val(item.ipoNoVatEx); getPOType(id); } else { console.log('Data is null or undefined'); } }, error: errorHandler }, beforeComplete(loader))); } function populateIncoterms() { $.ajax({ url: endpoint.GetIncoterms, success: function (response) { if (response && response.success && Array.isArray(response.data)) { var $incotermsName = $('#incotermsName'); $incotermsName.empty(); response.data.forEach(function (item) { var option = $('') .attr('value', item.incotermsId) .text(item.incotermsName); $incotermsName.append(option); }); if (response.data.length > 0) { var firstItem = response.data[0]; $incotermsName.val(firstItem.incotermsId); $('#incoTermsId').val(firstItem.incotermsId); } $incotermsName.on('change', function () { var selectedincotermsId = $(this).val(); $('#incoTermsId').val(selectedincotermsId); console.log(selectedincotermsId); }); } else { console.error('Invalid data format received:', response); } }, error: function (error) { console.error('Error fetching payment terms:', error); } }); } function popTerms() { $("#P-paymentTerms").autocomplete({ source: function (request, response) { $.ajax({ url: endpoint.GetPaymentTerms, data: { query: request.term }, success: function (result) { if (result && result.success && Array.isArray(result.data)) { var formattedData = result.data.map(item => ({ label: item.label || '', value: item.value !== undefined && item.value !== null ? item.value.toString() : '' })); response(formattedData); } else { console.error('Invalid data format received:', result); response([]); } } }); }, minLength: 2, select: function (event, ui) { $('#P-paymentTerms').val(ui.item.label); $('#P-paymentTermsId').val(ui.item.value); return false; }, focus: function (event, ui) { event.preventDefault(); }, open: function () { var dropdown = $(".ui-autocomplete"); dropdown.css({ "max-height": "200px", "overflow-y": "auto" }); }, messages: { noResults: '', results: function (count) { return count + (count > 1 ? ' results' : ' result'); } } }); } function popPortOfDisCharge() { $("#P-portOfDischarge").autocomplete({ source: function (request, response) { $.ajax({ url: endpoint.GetPortOfDischarge, data: { query: request.term }, success: function (result) { if (result && result.success && Array.isArray(result.data)) { var formattedData = result.data.map(item => ({ label: item.label || '', value: item.value !== undefined && item.value !== null ? item.value.toString() : '' })); response(formattedData); } else { console.error('Invalid data format received:', result); response([]); } } }); }, minLength: 2, select: function (event, ui) { $('#P-portOfDischarge').val(ui.item.label); $('#P-portOfDischarge-id').val(ui.item.value); return false; }, focus: function (event, ui) { event.preventDefault(); }, open: function () { var dropdown = $(".ui-autocomplete"); dropdown.css({ "max-height": "200px", "overflow-y": "auto" }); }, messages: { noResults: '', results: function (count) { return count + (count > 1 ? ' results' : ' result'); } } }); } function populateSupplier() { $("#supplierName").autocomplete({ source: function (request, response) { $.ajax({ url: endpoint.GetSuppliers, data: { query: request.term }, success: function (result) { if (result && result.success && Array.isArray(result.data)) { var formattedData = result.data.map(item => ({ label: item.label || '', value: item.value !== undefined && item.value !== null ? item.value.toString() : '', value2: item.value2 !== undefined && item.value2 !== null ? item.value2.toString() : '', value3: item.value3 !== undefined && item.value3 !== null ? item.value3.toString() : '', value4: item.value4 !== undefined && item.value4 !== null ? item.value4.toString() : '' })); response(formattedData); } else { console.error('Invalid data format received:', result); response([]); } } }); }, minLength: 2, select: function (event, ui) { $('#supplierName').val(ui.item.label); $('#supplierId').val(ui.item.value); $('#currency').val(ui.item.value2); $('#C-paymentTerms').val(ui.item.value3); $('#C-paymentTermsId').val(ui.item.value4); return false; }, focus: function (event, ui) { event.preventDefault(); }, open: function () { var dropdown = $(".ui-autocomplete"); dropdown.css({ "max-height": "200px", "overflow-y": "auto" }); }, messages: { noResults: '', results: function (count) { return count + (count > 1 ? ' results' : ' result'); } } }); } function populateDropdown(selector, value) { const $dropdown = $(selector); $dropdown.empty(); $('').val(value).text(value).appendTo($dropdown); $dropdown.val(value); }