92 lines
3.5 KiB
JavaScript
92 lines
3.5 KiB
JavaScript
$(document).ready(function () {
|
|
const reportTitle = `PR Tracking - as of ${getFormattedDateTime()}`;
|
|
|
|
loader = $('#overlay, #loader');
|
|
var prTable = $('#PRTable').DataTable({
|
|
serverSide: true,
|
|
processing: true,
|
|
searching: false,
|
|
ajax: {
|
|
url: endpoint.GetDetailedPRTracking,
|
|
type: 'GET',
|
|
data: function (d) {
|
|
return {
|
|
draw: d.draw,
|
|
searchPRNo: ($('#srchPRNo').val() || '').trim(),
|
|
searchItemName: ($('#srchItem').val() || '').trim(),
|
|
searchDept: ($('#srchDept').val() || '').trim(),
|
|
searchStatusName: ($('#srchStatus').val() || '').trim(),
|
|
pageNumber: Math.floor(d.start / d.length) + 1,
|
|
pageSize: d.length
|
|
};
|
|
},
|
|
dataSrc: function (json) {
|
|
const $sel = $('#srchStatus');
|
|
if ($sel.find('option').length <= 1 && json.statusList?.length) {
|
|
json.statusList.forEach(function (s) {
|
|
$sel.append(`<option value="${s}">${s}</option>`);
|
|
});
|
|
}
|
|
return json.data;
|
|
},
|
|
beforeSend: function () { loader.show(); },
|
|
complete: function () { loader.hide(); },
|
|
error: function (xhr, error) {
|
|
loader.hide();
|
|
if (typeof toastr !== 'undefined')
|
|
toastr.error('Failed to load data. Please try again.');
|
|
}
|
|
},
|
|
dom: 'lBfrtip',
|
|
buttons: [
|
|
{
|
|
text: '<i class="fas fa-file-csv"></i> CSV',
|
|
className: 'btn btn-sm btn-secondary',
|
|
action: function () { exportAllData('csv', endpoint.GetDetailedPRTracking, loader, reportTitle, colOnPRtracking); }
|
|
},
|
|
{
|
|
text: '<i class="fas fa-file-excel"></i> Excel',
|
|
className: 'btn btn-sm btn-success',
|
|
action: function () { exportAllData('excel', endpoint.GetDetailedPRTracking, loader, reportTitle, colOnPRtracking); }
|
|
},
|
|
{
|
|
text: '<i class="fas fa-file-pdf"></i> PDF',
|
|
className: 'btn btn-sm btn-danger',
|
|
action: function () { exportAllData('pdf', endpoint.GetDetailedPRTracking, loader, reportTitle, colOnPRtracking); }
|
|
}
|
|
],
|
|
columns: colOnPRtracking,
|
|
rowCallback: rowStatusColorCallback,
|
|
language: { emptyTable: "No approved records available" }
|
|
});
|
|
|
|
function debounce(fn, delay) {
|
|
let t;
|
|
return function (...args) {
|
|
clearTimeout(t);
|
|
t = setTimeout(() => fn.apply(this, args), delay);
|
|
};
|
|
}
|
|
|
|
$('#srchPRNo, #srchItem, #srchDept')
|
|
.on('keyup', debounce(() => prTable.ajax.reload(), 400));
|
|
|
|
$('#srchStatus').on('change', function () {
|
|
prTable.ajax.reload();
|
|
});
|
|
|
|
$('.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}`;
|
|
} |