From 637712aa71025b126ec8052d11e15a7a0062e187 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 2 Jan 2023 16:03:52 -0500 Subject: [PATCH] Eworked year selector on the dashboard --- dashboard_financial.php | 143 +++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 69 deletions(-) diff --git a/dashboard_financial.php b/dashboard_financial.php index a462a937..1b853618 100644 --- a/dashboard_financial.php +++ b/dashboard_financial.php @@ -18,14 +18,19 @@ function roundUpToNearestMultiple($n, $increment = 1000) return (int) ($increment * ceil($n / $increment)); } -if(isset($_GET['year'])){ - $year = intval($_GET['year']); -}else{ - $year = date('Y'); +if (isset($_GET['year'])) { + $year = intval($_GET['year']); +} else { + $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; @@ -67,17 +72,17 @@ $profit = $total_income - $total_expenses; $sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts WHERE company_id = $session_company_id"); $sql_latest_invoice_payments = mysqli_query($mysqli,"SELECT * FROM payments, invoices, clients - WHERE payment_invoice_id = invoice_id - AND invoice_client_id = client_id + WHERE payment_invoice_id = invoice_id + AND invoice_client_id = client_id AND clients.company_id = $session_company_id - ORDER BY payment_id DESC LIMIT 5" + ORDER BY payment_id DESC LIMIT 5" ); $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, categories - WHERE expense_vendor_id = vendor_id - AND expense_category_id = category_id + WHERE expense_vendor_id = vendor_id + AND expense_category_id = category_id AND expenses.company_id = $session_company_id - ORDER BY expense_id DESC LIMIT 5" + ORDER BY expense_id DESC LIMIT 5" ); //Get Monthly Recurring Total @@ -109,13 +114,13 @@ $vendors_added = $row['vendors_added'];