NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/Receiving/RRReports.js
2026-01-20 07:44:30 +08:00

110 lines
4.1 KiB
JavaScript

let isSorting = false;
$(document).ready(function () {
loader = $('#overlay, #loader');
const reportTitle = `RR Report - as of ${getFormattedDateTime()}`;
receivingTable = $('#ReportTable').DataTable({
ajax: $.extend({
url: '/Receiving/GetRRReport',
type: 'GET',
data: function (d) {
d.dateFrom = $('#dateFrom').val();
d.dateTo = $('#dateTo').val();
d.isSorting = isSorting;
},
}, beforeComplete(loader)),
language: {
emptyTable: "No record available"
},
columns: colOnRRReport,
pageLength: 5,
lengthMenu: [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"]],
initComplete: function () {
initializeColumnSearch({
tableId: '#ReportTable',
dataTable: receivingTable,
searchableColumns: [
{
columnIndex: 0,
columnName: 'PR No',
placeholder: 'Enter PR Number...',
searchType: 'text',
searchMode: 'exact',
width: '150px'
},
{
columnIndex: 1,
columnName: 'Item No',
placeholder: 'Enter Item Number...',
searchType: 'text',
searchMode: 'exact',
width: '150px'
},
{
columnIndex: 4,
columnName: 'Item Name',
placeholder: 'Enter Item Name...',
searchType: 'text',
searchMode: 'contains',
width: '200px'
},
{
columnIndex: 11,
columnName: 'Department',
placeholder: 'Select Department...',
searchType: 'select',
searchMode: 'exact',
width: '150px'
}
]
});
const uniqueSearchClass = 'column-search-input-ReportTable';
populateSelectOptions(receivingTable, 11, '.' + uniqueSearchClass + '[data-column="11"]');
restoreSearchFromURL(uniqueSearchClass, '#ReportTable');
},
dom: 'lBfrtip',
buttons: [
{
extend: 'csv',
title: reportTitle
},
{
extend: 'excel',
title: reportTitle
}
],
error: errorHandler,
columnDefs: [
{
targets: '_all',
render: function (data, type, row) {
if (type === 'display' && data && data.length > 50) {
return '<div style="white-space: normal; word-wrap: break-word;">' + data + '</div>';
}
return data;
}
}
]
});
});
function sortByDate() {
// Custom sorting function for MM/DD/YYYY format
$.fn.dataTable.ext.type.order['date-custom-pre'] = function (d) {
// Parse date string in format MM/DD/YYYY
console.log('Sorting by custom date');
var dateParts = d.split('/');
return new Date(dateParts[2], dateParts[0] - 1, dateParts[1]).getTime();
};
isSorting = true;
// Trigger DataTable reload to apply the new sorting and date range filtering
$('#ReportTable').DataTable().ajax.reload();
}
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}`;
}