EVOLUTION-NINJA
Edit File: dealer_report.php
<?php echo view('includes/sidebar'); ?> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css"> <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script> <section class="home-section" style="padding:15px"> <div class="row m-0"> <div class="col-sm-12"> <h1 class="crt-pjt">Dealer Report</h1> <br> </div> </div> <!-- FILTER --> <!-- FILTER --> <form id="dealerFilter"> <div class="row mb-4"> <!-- DEALER --> <div class="col-sm-3"> <label class="inpfieldname"> Dealer Name </label> <select id="dealer_name" name="dealer_name" class="form-control fieldsbox"> <option value=""> All Dealers </option> </select> </div> <!-- FROM DATE --> <div class="col-sm-2"> <label class="inpfieldname"> From Date </label> <input type="date" id="from_date" name="from_date" class="form-control fieldsbox"> </div> <!-- TO DATE --> <div class="col-sm-2"> <label class="inpfieldname"> To Date </label> <input type="date" id="to_date" name="to_date" class="form-control fieldsbox"> </div> <!-- BUTTON --> <div class="col-sm-2 d-flex align-items-end"> <button type="submit" class="submit" style="width:180px; height:45px;"> Get Report </button> </div> </div> </form> <!-- TABLE --> <div class="container-fluid"> <table id="dealerReportTable" class="display" style="width:100%"> <thead> <tr> <th>Sl No</th> <th>Dealer Name</th> <th>No. of Customers</th> <th>Billing Price</th> <th>Total Subsidy Amount</th> <th>Subsidy Paid</th> <th>Total Farmer Share</th> <th>Farmer Share Paid</th> <th>Total Paid</th> <th>Balance Amount</th> <th>AE Commission</th> <th>Action</th> </tr> </thead> </table> </div> </section> <style> .dataTables_wrapper{ width:100%; overflow-x:auto; } table.dataTable{ width:100% !important; } </style> <script> let table; // ===================================== // LOAD DEALER DROPDOWN // ===================================== function loadDealerFilter() { $.ajax({ url: "<?= base_url('dealer/get-report') ?>", type: "POST", dataType: "json", success: function(data) { let dealers = []; data.forEach(function(row){ if( row.dealer_name && !dealers.includes(row.dealer_name) ){ dealers.push(row.dealer_name); $('#dealer_name').append( `<option value="${row.dealer_name}"> ${row.dealer_name} </option>` ); } }); } }); } // ===================================== // LOAD TABLE // ===================================== function loadTable() { if ($.fn.DataTable.isDataTable('#dealerReportTable')) { $('#dealerReportTable').DataTable().destroy(); } table = $('#dealerReportTable').DataTable({ processing: true, destroy: true, pageLength: 10, scrollX: true, responsive: false, ajax: { url: "<?= base_url('dealer/get-report') ?>", type: "POST", data: function(d){ d.dealer_name = $('#dealer_name').val(); d.from_date = $('#from_date').val(); d.to_date = $('#to_date').val(); }, dataSrc: "" }, columns: [ { data: null, render: function (data, type, row, meta) { return meta.row + 1; } }, { data: "dealer_name" }, { data: "total_customers" }, { data: "total_billing_price" }, { data: "total_subsidy_amount" }, { data: "subsidy_paid" }, { data: "total_farmer_share_amount" }, { data: "farmer_share_paid" }, { data: "total_paid" }, { data: "balance_amount" }, { data: "total_ae_commission" }, { data: null, render: function(data, type, row) { return ` <button class="btn btn-sm btn-primary" onclick="viewCustomers('${row.dealer_name}')"> View Customers </button> `; } } ] }); } // ===================================== // DOCUMENT READY // ===================================== $(document).ready(function () { loadDealerFilter(); loadTable(); }); // ===================================== // FILTER SUBMIT // ===================================== $('#dealerFilter').submit(function(e){ e.preventDefault(); loadTable(); }); </script> <script> function viewCustomers(dealer_name) { window.location.href = "<?= base_url('farmer-report') ?>?dealer_name=" + encodeURIComponent(dealer_name); } </script> <?php echo view('includes/footer'); ?>