Eworked year selector on the dashboard

This commit is contained in:
johnnyq
2023-01-02 16:03:52 -05:00
parent d9fdcb8702
commit 637712aa71
+14 -9
View File
@@ -18,14 +18,19 @@ function roundUpToNearestMultiple($n, $increment = 1000)
return (int) ($increment * ceil($n / $increment)); return (int) ($increment * ceil($n / $increment));
} }
if(isset($_GET['year'])){ if (isset($_GET['year'])) {
$year = intval($_GET['year']); $year = intval($_GET['year']);
}else{ } else {
$year = date('Y'); $year = date('Y');
} }
//GET unique years from expenses, payments and revenues //GET unique years from expenses, payments invoices and revenues
$sql_payment_years = mysqli_query($mysqli,"SELECT YEAR(expense_date) AS all_years FROM expenses WHERE company_id = $session_company_id UNION DISTINCT SELECT YEAR(payment_date) FROM payments WHERE company_id = $session_company_id UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues WHERE company_id = $session_company_id ORDER BY all_years DESC"); $sql_years_select = mysqli_query($mysqli,"SELECT YEAR(expense_date) AS all_years FROM expenses WHERE company_id = $session_company_id
UNION DISTINCT SELECT YEAR(payment_date) FROM payments WHERE company_id = $session_company_id
UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues WHERE company_id = $session_company_id
UNION DISTINCT SELECT YEAR(invoice_date) FROM invoices WHERE company_id = $session_company_id
ORDER BY all_years DESC
");
//Define var so it doesnt throw errors in logs //Define var so it doesnt throw errors in logs
$largest_income_month = 0; $largest_income_month = 0;
@@ -109,13 +114,13 @@ $vendors_added = $row['vendors_added'];
<select onchange="this.form.submit()" class="form-control" name="year"> <select onchange="this.form.submit()" class="form-control" name="year">
<?php <?php
while($row = mysqli_fetch_array($sql_payment_years)){ while($row = mysqli_fetch_array($sql_years_select)){
$payment_year = $row['all_years']; $year_select = $row['all_years'];
if(empty($payment_year)){ if(empty($year_select)){
$payment_year = date('Y'); $year_select = date('Y');
} }
?> ?>
<option <?php if($year == $payment_year){ echo "selected"; } ?> > <?php echo $payment_year; ?></option> <option <?php if($year == $year_select){ echo "selected"; } ?> > <?php echo $year_select; ?></option>
<?php <?php
} }