From 40789eff32e663a402991f7b9b20022512943c18 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sun, 1 Jan 2023 13:40:18 +0000 Subject: [PATCH] Deduplicate sql payment years query --- dashboard_financial.php | 3 - dashboard_technical.php | 898 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 898 insertions(+), 3 deletions(-) create mode 100644 dashboard_technical.php diff --git a/dashboard_financial.php b/dashboard_financial.php index 696eab02..941970b9 100644 --- a/dashboard_financial.php +++ b/dashboard_financial.php @@ -27,9 +27,6 @@ if(isset($_GET['year'])){ //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 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"); //Define var so it doesnt throw errors in logs $largest_income_month = 0; diff --git a/dashboard_technical.php b/dashboard_technical.php new file mode 100644 index 00000000..94f81745 --- /dev/null +++ b/dashboard_technical.php @@ -0,0 +1,898 @@ + + + 0 AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_total_revenues); +$total_revenues = $row['total_revenues']; + +$total_income = $total_payments_to_invoices + $total_revenues; + +//Get Total expenses and do not grab transfer expenses as these have a vendor of 0 +$sql_total_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE expense_vendor_id > 0 AND YEAR(expense_date) = $year AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_total_expenses); +$total_expenses = $row['total_expenses']; + +//Total up all the Invoices that are not draft or cancelled +$sql_invoice_totals = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_totals FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' AND YEAR(invoice_date) = $year AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_invoice_totals); +$invoice_totals = $row['invoice_totals']; + +//Quaeries from Receivables +$sql_total_payments_to_invoices_all_years = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments_to_invoices_all_years FROM payments WHERE company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_total_payments_to_invoices_all_years); +$total_payments_to_invoices_all_years = $row['total_payments_to_invoices_all_years']; + +$sql_invoice_totals_all_years = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_totals_all_years FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_invoice_totals_all_years); +$invoice_totals_all_years = $row['invoice_totals_all_years']; + +$receivables = $invoice_totals_all_years - $total_payments_to_invoices_all_years; + +$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 + AND clients.company_id = $session_company_id + 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 + AND expenses.company_id = $session_company_id + ORDER BY expense_id DESC LIMIT 5" +); + +//Get Monthly Recurring Total +$sql_recurring_monthly_total = mysqli_query($mysqli,"SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_recurring_monthly_total); +$recurring_monthly_total = $row['recurring_monthly_total']; + +//Get Yearly Recurring Total +$sql_recurring_yearly_total = mysqli_query($mysqli,"SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_recurring_yearly_total); +$recurring_yearly_total = $row['recurring_yearly_total']; + +//Get Total Miles Driven +$sql_miles_driven = mysqli_query($mysqli,"SELECT SUM(trip_miles) AS total_miles FROM trips WHERE YEAR(trip_date) = $year AND company_id = $session_company_id"); +$row = mysqli_fetch_array($sql_miles_driven); +$total_miles = $row['total_miles']; + +//Get Total Clients added +$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('client_id') AS clients_added FROM clients WHERE YEAR(client_created_at) = $year AND company_id = $session_company_id")); +$clients_added = $row['clients_added']; + +//Get Total Vendors added +$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('vendor_id') AS vendors_added FROM vendors WHERE YEAR(vendor_created_at) = $year AND vendor_client_id = 0 AND company_id = $session_company_id")); +$vendors_added = $row['vendors_added']; + +?> + +
+ +
+ + +
+ + + + + + +
+ +
+
+

+

Profit

+
+
+ +
+
+
+ + +
+ +
+
+

+

Monthly Recurring

+
+
+ +
+
+
+ + +
+ +
+
+

+

Yearly Recurring

+
+
+ +
+
+
+ + + + + + + + + + + +
+
+
+

Cash Flow

+
+ + + + +
+
+
+ +
+
+
+ +
+
+
+

Trip Flow

+
+ + + + +
+
+
+ +
+
+
+ +
+
+
+

Income By Category

+
+ +
+
+
+ +
+
+
+ +
+
+
+

Expenses By Category

+
+ +
+
+
+ +
+
+
+ +
+
+
+

Expenses By Vendor

+
+ +
+
+
+ +
+
+
+ +
+
+
+

Account Balance

+
+ +
+
+
+ + + + + + + + + + + +
+
+
+
+
+
+
+

Latest Income

+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + +
DateCustomerInvoiceAmount
+
+
+
+
+
+
+

Latest Expenses

+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + +
DateVendorCategoryAmount
+
+
+
+
+ + + \ No newline at end of file