window.location.href = \'dashboard_technical.php\';'); } if (isset($_GET['year'])) { $year = intval($_GET['year']); } else { $year = date('Y'); } //GET unique years from expenses, payments invoices and revenues $sql_years_select = mysqli_query( $mysqli, "SELECT YEAR(expense_date) AS all_years FROM expenses UNION DISTINCT SELECT YEAR(payment_date) FROM payments UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues UNION DISTINCT SELECT YEAR(invoice_date) FROM invoices ORDER BY all_years DESC "); //Define var so it doesnt throw errors in logs $largest_income_month = 0; //Get Total income $sql_total_payments_to_invoices = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments_to_invoices FROM payments WHERE YEAR(payment_date) = $year"); $row = mysqli_fetch_array($sql_total_payments_to_invoices); $total_payments_to_invoices = floatval($row['total_payments_to_invoices']); //Do not grab transfer payment as these have a category_id of 0 $sql_total_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE YEAR(revenue_date) = $year AND revenue_category_id > 0"); $row = mysqli_fetch_array($sql_total_revenues); $total_revenues = floatval($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"); $row = mysqli_fetch_array($sql_total_expenses); $total_expenses = floatval($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"); $row = mysqli_fetch_array($sql_invoice_totals); $invoice_totals = floatval($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"); $row = mysqli_fetch_array($sql_total_payments_to_invoices_all_years); $total_payments_to_invoices_all_years = floatval($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'"); $row = mysqli_fetch_array($sql_invoice_totals_all_years); $invoice_totals_all_years = floatval($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"); $sql_latest_invoice_payments = mysqli_query( $mysqli, "SELECT * FROM payments, invoices, clients WHERE payment_invoice_id = invoice_id AND invoice_client_id = client_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 ORDER BY expense_id DESC LIMIT 5" ); //Get Yearly Recurring Income 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 YEAR(recurring_created_at) <= $year"); $row = mysqli_fetch_array($sql_recurring_yearly_total); $recurring_yearly_total = floatval($row['recurring_yearly_total']); //Get Monthly Recurring Income 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 YEAR(recurring_created_at) <= $year"); $row = mysqli_fetch_array($sql_recurring_monthly_total); $recurring_monthly_total = floatval($row['recurring_monthly_total']) + ($recurring_yearly_total / 12); //Get Yearly Recurring Expenses Total $sql_recurring_expense_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_expense_amount) AS recurring_expense_yearly_total FROM recurring_expenses WHERE recurring_expense_status = 1 AND recurring_expense_frequency = 2 AND YEAR(recurring_expense_created_at) <= $year"); $row = mysqli_fetch_array($sql_recurring_expense_yearly_total); $recurring_expense_yearly_total = floatval($row['recurring_expense_yearly_total']); //Get Monthly Recurring Expenses Total $sql_recurring_expense_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_expense_amount) AS recurring_expense_monthly_total FROM recurring_expenses WHERE recurring_expense_status = 1 AND recurring_expense_frequency = 1 AND YEAR(recurring_expense_created_at) <= $year"); $row = mysqli_fetch_array($sql_recurring_expense_monthly_total); $recurring_expense_monthly_total = floatval($row['recurring_expense_monthly_total']) + ($recurring_expense_yearly_total / 12); //Get Total Miles Driven $sql_miles_driven = mysqli_query($mysqli, "SELECT SUM(trip_miles) AS total_miles FROM trips WHERE YEAR(trip_date) = $year"); $row = mysqli_fetch_array($sql_miles_driven); $total_miles = floatval($row['total_miles']); //Get Total Recurring Invoices added $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS recurring_invoices_added FROM recurring WHERE YEAR(recurring_created_at) = $year")); $recurring_invoices_added = intval($row['recurring_invoices_added']); //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")); $clients_added = intval($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 vendor_template = 0")); $vendors_added = intval($row['vendors_added']); ?>

Income


Receivables:

Expenses

Profit

Monthly Recurring Income

Monthly Recurring Expense

Recurring Invoices Added

New Clients

New Vendors

Miles Traveled

Cash Flow

Income by Category (Top 5)

Expenses by Category (Top 5)

Expenses by Vendor (Top 5)

Account Balances

Latest Income

Date Customer Invoice Amount

Latest Expenses

Date Vendor Category Amount

Trip Flow