Eworked year selector on the dashboard

This commit is contained in:
johnnyq
2023-01-02 16:03:52 -05:00
parent d9fdcb8702
commit 637712aa71
+12 -7
View File
@@ -24,8 +24,13 @@ if(isset($_GET['year'])){
$year = date('Y');
}
//GET unique years from expenses, payments 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");
//GET unique years from expenses, payments invoices and revenues
$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
$largest_income_month = 0;
@@ -109,13 +114,13 @@ $vendors_added = $row['vendors_added'];
<select onchange="this.form.submit()" class="form-control" name="year">
<?php
while($row = mysqli_fetch_array($sql_payment_years)){
$payment_year = $row['all_years'];
if(empty($payment_year)){
$payment_year = date('Y');
while($row = mysqli_fetch_array($sql_years_select)){
$year_select = $row['all_years'];
if(empty($year_select)){
$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
}