var UserRights; var inventTable; var inventDetailTable; var InventoryId; function hasRolePermission(role) { return UserRights.includes(role); } function renderItembtns(data, row) { var jsonData = JSON.stringify(row).replace(/"/g, """); var buttonsHtml = ''; // var statusNumber = parseInt(row.status, 10); buttonsHtml += ' '; return buttonsHtml; } function showHideLabelButtons(isNewOrUpdate) { //console.log('isNewOrUpdate: ' + isNewOrUpdate); if (isNewOrUpdate == 1) { let labelHeaderUpdate = document.getElementById('headerUpdate'); let btnUpdateLayoutType = document.getElementById('btnUpdateItem'); labelHeaderUpdate.style.display = 'none'; btnUpdateLayoutType.style.display = 'none'; let labelHeaderAddNew = document.getElementById('headerNew'); let btnAddNewLayoutType = document.getElementById('btnaddNewItem'); labelHeaderAddNew.style.display = 'block'; btnAddNewLayoutType.style.display = 'block'; } else { let labelHeaderAddNew = document.getElementById('headerNew'); let btnAddNewLayoutType = document.getElementById('btnaddNewItem'); labelHeaderAddNew.style.display = 'none'; btnAddNewLayoutType.style.display = 'none'; let labelHeaderUpdate = document.getElementById('headerUpdate'); let btnUpdateLayoutType = document.getElementById('btnUpdateItem'); labelHeaderUpdate.style.display = 'block'; btnUpdateLayoutType.style.display = 'block'; } } function showModalNewItem() { clearTextModal(); let update = 1; showHideLabelButtons(update); $('#addNewItem').modal('show'); } function showAndUpdate(data) { showHideLabelButtons(2); $('#lotId').val(data.lotId); $('#lotName').val(data.lotName); $('#addNewItem').modal('show'); } function clearTextModal() { document.getElementById("lotName").value = ""; document.getElementById("lotTypeId").value = ""; } function postPutLotNo(isSave) { var loader = $('#overlay, #loader').css('z-index', 1060); console.log('isSave', isSave); const lotNameInput = document.getElementById('lotName'); const lotTypeIdInput = document.getElementById('lotTypeId'); var LotId = document.getElementById('lotId').value; const LotName = lotNameInput.value; const LotTypeId = lotTypeIdInput.value; if (!LotName || !LotTypeId) { alert('Please fill the required fields !'); if (!LotName) { lotNameInput.classList.add('error-input'); } if (!LotTypeId) { lotTypeIdInput.classList.add('error-input'); } return; } const confirmation = confirm('Are you sure you want to proceed?'); if (confirmation) { $.ajax({ url: '/InventoryMgmt/PostPutLotNo', type: 'POST', data: { LotName, LotTypeId, LotId }, success: function (response) { if (response.success) { inventTable.ajax.reload(); $('#addNewItem').modal('hide'); if (isSave == 1) { alert('Lot Save Successfully'); } else { alert('Lot Updated Successfully'); } } else { itemTable.ajax.reload(); alert('Failed: ' + response.response); } }, beforeSend: function () { // Show the loader before making the AJAX request loader.show(); }, complete: function () { // Hide the loader after the AJAX request is complete (success or error) loader.hide(); } }); } } $(document).ready(function () { var loader = $('#overlay, #loader'); UserRights = document.getElementById("roleRights").value; inventTable = $('#PRTable').DataTable({ ajax: { url: '/InventoryMgmt/GetLotNo', // Replace with your API endpoint type: 'GET', beforeSend: function () { // Show the loader before making the AJAX request loader.show(); }, complete: function () { loader.hide(); } }, // Check for the "No Data" response and display the message initComplete: function () { var api = this.api(); var data = api.ajax.json(); if (!data || !data.data || data.data === "No Data") { // Display the "No record available" message $('.dataTables_empty').html("No record available"); } }, columns: [ { data: 'lotId' }, { data: 'lotName' }, { data: 'lotTypeName' }, { data: 'createdBy' }, { data: 'createdDate' }, { data: 'updatedBy' }, { data: 'updatedDate' }, { data: null, render: function (data, type, row) { return renderItembtns(data, row); } }, ], responsive: true, language: { emptyTable: "No record available" }, error: function (xhr, error, thrown) { console.log('DataTables error:', error); console.log('Status:', Status); console.log('Details:', xhr.responseText); window.location.href = '/Home/Logout'; } }); }) function removeErrorClass() { if (this.value.trim() !== '') { this.classList.remove('error-input'); } }