function renderItembtns(data, row) { var jsonData = JSON.stringify(row).replace(/"/g, """); var buttonsHtml = ''; buttonsHtml += ' '; return buttonsHtml; } function refreshTable() { itemTable.ajax.reload(); } function clearTextModal() { document.getElementById("ItemName").value = ""; document.getElementById("ItemDescription").value = ""; document.getElementById("ItemCategory").value = ""; document.getElementById("requestTypeId").value = ""; } function isFullFilled() { var itemNameInput = document.getElementById('itemName').value; var itemDescriptionInput = document.getElementById('itemDescription').value; var itemCategoryInput = document.getElementById('itemCategoryName').value; var itemLocalNameInput = document.getElementById('itemLocalName').value; var uomNameInput = document.getElementById('uomName').value; var itemQtyInput = document.getElementById('itemQty').value; var itemClassIdInput = document.getElementById('itemClassId').value; var packagingTypeIdInput = document.getElementById('packagingTypeId').value; var prTypeIdInput = document.getElementById('prTypeId').value; var itemColorIdInput = document.getElementById('itemColorId').value; if (!itemNameInput || !itemCategoryInput || itemQtyInput === '0' || !itemDescriptionInput || !itemLocalNameInput || !uomNameInput || !itemClassIdInput || !packagingTypeIdInput || !prTypeIdInput || !itemColorIdInput) { let btnAddToCart = document.getElementById('btnAddToCart'); btnAddToCart.style.display = 'none'; } else { let btnAddToCart = document.getElementById('btnAddToCart'); btnAddToCart.style.display = 'block'; } } $(document).ready(function () { loader = $('#overlay, #loader'); const reportTitle = `Item List - as of ${getFormattedDateTime()}`; let cartItemCount = $('#cartItemCount').val(); $('#cartCount').text(cartItemCount); const endpoint = '/ItemMgmt/GetItemList'; itemTable = $('#ItemTable').DataTable({ serverSide: true, processing: true, searching: false, ordering: false, ajax: { url: endpoint, type: 'GET', data: function (d) { return { draw: d.draw, searchItemNo: ($('#srchItemNo').val() || '').trim(), searchItemName: ($('#srchItem').val() || '').trim(), searchCategory: ($('#srchCategory').val() || '').trim(), pageNumber: Math.floor(d.start / d.length) + 1, pageSize: d.length }; }, dataSrc: function (json) { const $sel = $('#srchCategory'); if ($sel.find('option').length <= 1 && json.categoryList?.length) { json.categoryList.forEach(function (s) { $sel.append(``); }); } return json.data; }, beforeSend: function () { loader.show(); }, complete: function () { loader.hide(); }, }, dom: 'lBfrtip', buttons: [ { text: ' CSV', className: 'btn btn-sm btn-secondary', action: function () { exportAllData('csv', endpoint, loader, reportTitle, colOnItemList); } }, { text: ' Excel', className: 'btn btn-sm btn-success', action: function () { exportAllData('excel', endpoint, loader, reportTitle, colOnItemList); } }, { text: ' PDF', className: 'btn btn-sm btn-danger', action: function () { exportAllData('pdf', endpoint, loader, reportTitle, colOnItemList); } } ], columns: colOnItemList, order: [[0, 'desc']], responsive: true, language: { emptyTable: "Type in the search box to fetch data." } }); function debounce(fn, delay) { let t; return function (...args) { clearTimeout(t); t = setTimeout(() => fn.apply(this, args), delay); }; } $('#srchItem, #srchItemNo') .on('keyup', debounce(() => itemTable.ajax.reload(null, false), 400)); $('#srchCategory').on('change', function () { itemTable.ajax.reload(null, false); }); $('.aprv-search-clear').on('click', function () { $($(this).data('target')).val('').trigger('change'); }); }); function getFormattedDateTime() { const now = new Date(); const yyyy = now.getFullYear(); const mm = String(now.getMonth() + 1).padStart(2, '0'); const dd = String(now.getDate()).padStart(2, '0'); const hh = String(now.getHours()).padStart(2, '0'); const min = String(now.getMinutes()).padStart(2, '0'); const ss = String(now.getSeconds()).padStart(2, '0'); return `${yyyy}-${mm}-${dd}_${hh}${min}${ss}`; } document.addEventListener('DOMContentLoaded', function () { const triggers = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')); triggers.forEach(el => { new bootstrap.Tooltip(el, { container: 'body', boundary: 'window', }); }); });