JezK
Edit File: dashboard.php
<?php include "./sidemenu-start.php" ?> <div class="container-fluid"> <div class="row"> <div class="col-lg-5 col-12"> <h1>Dashboard</h1> </div> <div class="col-lg-7 col-12 calendar-options"> <div class="d-flex align-items-baseline"> <select class="form-select dashboard-options me-2" id="mySelect"> <option value="1" selected>All</option> <option value="2">Week</option> <option value="3">Month</option> <option value="4">Year</option> </select> <div class="datePicker"> <form id="datePicker"> <div class="d-flex align-items-baseline"> <div class="input-group date me-2" id="datepicker"> <input type="date" class="form-control dashboard-options" id="startDate" /> </div> <div class="mx-2">to</div> <div class="input-group date mx-2" id="datepicker"> <input type="date" class="form-control dashboard-options" id="endDate" /> </div> </div> <p style="font-size:11px" class="error date_error"></p> </div> <button type="submit" onclick="return validateDateForm()" class="no-btn datePicker"><img src="./images/Vector.png" /></button> </form> <div class="SingleDatePicker"> <form id="SingleDatePicker"> <div class="d-flex align-items-baseline"> <div class="input-group date me-2" id="datepicker"> <input type="date" class="form-control dashboard-options" id="singleDate" /> </div> </div> <p class="error singleDate_error"></p> </div> <button type="submit" onclick="return validateSingleDateForm()" class="no-btn SingleDatePicker"><img src="./images/Vector.png" /></button> </form> </div> </div> </div> <div class="row mt-5"> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="userCount">0</h2> <h3>Users Count</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="servicesCount">0</h2> <h3>Services</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="packageCount">0</h2> <h3>Care Club</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="productCount">0</h2> <h3>Products</h3> </div> </div> </div> <div class="row mt-5 db-m"> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="subAdminCount">0</h2> <h3>Sub Admin</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="PurchasesRevenue"></h2> <h3>Purchase Revenue</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="packageRevenue"></h2> <h3>Care Club Revenue</h3> </div> </div> <div class="col-sm-6 col-md-3 db-3"> <div class="tile"> <h2 id="branchCount">0</h2> <h3>Total Branches</h3> </div> </div> </div> </div> <?php include "./sidemenu-end.php" ?> <script> $(document).ready(function() { Ready() $('.SingleDatePicker').addClass('d-none') }) function Ready() { $.ajax({ type: 'POST', url: 'app/dashboard.php', data: { getReady: 'getReady' }, success: function(response) { data = JSON.parse(response); $('#userCount').html(data.usersCount); $('#servicesCount').html(data.servicesCount); $('#packageCount').html(data.packageCount); $('#productCount').html(data.productCount); $('#branchCount').html(data.branchCount); $('#subAdminCount').html(data.subAdminCount); $('#PurchasesRevenue').html(data.purchaseRevenue ? data.purchaseRevenue + " Rs" : '0 Rs'); $('#packageRevenue').html(data.packageRevenue ? data.packageRevenue + " Rs" : '0 Rs'); // $('#productsRevenue').prepend(data.productsRevenue) } }) } $("#startDate").change(function() { if (!$("#startDate").val()) { $.ajax({ type: 'POST', url: 'app/dashboard.php', data: { getReady: 'getReady' }, success: function(response) { data = JSON.parse(response); $('#userCount').html(data.usersCount); $('#servicesCount').html(data.servicesCount); $('#packageCount').html(data.packageCount); $('#productCount').html(data.productCount); $('#branchCount').html(data.branchCount); $('#subAdminCount').html(data.subAdminCount); $('#PurchasesRevenue').html(data.purchaseRevenue ? data.purchaseRevenue + " Rs" : '0 Rs'); $('#packageRevenue').html(data.packageRevenue ? data.packageRevenue + " Rs" : '0 Rs'); // $('#productsRevenue').prepend(data.productsRevenue) } }) } }) $("#endDate").change(function() { if (!$("#endDate").val()) { $.ajax({ type: 'POST', url: 'app/dashboard.php', data: { getReady: 'getReady' }, success: function(response) { data = JSON.parse(response); $('#userCount').html(data.usersCount); $('#servicesCount').html(data.servicesCount); $('#packageCount').html(data.packageCount); $('#productCount').html(data.productCount); $('#branchCount').html(data.branchCount); $('#subAdminCount').html(data.subAdminCount); $('#PurchasesRevenue').html(data.purchaseRevenue ? data.purchaseRevenue + " Rs" : '0 Rs'); $('#packageRevenue').html(data.packageRevenue ? data.packageRevenue + " Rs" : '0 Rs'); // $('#productsRevenue').prepend(data.productsRevenue) } }) } }) $('#datePicker').submit(function(event) { event.preventDefault(); let startDate = $('#startDate').val(); let endDate = $('#endDate').val(); $.ajax({ type: 'POST', url: 'app/dashboard.php', data: { startDate: startDate, endDate: endDate, }, success: function(response) { data = JSON.parse(response); $('#userCount').html(data.usersCount); $('#servicesCount').html(data.servicesCount); $('#packageCount').html(data.packageCount); $('#productCount').html(data.productCount); $('#branchCount').html(data.branchCount); $('#subAdminCount').html(data.subAdminCount); $('#PurchasesRevenue').html(data.purchaseRevenue ? data.purchaseRevenue + " Rs" : '0 Rs'); $('#packageRevenue').html(data.packageRevenue ? data.packageRevenue + " Rs" : '0 Rs'); } }) }) $('#mySelect').change(function() { let mySelect = $('#mySelect').val(); if (mySelect == 1) { $('.SingleDatePicker').addClass('d-none') $('.datePicker').removeClass('d-none') } else { $('.SingleDatePicker').removeClass('d-none') $('.datePicker').addClass('d-none') } }) $('#SingleDatePicker').submit(function(event) { event.preventDefault(); let mySelect = $('#mySelect').val(); let startDate = $('#singleDate').val(); let endDate = new Date(startDate); if (mySelect == 2) { endDate.setDate(endDate.getDate() + 7); // Add 7 days from the start date } else if (mySelect == 3) { endDate.setDate(endDate.getDate() + 30); // Add 30 days from the start date } else if (mySelect == 4) { endDate.setFullYear(endDate.getFullYear() + 1); // Add 1 year from the start date } else if (mySelect == 1) { return Ready() } let startedDate = new Date(startDate); let endedDate = new Date(endDate); const options = { year: 'numeric', month: '2-digit', day: '2-digit' }; const formattedStartDate = startedDate.toLocaleDateString('en-US', options); let [month, day, year] = formattedStartDate.split('/'); const desiredStartFormat = `${year}-${month}-${day}`; const formattedEndDate = endedDate.toLocaleDateString('en-US', options); [month, day, year] = formattedEndDate.split('/'); const desiredEndFormat = `${year}-${month}-${day}`; endDate = desiredEndFormat; startDate = desiredStartFormat; $.ajax({ type: 'POST', url: 'app/dashboard.php', data: { startDate: startDate, endDate: endDate, }, success: function(response) { data = JSON.parse(response); $('#userCount').html(data.usersCount); $('#servicesCount').html(data.servicesCount); $('#packageCount').html(data.packageCount); $('#productCount').html(data.productCount); $('#branchCount').html(data.branchCount); $('#subAdminCount').html(data.subAdminCount); $('#serviceRevenue').html(data.serviceRevenue ? data.serviceRevenue + " Rs" : '0 Rs'); $('#PurchasesRevenue').html(data.purchaseRevenue ? data.purchaseRevenue + " Rs" : '0 Rs'); $('#packageRevenue').html(data.packageRevenue ? data.packageRevenue + " Rs" : '0 Rs'); } }) }) </script>