File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/report/MonthlyTechnicalSupportSummary.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(); $.ajax({ url: "/reports/get/monthly-tech-support-count-summary?page=1", type: "POST", data: { year : year, company : company, dealer : dealer, department_id : $("#department_id").val(), personnel : $("#personnel").val(), ticket_status: $("#ticket_status").val(), categories : $("#categories").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 for the Year of '+year, 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', { // 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.setFont('sans serif', 'normal') doc.text('Prepared date', startXtitle, 28); doc.text(':', 28, 28); 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, 28); doc.setFont('sans serif', 'normal') doc.text('Prepared by', startXtitle, 32); doc.text(':', 28, 32); doc.setFont('sans serif', 'italic'); doc.text(employee_name, 30, 32); // Define column widths based on the number of items var numColumns = data.length + 2; // plus 1 for last column total var colWidth = contentWidth / numColumns; // Draw the category headers (Network, System, Hardware, etc.) doc.setFont('helvetica', 'bold'); var currentX = margin; doc.setFontSize(8); doc.setFont('helvetica', 'bold'); doc.setFillColor(200, 200, 200); doc.rect(currentX, startY+1, colWidth, cellHeight -1, 'F'); doc.text("Month", currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; data.forEach(item => { doc.setFillColor(200, 200, 200); doc.rect(currentX, startY+1, colWidth, cellHeight -1, 'F'); doc.text(item.category || 'N/A', currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); doc.setFillColor(200, 200, 200); doc.rect(currentX, startY+1, colWidth, cellHeight-1, 'F'); doc.text("Total Support", currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); startY += cellHeight; // Monthly data rows var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; doc.setFont('helvetica', 'normal'); // Store grand totals for each category var grandTotals = new Array(data.length).fill(0); var grandMonthlyTotal = 0; months.forEach((month, index) => { var currentX = margin; var monthlyTotal = 0; // Print month name doc.rect(currentX, startY, colWidth, cellHeight); doc.text(month, currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; // Print category counts for the month and accumulate monthly and grand totals data.forEach((item, i) => { var count = item.monthly_counts[index + 1] || 0; monthlyTotal += count; grandTotals[i] += count; doc.rect(currentX, startY, colWidth, cellHeight); doc.text(count.toString(), currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); // Print total for the month doc.rect(currentX, startY, colWidth, cellHeight); doc.text(monthlyTotal.toString(), currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); grandMonthlyTotal += monthlyTotal; startY += cellHeight; }); // Grand Total Row currentX = margin; doc.setFont('helvetica', 'bold'); doc.setFillColor(220, 220, 220); // Different color for grand total row doc.rect(currentX, startY, colWidth, cellHeight, 'F'); doc.text("TOTAL", currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; grandTotals.forEach(total => { doc.setFillColor(220, 220, 220); doc.rect(currentX, startY, colWidth, cellHeight, 'F'); doc.text(total.toString(), currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); currentX += colWidth; }); // Print grand monthly total doc.setFillColor(220, 220, 220); doc.rect(currentX, startY, colWidth, cellHeight, 'F'); doc.text(grandMonthlyTotal.toLocaleString(), currentX + colWidth / 2, startY + cellHeight / 2 + 2, 'center'); addFooter(); var pdfData = doc.output('blob'); var blobUrl = URL.createObjectURL(pdfData); window.open(blobUrl); } function generateExcel(data) { // Create a new workbook and add a worksheet var workbook = XLSX.utils.book_new(); var worksheetData = []; worksheetData.push([company_name]); // Add company name as the first row worksheetData.push([dealer_name]); // Add dealer name as the second row worksheetData.push([department_name]); // Add department name as the third row worksheetData.push(["Individual Technical Support Summary for the Year of " + year]); // Add year info as the fourth row worksheetData.push([personnel_name]); worksheetData.push([]); // Header row (Month, Categories, Total Support) const headerRow = ["Month"]; data.forEach(item => { headerRow.push(item.category || 'N/A'); }); headerRow.push("Total Support"); worksheetData.push(headerRow); // Monthly data rows and grand total calculation var grandTotals = new Array(data.length).fill(0); var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; months.forEach((month, index) => { const row = [month]; let monthlyTotal = 0; // Add category counts for the month and accumulate monthly and grand totals data.forEach((item, i) => { const count = item.monthly_counts[index + 1] || 0; row.push(count); monthlyTotal += count; grandTotals[i] += count; }); // Monthly total row.push(monthlyTotal); worksheetData.push(row); }); // Grand total row const totalRow = ["TOTAL"]; grandTotals.forEach(total => totalRow.push(total)); totalRow.push(grandTotals.reduce((sum, val) => sum + val, 0)); // Total of all categories across months worksheetData.push(totalRow); // Create worksheet and add to workbook var worksheet = XLSX.utils.aoa_to_sheet(worksheetData); XLSX.utils.book_append_sheet(workbook, worksheet, "Support Data"); // Export to Excel XLSX.writeFile(workbook, 'Individual_technical_summary_report_for_the_year_'+year+'.xlsx'); } });
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.13 |
proxy
|
phpinfo
|
Settings