File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/report/SupportTicketCountReport.js
Back
$(document).ready(function() { window.jsPDF = window.jspdf.jsPDF; var data_set = []; var date_from = ''; var date_to = ''; var totalRecords = 0; var department_name =''; // 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(); let department_id = $("#department_id").val(); $.ajax({ url: "/reports/get/SLAsupport_ticket_count?page=1", type: "POST", data: { from_date: from_date, to_date: to_date, status : ticket_status, department : department_id, }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result) { console.log(result); totalRecords = 0; // totalClosedTicket = 0; // totalOngoingTicket = 0; total_count = 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; department_name = result.department_name; total_count = result.total_sla_ticket_count; $('#loading-modal-slacount').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/SLAsupport_ticket_count?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('Ticket Count by Support Personnel', 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('Department :', startXtitle, 16); doc.setFont('sans serif', 'bold'); doc.text(department_name, 28, 16); doc.setFont('sans serif', 'normal'); doc.text('Date range :', startXtitle, 20); doc.text(DateFrom_formattedDateTime + ' to ' + DateTo_formattedDateTime, 28, 20); // 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, 24); // 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, 24); // 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, 28); // doc.setFont('sans serif', 'italic'); doc.text(employee_name, 28, 28); doc.setFont('sans serif', 'normal'); doc.text('Total Records :', startXtitle, 32); // doc.setFont('sans serif', 'italic'); doc.text(totalRecords.toString(), 28, 32); doc.setFontSize(10); var startY = 33;//28; var startX = margin; var lineHeight = 8; var cellWidth = 20; var cellHeight = 9; var headers = [ 'No.', 'Support', 'Count' ]; // 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; if(i==0) { var textX = currentX + 6; } var textY = startY + cellHeight / 2 +1; // 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 startYData = 30; doc.setFont('helvetica', 'normal'); var lineHeight = 10; // Adjusted line height doc.setFillColor(255, 255, 255); // Reset background color cellHeight = 15; doc.setFontSize(10); var counter = 1; // Counter variable for the first column var totalCount = 0; data.forEach(function(item, rowIndex) { startYData += lineHeight; if (startY > doc.internal.pageSize.height - 20) { doc.addPage(); // Add a new page if startY exceeds the height startYData = 20; // Reset startY for the new page } var currentX = startX; // Track the current X position doc.text(14, startYData + cellHeight / 2, counter.toString(), null, null, 'center'); counter++; // Increment the counter Object.values(item).forEach(function(value, colIndex) { console.log('col index '+colIndex ); console.log('value '+ value); if(colIndex ===2) { totalCount += parseInt(value); // Accumulate the total count } var splitValue = doc.splitTextToSize(value, cellWidths - 5); // Adjust width as needed splitValue = (splitValue == 'null' || splitValue == 'null' || splitValue == 'NULL' ? '' : splitValue); doc.rect(currentX, startYData +2, cellWidths, 10); doc.text(currentX + cellWidths / 2, startYData + cellHeight / 2 , splitValue, null, null, 'center'); currentX += cellWidths; // Move to the next column }); }); // Add total row // if (startYData > doc.internal.pageSize.height - 20) { // doc.addPage(); // Add a new page if startYData exceeds the height // startYData = 20; // Reset startYData for the new page // } doc.setFont('helvetica', 'bold'); currentX = startX + 120; // Total label doc.setFillColor(200, 200, 200); doc.rect(startX, startYData+ cellHeight-3, totalHeaderWidth, 8, 'F'); doc.setFillColor(255, 255, 255); // doc.rect(startX, startY+cellHeight, totalHeaderWidth,0); doc.text(currentX , startYData + cellHeight+3 , 'Total', null, null, 'center'); // Total count doc.text(currentX + 38, startYData + cellHeight+3 , totalCount.toString(), null, null, 'center'); doc.setFillColor(0, 255, 255); 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: 'No.', key: 'number' }, { display: 'Support', key: 'SUPPORT' }, { display: 'Count', key: 'occurrence_count' } ]; 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); // }); var dataArray = []; // Add headers to the array var headerRow = headers.map(header => header.display); dataArray.push(headerRow); var totalOccurrenceCount = 0; // Initialize total counter // Add data rows data.forEach(function(item, index) { var row = []; headers.forEach(function(header) { var value; if (header.key === 'number') { value = (index + 1).toString(); // Add row number } else { value = String(item[header.key] || ''); // Convert value to string if (header.key === 'occurrence_count') { totalOccurrenceCount += parseInt(value, 10); // Sum up occurrence counts } } row.push(value); }); dataArray.push(row); }); // Add a row for the total occurrence count var totalRow = ['Total', '', totalOccurrenceCount.toString()]; dataArray.push(totalRow); // 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 = 'TicketCountBySupportPersonnel_'+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