EVOLUTION-NINJA
Edit File: report.php
<?php echo view('includes/sidebar'); ?> <script type="text/javascript" src="<?php echo base_url('public/assets/js/jquery-3.6.0.min.js'); ?>"></script> <script src="<?php echo base_url('public/assets/toastr/toastr.min.js');?>"></script> <link rel="stylesheet" href="<?php echo base_url('public/assets/toastr/toastr.min.css');?>"> <link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.4/xlsx.full.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <style> /* Styling for the table */ table { width: 100%; border-collapse: collapse; text-align: left; } th, td { padding: 10px; border: 1px solid #ddd; } th { background-color: #f4f4f4; font-weight: bold; } tr:nth-child(even) { background-color: #f9f9f9; } .table-container { width: 91%; margin: auto; overflow-x: auto; height: 552px; overflow-y: scroll; border: 1px solid #999; } /* Styling for totals and grand total row */ .total-row { font-weight: bold; background-color: #e0e0e0; } h4 { text-align: center; font-size: 20px; margin-bottom: 30px; margin-left: -150px; font-weight: bold; color: #4B0B0B; } .fieldsbox { width: 93% !important; } /* Additional styles for responsive view */ @media screen and (max-width: 768px) { th, td { font-size: 14px; padding: 8px; } .total-row th, .total-row td { font-size: 14px; padding: 8px; } .fieldsbox { width: 100%; } } /* Table header fixed while scrolling */ /*.table-container th {*/ /* position: sticky;*/ /* top: 0;*/ /* background-color: #f4f4f4;*/ /* z-index: 2;*/ /*}*/ #reportTable { width: 100%; margin: auto; } #reportTable, th, td { border-collapse: collapse; } #reportTable td { padding: 5px 10px; border: 1px solid black; font-size: 15px; } #reportTable th { padding:12px 10px; border: 1px solid black; font-size: 14px; font-weight: 600; vertical-align: middle; } #reportTable .width { padding: 0px 100px; } .heading { text-align: center; font-size: 22px; margin-left: -150px; font-weight: bold; color: #4B0B0B; /*border:none !important;*/ } </style> <section class="home-section fullpage"> <div class="home-content"> <i class='bx bx-menu'></i> <!-- <span class="text">Drop Down Sidebar</span> --> </div> <div class="row m-0"> <div class="col-sm-12"> <h1 class="crt-pjt">Reports</h1> </div> </div> <form id="report"> <div class="row m-0"> <div class="constuency_page"> <div class="constuencydetails"> <div class="constuencydetail row"> <div class="col-sm-4"> <label for="constituency" class="form-label inpfieldname">Constituency Name</label> <select class="form-select form-control fieldsbox" id="constituency" name="constituency"> <option value=""></option> </select> </div> <div class="col-sm-4"> <label for="mla" class="form-label inpfieldname">MLA/ MLC/MP</label> <select class="form-select form-control fieldsbox" id="mla" name="mla"> <option value=""></option> </select> </div> <div class="col-sm-4"> <label for="department" class="form-label inpfieldname">Department</label> <select class="form-select form-control fieldsbox" id="department" name="department"> <option value=""></option> </select> </div> </div> <!-- -------------------------------------------2nd row ------------------------------- --> <div class="constuencydetail row"> <div class="col-sm-4"> <label for="year" class="form-label inpfieldname">Financial Year</label> <select class="form-select form-control fieldsbox" id="year" name="year"> <option value="">Select</option> <option value="2027-28">2027-28</option> <option value="2026-27">2026-27</option> <option value="2025-26">2025-26</option> <option value="2024-25">2024-25</option> <option value="2023-24">2023-24</option> <option value="2022-23">2022-23</option> <option value="2021-22">2021-22</option> <option value="2020-21">2020-21</option> <option value="2019-20">2019-20</option> <option value="2018-19">2018-19</option> <option value="2017-18">2017-18</option> <option value="2016-17">2016-17</option> </select> </div> <div class="col-sm-4"> <label for="Apm" class="form-label inpfieldname">APM</label><br> <select class="form-select form-control fieldsbox" aria-label="Default select example" id="apm" name="apm"> <option value=""></option> </select> </div> <div class="col-sm-4"> <label for="engineer" class="form-label inpfieldname">Engineer</label><br> <select class="form-select form-control fieldsbox" aria-label="Default select example" id="Engineer" name="engineer"> <option value=""></option> </select> </div> </div> <div class="constuencydetail row"> <div class="col-sm-4"> <label for="engineer" class="form-label inpfieldname">Fund Wise</label><br> <select class="form-select form-control fieldsbox" aria-label="Default select example" id="Fund" name="fund"> <option value=""></option> </select> </div> <div class="col-sm-4"> <label for="engineer" class="form-label inpfieldname">Status</label><br> <select class="form-select form-control fieldsbox" aria-label="Default select example" id="status" name="status"> <option value="1">All</option> <option value="2">Progress</option> <option value="3">Action plan</option> </select> </div> <div class="col-sm-4"> <label for="engineer" class="form-label inpfieldname">Date</label><br> <input type="text" class="form-control fieldsbox" id="date" name="date" onchange="updateYearChange()" placeholder="dd/mm/yy"> </div> </div> </div> </div> <div class="col-sm-6 buttns-cnl"> <button type="submit" class="submit" style="width:200px">Get Report</button> </div> </div> </form> <!-- Table --> <div class=" mt-4 ml-3 mr-3 mt-3"> <button id="printBtn" class="btn btn-primary">Print PDF</button> <button id="printExcel" class="btn btn-primary">Export To Excel</button> <div class="table-container mt-5" id="reportContainer"> <table class="table mt-3" id="reportTable"> <thead> <tr> <td colspan="12" class="heading">Nirman Vision</td> </tr> <tr> <td colspan="12" style="text-align:center;font-size: 14px;font-weight: 600;padding: 6px;"> <span id="yearchange"></span> ಸಾಲಿನಲ್ಲಿ ಕೈಗೊಳ್ಳುತ್ತಿರುವ ಕಾಮಗಾರಿಗಳ ಘೋಷ್ವಾರ<span id="monthChange"></span></td> </tr> <tr> <th rowspan="2">SL NO</th> <th class="width" rowspan="2">Work Details</th> <th roespan="2">No Of Works</th> <th>Estimated Amount</th> <th>Previous Year Amount Release </th> <th>Present Year Amount Release </th> <th>Total Release</th> <th>Expenditure</th> <th colspan="3" class="text-center">Stage of Work</th> <!--<th>Page NO</th>--> </tr> <tr> <td></td> <th colspan="5" class="text-center">Lakhs in Rupees</th> <th>Completed</th> <th>Progress</th> <th>Not Started</th> </tr> </thead> <tbody id="reportTableBody"> <!-- Dynamic rows will be appended here --> </tbody> </table> </div> </div> </div> <script> $(document).ready(function () { function fetchReport(formData = null) { $.ajax({ url: "<?php echo base_url('get_report'); ?>", type: 'POST', data: formData ? formData : {}, processData: formData ? false : true, contentType: formData ? false : 'application/x-www-form-urlencoded; charset=UTF-8', dataType: 'json', success: function (response) { if (response.result === 1) { $('#reportTableBody').empty(); $('#totalAmount').text('0'); $('#previousYearAmount').text('0'); $('#presentYearAmount').text('0'); $('#totalReleaseAmount').text('0'); $('#totalExpenses').text('0'); $('#workingInProgressCount').text('0'); $('#notStartedCount').text('0'); $('#physicallyCount').text('0'); // $('#financiallyCount').text('0'); $('#serialNumberValue').text('0'); let totalsByDepartment = {}; let grandTotal = { totalOverall: 0, totalReleaseOverall: 0, totalExpenseOverall: 0, totalPreviousOverall: 0, totalPresentOverall: 0, workingInProgressOverall: 0, physicallyOverall: 0, // financiallyOverall: 0, notStartedOverall: 0, totalSerialValue: 0 }; let serialCounter = 1; $.each(response.table, function (index, project) { let p_amount = parseFloat(project.total_released_amount) || 0; let amount = parseFloat(project.Total_amount) || 0; // let previous_year_released = parseFloat(project.previous_year_released) || 0; let present_year_released = parseFloat(project.present_year_released) || 0; let previous_year_released = p_amount-present_year_released; let releaseAmount =previous_year_released +present_year_released; let expenses = parseFloat(project.total_expenditure) || 0; let workingStage = project.status ? project.status.toLowerCase() : null; let departmentName = project.department_name || ""; let constituencyName = project.constituency_name || ""; let serialNumberValue = parseInt(project.sl_no) || 0; let financialYear = project.financial_year || ''; let fundWise = project.fund_name ? project.fund_name : ''; if (!totalsByDepartment[departmentName]) { totalsByDepartment[departmentName] = { constituencies: {}, totalAmount: 0, totalPreviousReleased: 0, totalPresentReleased: 0, totalReleaseAmount: 0, totalExpenses: 0, serialNumberValue: 0, workingInProgress: 0, physically: 0, // financially: 0, notStarted: 0 }; } if (!totalsByDepartment[departmentName].constituencies[constituencyName]) { totalsByDepartment[departmentName].constituencies[constituencyName] = { financialYears: {}, totalAmount: 0, totalPreviousReleased: 0, totalPresentReleased: 0, totalReleaseAmount: 0, totalExpenses: 0, workingInProgress: 0, physically: 0, // financially: 0, notStarted: 0, serialNumberValue: 0 }; } if (!totalsByDepartment[departmentName].constituencies[constituencyName].financialYears[financialYear]) { totalsByDepartment[departmentName].constituencies[constituencyName].financialYears[financialYear] = {}; } if (!totalsByDepartment[departmentName].constituencies[constituencyName].financialYears[financialYear][fundWise]) { totalsByDepartment[departmentName].constituencies[constituencyName].financialYears[financialYear][fundWise] = { amount: 0, previous_year_released: 0, present_year_released: 0, releaseAmount: 0, expenses: 0, serialNumberValue: 0, workingInProgress: 0, physically: 0, // financially: 0, notStarted: 0 }; } let fundWiseTotals = totalsByDepartment[departmentName].constituencies[constituencyName].financialYears[financialYear][fundWise]; fundWiseTotals.amount += amount; fundWiseTotals.previous_year_released += previous_year_released; fundWiseTotals.present_year_released += present_year_released; fundWiseTotals.releaseAmount += releaseAmount; fundWiseTotals.expenses += expenses; fundWiseTotals.serialNumberValue += serialNumberValue; // Accumulate work stages if (workingStage === '1') { fundWiseTotals.workingInProgress+= (1*serialNumberValue); totalsByDepartment[departmentName].constituencies[constituencyName].workingInProgress++; grandTotal.workingInProgressOverall+= (1*serialNumberValue); } else if (workingStage === '3') { fundWiseTotals.physically+= (1*serialNumberValue); totalsByDepartment[departmentName].constituencies[constituencyName].physically++; grandTotal.physicallyOverall+= (1*serialNumberValue); } else if (workingStage === '2') { fundWiseTotals.notStarted+= (1*serialNumberValue); totalsByDepartment[departmentName].constituencies[constituencyName].notStarted++; grandTotal.notStartedOverall+= (1*serialNumberValue); } // Accumulate constituency totals totalsByDepartment[departmentName].constituencies[constituencyName].totalAmount += amount; totalsByDepartment[departmentName].constituencies[constituencyName].totalPreviousReleased += previous_year_released; totalsByDepartment[departmentName].constituencies[constituencyName].totalPresentReleased += present_year_released; totalsByDepartment[departmentName].constituencies[constituencyName].totalReleaseAmount += releaseAmount; totalsByDepartment[departmentName].constituencies[constituencyName].totalExpenses += expenses; totalsByDepartment[departmentName].constituencies[constituencyName].serialNumberValue += serialNumberValue; // Update grand total grandTotal.totalOverall += amount; grandTotal.totalReleaseOverall += releaseAmount; grandTotal.totalExpenseOverall += expenses; grandTotal.totalPreviousOverall += previous_year_released; grandTotal.totalPresentOverall += present_year_released; grandTotal.totalSerialValue += serialNumberValue; }); $.each(totalsByDepartment, function (departmentName, departmentTotals) { // Render department row let departmentRow = ` <tr style="font-weight: bold; background-color: #f0f0f0; text-align:left !important;"> <td>${serialCounter++}</td> <td colspan="13" style="text-align:center">${departmentName}</td> </tr> `; $('#reportTableBody').append(departmentRow); $.each(departmentTotals.constituencies, function (constituencyName, constituencyData) { // Render constituency row let constituencyRow = ` <tr style="background-color: #e9f7df; text-align:left !important;"> <td colspan="12" style="text-align:left;font-weight:bold;">${constituencyName}</td> </tr> `; $('#reportTableBody').append(constituencyRow); $.each(constituencyData.financialYears, function (financialYear, fundData) { // Render financial year header let financialYearRow = ` <tr style="background-color: #d0f0c0; text-align:center !important;font-weight:bold;"> <td colspan="13">${financialYear}</td> </tr> `; $('#reportTableBody').append(financialYearRow); // Render fund-wise totals under financial year $.each(fundData, function (fundWise, totals) { let financialFundRow = ` <tr style="background-color: #f7f7f7; text-align:left !important;"> <td></td> <td>${fundWise}</td> <td>${totals.serialNumberValue}</td> <td>${totals.amount.toFixed(2)}</td> <td>${totals.previous_year_released.toFixed(2)}</td> <td>${totals.present_year_released.toFixed(2)}</td> <td>${totals.releaseAmount.toFixed(2)}</td> <td>${totals.expenses.toFixed(2)}</td> <td>${totals.physically}</td> <td>${totals.workingInProgress}</td> <td>${totals.notStarted}</td> </tr> `; $('#reportTableBody').append(financialFundRow); }); }); // Render total row for constituency let totalRow = ` <tr style="font-weight: bold; background-color: #e0e0e0; text-align:left !important;"> <td></td> <td>Total</td> <td>${constituencyData.serialNumberValue}</td> <td>${constituencyData.totalAmount.toFixed(2)}</td> <td>${constituencyData.totalPreviousReleased.toFixed(2)}</td> <td>${constituencyData.totalPresentReleased.toFixed(2)}</td> <td>${constituencyData.totalReleaseAmount.toFixed(2)}</td> <td>${constituencyData.totalExpenses.toFixed(2)}</td> <td>${constituencyData.physically}</td> <td>${constituencyData.workingInProgress}</td> <td>${constituencyData.notStarted}</td> </tr> `; $('#reportTableBody').append(totalRow); }); // Render total row for department }); // Render grand total row let grandTotalRow = ` <tr style="font-weight: bold; background-color: #cccccc; text-align:left !important;"> <td></td> <td>Grand Total</td> <td>${grandTotal.totalSerialValue}</td> <td>${grandTotal.totalOverall.toFixed(2)}</td> <td>${grandTotal.totalPreviousOverall.toFixed(2)}</td> <td>${grandTotal.totalPresentOverall.toFixed(2)}</td> <td>${grandTotal.totalReleaseOverall.toFixed(2)}</td> <td>${grandTotal.totalExpenseOverall.toFixed(2)}</td> <td>${grandTotal.physicallyOverall}</td> <td>${grandTotal.workingInProgressOverall}</td> <td>${grandTotal.notStartedOverall}</td> </tr> `; $('#reportTableBody').append(grandTotalRow); // Update overall total fields $('#totalAmount').text(grandTotal.totalOverall.toFixed(2)); $('#previousYearAmount').text(grandTotal.totalPreviousOverall.toFixed(2)); $('#presentYearAmount').text(grandTotal.totalPresentOverall.toFixed(2)); $('#totalReleaseAmount').text(grandTotal.totalReleaseOverall.toFixed(2)); $('#totalExpenses').text(grandTotal.totalExpenseOverall.toFixed(2)); $('#completedCount').text(grandTotal.completedOverall); $('#workingInProgressCount').text(grandTotal.workingInProgressOverall); $('#notStartedCount').text(grandTotal.notStartedOverall); } else { // Handle case where there is no data $('#reportTableBody').html('<tr><td colspan="13" style="text-align:center;">No data available</td></tr>'); } }, error: function () { console.error('An error occurred while fetching the report.'); } }); } // Trigger the report fetching on document ready or specific event fetchReport(); $('#report').submit(function (e) { e.preventDefault(); let formData = new FormData(this); fetchReport(formData); }); $('#printBtn').click(function() { printReport(); }); $('#printExcel').click(function () { generateExcel(); }); function generateExcel() { const worksheet = XLSX.utils.table_to_sheet(document.getElementById('reportTable')); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, worksheet, "Report"); XLSX.writeFile(wb, "report.xlsx"); } function printReport() { // Create a new window const printWindow = window.open('', '_blank'); const reportContent = $('#reportContainer').html(); // Get the HTML of the report printWindow.document.write(` <html> <head> <title>Report</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> body { font-family: Arial, sans-serif; margin:0 5px !important; } .heading { font-size: 20px; font-weight: bold; text-align: center; margin-bottom: 20px; } table { width: 100%; border-collapse: collapse; } th, td { padding:7px 2px !important; text-align:center; border:2px solid black !important;vertical-align:middle !important } th {padding:0px 2px !important;font-size:14px !important } .width{padding:0px 100px !important; } /* Landscape orientation for printing */ @media print { @page { size: landscape; } } </style> </head> <body> <div class=" mt-4 ml-1 mr-1"> <div class="table-container">${reportContent}</div> </div> </body> </html> `); printWindow.document.close(); printWindow.onload = function() { printWindow.print(); printWindow.close(); }; } }); </script> <script> function updateYearChange() { const dateInput = document.getElementById('date').value; // Validate input format (dd/mm/yy) const dateParts = dateInput.split('/'); if (dateParts.length === 3) { const day = parseInt(dateParts[0], 10); const month = parseInt(dateParts[1], 10) - 1; // Month is zero-indexed in JavaScript const year = parseInt( dateParts[2], 10); // Prefix '20' for 2-digit year const date = new Date(year, month, day); // Format month and year const monthName = date.toLocaleString('kn-IN', { month: 'long' }); // Kannada month name const yearFull = date.getFullYear(); document.getElementById('monthChange').textContent = `(${monthName} - ${yearFull})`; } else { // alert('Please enter a valid date in dd/mm/yy format'); } } </script> // <script> // function updateYearChange() { // const dateInput = document.getElementById('date').value; // if (dateInput) { // const date = new Date(dateInput); // const month = date.toLocaleString('kn-IN', { month: 'long' }); // Kannada month name // const year = date.getFullYear(); // document.getElementById('monthChange').textContent = `(${month} - ${year})`; // } // } // </script> // <script> // $(document).ready(function() { // const currentYear = new Date().getFullYear(); // const fiscalYear = `${currentYear}-${currentYear + 1}`; // if (!$('#year').val()) { // $('#yearchange').text(fiscalYear); // } // $('#year').change(function() { // const selectedYear = $(this).val(); // // const fiscalSelectedYear = `${selectedYear}-${parseInt(selectedYear) + 1}`; // const fiscalSelectedYear = `${selectedYear}`; // $('#yearchange').text(fiscalSelectedYear); // }); // }); // </script> <script> $(document).ready(function () { const currentDate = new Date(); const currentYear = currentDate.getFullYear(); const currentMonth = currentDate.getMonth() + 1; // Months are 0-indexed in JavaScript let fiscalYear; if (currentMonth >= 4) { // From April to December fiscalYear = `${currentYear}-${currentYear + 1}`; } else { fiscalYear = `${currentYear - 1}-${currentYear}`; } if (!$('#year').val()) { $('#yearchange').text(fiscalYear); } $('#year').change(function () { const selectedYear = parseInt($(this).val()); const selectedMonth = currentMonth; let fiscalSelectedYear; if (selectedMonth >= 4) { fiscalSelectedYear = `${selectedYear}-${selectedYear + 1}`; } else { fiscalSelectedYear = `${selectedYear - 1}-${selectedYear}`; } $('#yearchange').text(fiscalSelectedYear); }); }); </script> <script> $(document).ready(function () { // Initialize Date of Estimation datepicker $('#date').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); }); </script> <script> let arrow = document.querySelectorAll(".arrow"); for (var i = 0; i < arrow.length; i++) { arrow[i].addEventListener("click", (e) => { let arrowParent = e.target.parentElement.parentElement; arrowParent.classList.toggle("showMenu"); }); } let sidebar = document.querySelector(".sidebar"); let sidebarBtn = document.querySelector(".bx-menu"); console.log(sidebarBtn); sidebarBtn.addEventListener("click", () => { sidebar.classList.toggle("close"); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-constituency"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select Constituency</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.constituency_name}</option>`; }); $('#constituency').html(options); } else { console.log('No constituency found'); } }, error: function (xhr, status, error) { console.error("Error fetching constituency:", error); } }); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-department"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select Department</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.department_name}</option>`; }); $('#department').html(options); } else { console.log('No department found'); } }, error: function (xhr, status, error) { console.error("Error fetching department:", error); } }); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-mla"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select </option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.mla}</option>`; }); $('#mla').html(options); } else { console.log('No mla found'); } }, error: function (xhr, status, error) { console.error("Error fetching mla:", error); } }); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-apm"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select APM</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.username}</option>`; }); $('#apm').html(options); } else { console.log('No apm found'); } }, error: function (xhr, status, error) { console.error("Error fetching apm:", error); } }); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-engineer"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select Engineer</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.username}</option>`; }); $('#Engineer').html(options); } else { console.log('No Engineer found'); } }, error: function (xhr, status, error) { console.error("Error fetching engineer:", error); } }); }); </script> <script> $(document).ready(function () { $.ajax({ url: '<?php echo base_url("fetch-fund"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select fund</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.fund_name}</option>`; }); $('#Fund').html(options); } else { console.log('No fund found'); } }, error: function (xhr, status, error) { console.error("Error fund engineer:", error); } }); }); </script> <?php echo view('includes/footer'); ?>