File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/report/IndividualSupportSummary.js
Back
$(document).ready(function() { window.jsPDF = window.jspdf.jsPDF; var data_set = []; var date_from = ''; var date_to = ''; var totalRecords = 0; var company_name =''; var dealer_name =''; var department_name =''; let year = $("#year").val(); // 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 company = $("#multiple-select-clear-field-company").val(); let dealer = $("#multiple-select-clear-field-dealer").val(); let personnels = $("#personnel").val(); $.ajax({ url: "/reports/get/individual-support-count-summary?page=1", type: "POST", data: { date_from : $("#date_from").val(), date_to : $("#date_to").val(), company : company, dealer : dealer, department_id : $("#department_id").val(), personnel : personnels, category : $("#categories").val(), ticket_status : $("#ticket_status").val(), }, 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; personnel_name = result.personnel_name; company_name = result.company_name; dealer_name = result.dealer_name; department_name = result.department_name; total_count = result.total_sla_ticket_count; $('#loading-modal-annual').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 = []; }); }); $("#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' }); console.log(data); var margin = 10; var pageSize = doc.internal.pageSize; var pageWidth = pageSize.width; var pageHeight = pageSize.height; var contentWidth = pageWidth - margin * 2; var startY = 33; // Starting Y position var cellHeight = 9; // Height for table cells 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); var textY = doc.internal.pageSize.getHeight() - 8; doc.text('Page ' + i + ' of ' + totalPages, pageWidth / 2, textY, 'center'); } }; var startXtitle = 10; doc.setFont('sans serif', 'bold'); doc.setFontSize(10); doc.text(company_name, pageWidth /2, startXtitle,'center'); doc.text(dealer_name, pageWidth /2, startXtitle + 4,'center'); doc.text(department_name, pageWidth /2, startXtitle + 8,'center'); doc.setFont('sans serif', 'normal') doc.text('Individual Technical Support Summary ', pageWidth /2, startXtitle + 12,'center'); doc.setFont('sans serif', 'bold'); // doc.text(personnel_name, pageWidth /2, startXtitle + 16,'center'); doc.setFont('sans serif', 'normal') doc.setFontSize(7); const setDateFrom = new Date(date_from); const DateFrom_formattedDateTime = setDateFrom.toLocaleString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); const setDateTo = new Date(date_to); const DateTo_formattedDateTime = setDateTo.toLocaleString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); doc.text('Date range :', startXtitle, 29); doc.text(DateFrom_formattedDateTime + ' to ' + DateTo_formattedDateTime, 28, 29); doc.setFont('sans serif', 'normal') doc.text('Prepared date', startXtitle, 33); doc.text(':', 28, 33); 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, 30, 33); doc.setFont('sans serif', 'normal') doc.text('Prepared by', startXtitle, 37); doc.text(':', 28, 37); doc.setFont('sans serif', 'italic'); doc.text(employee_name, 30, 37); // Get unique category names from the data var categories = []; data.forEach(item => { Object.keys(item.categories).forEach(category => { if (!categories.includes(category)) { categories.push(category); } }); }); var numColumns = categories.length + 2; // +2 for "Personnel" column and "Total" column var colWidth = (pageWidth - 2 * margin) / numColumns; // Draw the headers var currentX = margin; doc.setFont('helvetica', 'bold'); doc.setFontSize(8); doc.setFillColor(200, 200, 200); // Personnel column header var startTableY = startY + 5; doc.rect(currentX, startTableY +1, pageWidth - (margin*2), cellHeight - 1, 'F'); doc.text("Name", currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); currentX += colWidth; // Category headers categories.forEach(category => { doc.text(category, currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); // Total column header doc.text("Total Support", currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); startTableY+= cellHeight; // Store grand totals for each category var grandTotals = new Array(categories.length).fill(0); var grandTotal = 0; // Print data for each personnel data.forEach(item => { var currentX = margin; doc.setFont('helvetica', 'normal'); doc.setFillColor(255, 255, 255); // Print Personnel Name doc.setFontSize(6); doc.rect(currentX, startTableY, colWidth, cellHeight); doc.text(item.personnel, currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); currentX += colWidth; doc.setFontSize(8); // Print category counts for each personnel var totalForPersonnel = 0; categories.forEach((category, index) => { var count = item.categories[category] || 0; totalForPersonnel += count; grandTotals[index] += count; doc.rect(currentX, startTableY, colWidth, cellHeight); doc.text(count.toString(), currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); // Print total for the personnel doc.rect(currentX, startTableY, colWidth, cellHeight); doc.text(totalForPersonnel.toString(), currentX + colWidth / 2, startTableY + cellHeight / 2 + 2, 'center'); startTableY += cellHeight; }); doc.setFontSize(8); // Print Grand Total Row var currentX = margin; doc.setFont('helvetica', 'bold'); doc.setFillColor(220, 220, 220); // Color for grand total row doc.rect(currentX, startTableY, colWidth, cellHeight-1, 'F'); doc.text("TOTAL", currentX + colWidth / 2, (startTableY-1) + cellHeight / 2 + 2, 'center'); currentX += colWidth; grandTotals.forEach(total => { doc.setFillColor(220, 220, 220); doc.rect(currentX, startTableY, colWidth, cellHeight-1, 'F'); doc.text(total.toString(), currentX + colWidth / 2, (startTableY-1) + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); // Print overall grand total doc.setFillColor(220, 220, 220); doc.rect(currentX, startTableY, colWidth, cellHeight-1, 'F'); var grandTotalSum = grandTotals.reduce((sum, val) => sum + val, 0); doc.text(grandTotalSum.toLocaleString(), currentX + colWidth / 2, (startTableY-1) + cellHeight / 2 + 2, 'center'); addFooter(); var pdfData = doc.output('blob'); var blobUrl = URL.createObjectURL(pdfData); window.open(blobUrl); } function generateExcel(data) { // Create a workbook and a worksheet const wb = XLSX.utils.book_new(); const wsData = []; // Add the additional info as headers wsData.push([company_name || ""]); wsData.push([department_name || ""]); wsData.push(["Individual Technical Support Summary" || ""]); wsData.push([]); // Blank row for spacing const setDateFrom = new Date(date_from); const DateFrom_formattedDateTime = setDateFrom.toLocaleString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); const setDateTo = new Date(date_to); const DateTo_formattedDateTime = setDateTo.toLocaleString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); wsData.push(["Date Range:", DateFrom_formattedDateTime+' '+DateTo_formattedDateTime || ""]); wsData.push([]); // Another blank row for spacing // Define the headers for the table const categories = []; data.forEach(item => { Object.keys(item.categories).forEach(category => { if (!categories.includes(category)) { categories.push(category); } }); }); const headers = ["Name", ...categories, "Total Support"]; wsData.push(headers); // Prepare the data for the worksheet const grandTotals = new Array(categories.length).fill(0); let grandTotalSum = 0; data.forEach(item => { const row = []; row.push(item.personnel); // Personnel Name let totalForPersonnel = 0; // Add category counts categories.forEach((category, index) => { const count = item.categories[category] || 0; row.push(count); totalForPersonnel += count; grandTotals[index] += count; }); // Add total for the personnel row.push(totalForPersonnel); grandTotalSum += totalForPersonnel; wsData.push(row); }); // Add grand total row const totalRow = ["TOTAL", ...grandTotals, grandTotalSum]; wsData.push(totalRow); // Create the worksheet const worksheet = XLSX.utils.aoa_to_sheet(wsData); // Add the worksheet to the workbook XLSX.utils.book_append_sheet(wb, worksheet, "Report"); // Export the workbook XLSX.writeFile(wb, "IndividualSupportCountSummary.xlsx"); } });
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings