File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/report/SupportSLAsummaryReport.js
Back
$(document).ready(function() { window.jsPDF = window.jspdf.jsPDF; var data_set = []; var date_from = ''; var date_to = ''; var totalRecords = 0; // var totalClosedTicket = 0; // var totalOngoingTicket = 0; var total_sla = 0; $('.btn-submit').click(function(e) { e.preventDefault(); $('#progrss-loading-bar').css('width', 0 + '%'); $('#progrss-loading-bar').text(0 + '%'); $('#progrss-loading-bar').attr('aria-valuenow', 0); $("#btn-pdf").hide(); $("#btn-table").hide(); data_set = []; // let comp_code = $("#multiple-select-clear-field-company").val(); // let dealer_code = $("#multiple-select-clear-field-dealer").val(); let from_date = $("#from_date").val(); let to_date = $("#to_date").val(); let ticket_status = $("#ticket_status").val(); $.ajax({ url: "/reports/get/support_sla_masterfile?page=1", type: "POST", data: { from_date: from_date, to_date: to_date, status : ticket_status, }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result) { console.log(result); totalRecords = 0; // totalClosedTicket = 0; // totalOngoingTicket = 0; total_sla = 0; data_set.push(...result.data); date_from = result.date_from; date_to = result.date_to; totalRecords = result.total_records; // totalClosedTicket = result.total_closed_ticket; // totalOngoingTicket = result.total_ongoing_ticket; // total_sla = result.total_sla_ticket; $('#loading-modal').modal('show'); if (result.total_records == 0 || result.total_page == 1) { $('#progrss-loading-bar').css('width', 100 + '%'); $('#progrss-loading-bar').text(100 + '%'); $("#btn-pdf").show(); $("#btn-table").show(); } if(result.total_page > 1){ fetchData(result.total_page,from_date,to_date,ticket_status); } }, error: function(xhr, status, error) { // Hide loading indicator // Handle error response console.error(xhr.responseText); alert('Error processing data. Please try again.'); } }); $("#close-moda-btn").on('click', function() { data_set = []; }); }); async function collectData(page,from_date,to_date,ticket_status) { return new Promise(function(resolve, reject) { $.ajax({ url: "/reports/get/support_sla_masterfile?page=" + page, type: "POST", data: { from_date: from_date, to_date: to_date, status: ticket_status }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(response) { resolve(response); }, error: function(xhr, status, error) { reject(error); } }); }); } async function fetchData(totalPages,from_date,to_date,ticket_status) { for (var i = 2; i <= totalPages; i++) { console.log('i...'); console.log(i); console.log('totalPages '+totalPages); if (i != 0 && i > 1) { try { const response = await collectData(i,from_date,to_date,ticket_status); var loadingPercentage = computeLoadingPercentage(response.currentPage, response .total_records, response.total_page, response.perPage); incPercent = Math.floor(loadingPercentage); console.log(incPercent); $('#progrss-loading-bar').attr('aria-valuenow', incPercent); $('#progrss-loading-bar').css('width', incPercent+ '%'); $('#progrss-loading-bar').text(incPercent + '%'); data_set.push(...response.data); console.log('loading percent '+loadingPercentage ) if (incPercent == 100) { isDone = true; $("#btn-pdf").show(); $("#btn-table").show(); // $("#txt-center-lable").hide(); } } catch (error) { console.error(error); } } } } function computeLoadingPercentage(currentPage, totalRows, totalPageCount, rowsPerPage) { totalPageCount = Math.ceil(totalRows / rowsPerPage); const loadedPageCount = Math.min(currentPage, totalPageCount); return (loadedPageCount / totalPageCount) * 100; } $("#btn-pdf").on('click', function() { generatePDFtable(data_set); }); $("#btn-table").on('click', function() { generateExcel(data_set); }); function generatePDFtable(data) { console.log(data); var doc = new jsPDF({ orientation: 'portrait', format: 'a4' }); // Get the page dimensions var margin =10; var pageSize =doc.internal.pageSize; var pageWidth = pageSize.width; var pageHeight = pageSize.height; var contentWidth = pageWidth - margin * 2; var borderHeight = 40; var height = 5; var maxHeight = pageHeight - margin; var currentPage = 1; var imgWidth = 30; var imgHeight = 20; var imgY = 10; doc.addImage(logo, 'PNG', pageWidth - 40, imgY, imgWidth, imgHeight); var addFooter = function() { var totalPages = doc.internal.getNumberOfPages(); doc.setFontSize(6); for (var i = 1; i <= totalPages; i++) { doc.setPage(i); if (i === totalPages) { doc.text('Page ' + i + ' of ' + totalPages, contentWidth/2, doc.internal.pageSize.getHeight() - 8); } else { doc.text('Page ' + i + ' of ' + totalPages, contentWidth/2, doc.internal.pageSize.getHeight() - 3); } } }; var startXtitle = 10; doc.setFont('sans serif', 'bold'); doc.setFontSize(10); doc.text('Support SLA Masterfile', pageWidth /2, 10,'center'); doc.setFont('sans serif', 'normal') doc.setFontSize(8); const setDateFrom = new Date(date_from); const DateFrom_formattedDateTime = setDateFrom.toLocaleString('en-US', { // weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', // hour: 'numeric', // minute: 'numeric', // second: 'numeric', // hour12: true // Include AM/PM indicator }); const setDateTo = new Date(date_to); const DateTo_formattedDateTime = setDateTo.toLocaleString('en-US', { // weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }); doc.text('Date range:', startXtitle, 15); doc.text(DateFrom_formattedDateTime + ' to ' + DateTo_formattedDateTime, 28, 15); // doc.setFont('sans serif', 'normal') // doc.text('Closed :', 90, 15); // doc.setFont('sans serif', 'italic'); // doc.text(totalClosedTicket.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), 107, 15); // doc.setFont('sans serif', 'normal') // doc.text('Prepared by :',startXtitle, 19); // doc.setFont('sans serif', 'italic'); // doc.text(employee_name,28, 19); doc.setFont('sans serif', 'normal') doc.text('Prepared date :', startXtitle, 19); doc.setFont('sans serif', 'italic'); let now = new Date(); const formattedDateTime = now.toLocaleString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true // Include AM/PM indicator }); doc.text(formattedDateTime, 28, 19); // doc.setFont('sans serif', 'normal') // doc.text('Ongoing :', 90, 19); // doc.setFont('sans serif', 'italic'); // // doc.text(totalOngoingTicket.toString(), 107, 19); // doc.setFont('sans serif', 'normal') // doc.text('Total SLA :', 90, 23); // doc.setFont('sans serif', 'italic'); // // doc.setFont(undefined, 'bold'); set italic to bold // doc.text((total_sla / 60).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' hrs.', // 107, 23); doc.setFont('sans serif', 'normal') doc.text('Prepared by :', startXtitle, 23); doc.setFont('sans serif', 'italic'); doc.text(employee_name, 28, 23); doc.setFont('sans serif', 'normal'); doc.text('Total Records :', startXtitle, 27); doc.setFont('sans serif', 'italic'); doc.text(totalRecords.toString(), 28, 27); doc.setFontSize(10); var startY = 28; var startX = margin; var lineHeight = 8; var cellWidth = 20; var cellHeight = 9; var headers = [ 'No.', 'Ticket No', 'Support', 'Date created', 'Date started', 'Date ended', 'Status', 'SLA', 'Elapsed Time', 'SLA Status' ]; // Define the widths of each column // var cellWidths = [ // 12, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,20 // ]; // Adjust the width of the first column var cellWidths = contentWidth / headers.length; doc.setFont('helvetica', 'bold'); doc.setFillColor(200, 200, 200); // Light gray background color // doc.setFillColor(0, 255, 255); //ligth blue // Calculate the total width of the headers var totalHeaderWidth =contentWidth;// cellWidths.reduce((acc, curr) => acc + curr, 0); // Draw background rectangle for the header row doc.rect(startX, startY, totalHeaderWidth, cellHeight, 'F'); doc.setFillColor(0, 255, 255); doc.rect(startX, startY+cellHeight, totalHeaderWidth,0); doc.setFontSize(8); // Draw headers with adjusted column widths var currentX = 10; // Track the current X position console.log('current X '+currentX); headers.forEach(function(header, i) { console.log(i) var splitValue = doc.splitTextToSize(header, cellWidths); // Adjust width as needed var textX = currentX + cellWidths / 2; var textY = startY + cellHeight / 2 + 2; // Adjust the Y position slightly for vertical centering // Draw the header text doc.text(textX, textY, splitValue, null, null, 'center'); // Move to the next column currentX += cellWidths; }); // Draw data rows with adjusted column widths var startY = 23; doc.setFont('helvetica', 'normal'); var lineHeight = 15; // Adjusted line height doc.setFillColor(255, 255, 255); // Reset background color cellHeight = 10; doc.setFontSize(7); var counter = 1; // Counter variable for the first column data.forEach(function(item, rowIndex) { startY += lineHeight; if (startY > doc.internal.pageSize.height - 20) { doc.addPage(); // Add a new page if startY exceeds the height startY = 20; // Reset startY for the new page } var currentX = startX; // Track the current X position doc.text(14, startY + 11 / 2, counter.toString(), null, null, 'center'); counter++; // Increment the counter Object.values(item).forEach(function(value, colIndex) { if(colIndex ===8) { value = formatElapsedTime(value); } var splitValue = doc.splitTextToSize(value, cellWidths - 5); // Adjust width as needed splitValue = (splitValue == 'null' || splitValue == 'null' || splitValue == 'NULL' ? '' : splitValue); doc.rect(currentX, startY-1, cellWidths, 15); doc.text(currentX + cellWidths / 2, startY + cellHeight / 2, splitValue, null, null, 'center'); currentX += cellWidths; // Move to the next column }); }); addFooter(); var pdfData = doc.output('datauristring'); // window.open(pdfData); // var link = document.createElement('a'); // link.href = pdfData; // link.target = '_blank'; // Open link in new tab // link.innerHTML = 'Open PDF'; // Link text // document.body.appendChild(link); // Append link to the body // link.click(); // Simulate click event to open the PDF var pdfData = doc.output('blob'); var blobUrl = URL.createObjectURL(pdfData); window.open(blobUrl); } function formatElapsedTime(time) { let formattedTime = ''; if (time != null) { let [hours, minutes, seconds] = time.split(':').map(Number); let totalMinutes = hours * 60 + minutes; if (totalMinutes > 0) { formattedTime += totalMinutes + ' min' + (totalMinutes > 1 ? 's' : ''); } if (seconds > 0) { if (formattedTime.length > 0) { formattedTime += ' and '; } formattedTime += seconds + ' second' + (seconds > 1 ? 's' : ''); } } return formattedTime; } function generateExcel(data) { var headers = [ { display: 'Ticket No', key: 'ticket_no' }, { display: 'Support', key: 'fullname' }, { display: 'Date created', key: 'date_created' }, { display: 'Date started', key: 'start_date' }, { display: 'Date ended', key: 'end_date' }, { display: 'Status', key: 'status' }, { display: 'SLA', key: 'content' }, { display: 'Elapsed Time', key: 'time_elapsed' }, { display: 'SLA Status', key: 'sla_status' } ]; var dataArray = []; // Convert data to array of arrays // var dataArray = [headers]; var headerRow = headers.map(header => header.display); dataArray.push(headerRow); data.forEach(function(item) { var row = []; headers.forEach(function(header) { // var key = header.toLowerCase().replace(/\s/g, '_'); var value = String(item[header.key] || ''); // Convert value to string // console.log(value); row.push(value); }); dataArray.push(row); }); // Create a worksheet var worksheet = XLSX.utils.aoa_to_sheet(dataArray); // Create a workbook var workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1'); // Convert the workbook to a binary Excel file var excelFile = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' }); // Convert the binary Excel data to a Blob var blob = new Blob([s2ab(excelFile)], { type: 'application/octet-stream' }); // Create a download link var url = window.URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; const dateTime = new Date().toLocaleString(); a.download = 'Support SLA Summary Masterfile ' + dateTime + '.xlsx'; // Trigger a click event to download the file a.click(); window.URL.revokeObjectURL(url); } // Helper function to convert string to array buffer function s2ab(s) { var buf = new ArrayBuffer(s.length); var view = new Uint8Array(buf); for (var i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF; return buf; } });
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings