From bf4f341ed2360d49ec98747904a7aa1bc71ae117 Mon Sep 17 00:00:00 2001 From: jaytagdamian Date: Fri, 20 Sep 2024 19:26:53 +0100 Subject: [PATCH] Update dashboard.php to add some more data when accounting and ticketing is disabled The dashboard appears completely empty when ticketing and accounting modules are disabled. Modified the page to add some basic dashboard elements (recently updated clients, technical dashboard sans ticketing) --- dashboard.php | 658 +++++++++++++++++--------------------------------- 1 file changed, 216 insertions(+), 442 deletions(-) diff --git a/dashboard.php b/dashboard.php index 18d67ead3..b79c9efb7 100644 --- a/dashboard.php +++ b/dashboard.php @@ -61,7 +61,7 @@ - = 2 && $config_module_enable_ticketing == 1) { ?> + = 2 && $config_module_enable_ticketing == 1 || $session_user_role >= 2) { ?>
> @@ -71,467 +71,239 @@
window.location.href = \'dashboard_technical.php\';'); - } - - // Fetch financial data for the dashboard - // Define variables to avoid errors in logs - $largest_income_month = 0; - - $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']); - - $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; - - $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']); - - $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']); - - $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']); +if ($user_config_dashboard_technical_enable == 1) { + + // fetch client data for the dashboard + $sql_recent_client_updates = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL ORDER BY client_updated_at DESC LIMIT 10"); + + $expiration_days = 90; + // fetch expiry data for the dashboard + // Get Domains Expiring + $sql_domains_expiring = mysqli_query( + $mysqli, + "SELECT * FROM domains + WHERE domain_expire IS NOT NULL + AND domain_archived_at IS NULL + AND domain_expire > CURRENT_DATE + AND domain_expire < CURRENT_DATE + INTERVAL $expiration_days DAY + ORDER BY domain_expire ASC + LIMIT 5" + ); + + // Get Certificates Expiring + $sql_certificates_expiring = mysqli_query( + $mysqli, + "SELECT * FROM certificates + WHERE certificate_expire IS NOT NULL + AND certificate_archived_at IS NULL + AND certificate_expire > CURRENT_DATE + AND certificate_expire < CURRENT_DATE + INTERVAL $expiration_days DAY + ORDER BY certificate_expire ASC + LIMIT 5" + ); + + // Get Licenses Expiring + $sql_licenses_expiring = mysqli_query( + $mysqli, + "SELECT * FROM software + WHERE software_expire IS NOT NULL + AND software_archived_at IS NULL + AND software_expire > CURRENT_DATE + AND software_expire < CURRENT_DATE + INTERVAL $expiration_days DAY + ORDER BY software_expire ASC + LIMIT 5" + ); + + // Get Asset Warranties Expiring + $sql_asset_warranties_expiring = mysqli_query( + $mysqli, + "SELECT * FROM assets + WHERE asset_warranty_expire IS NOT NULL + AND asset_archived_at IS NULL + AND asset_warranty_expire > CURRENT_DATE + AND asset_warranty_expire < CURRENT_DATE + INTERVAL $expiration_days DAY + ORDER BY asset_warranty_expire ASC + LIMIT 5" + ); + + // Get Assets Retiring 7 Year + $sql_asset_retire = mysqli_query( + $mysqli, + "SELECT * FROM assets + WHERE asset_install_date IS NOT NULL + AND asset_archived_at IS NULL + AND asset_install_date + INTERVAL 7 YEAR > CURRENT_DATE -- Not yet expired + AND asset_install_date + INTERVAL 7 YEAR <= CURRENT_DATE + INTERVAL $expiration_days DAY + ORDER BY asset_install_date ASC + LIMIT 5" + ); + + if (mysqli_num_rows($sql_recent_client_updates) > 0) { ?> +
+
+
+
+
Recent Client Activities (Last 10 updates)
+
+
- $receivables = $invoice_totals_all_years - $total_payments_to_invoices_all_years; + + + + + + + - $sql_latest_invoice_payments = mysqli_query($mysqli, " - SELECT * FROM payments - JOIN invoices ON payment_invoice_id = invoice_id - JOIN clients ON invoice_client_id = client_id - ORDER BY payment_id DESC LIMIT 5 - "); + - $sql_latest_expenses = mysqli_query($mysqli, " - SELECT * FROM expenses - JOIN vendors ON expense_vendor_id = vendor_id - JOIN categories ON expense_category_id = category_id - ORDER BY expense_id DESC LIMIT 5 - "); + +
+
+ + + +
+
- // Get recurring totals - $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']); + No recent client activities found.
"; + } + ?> - $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); +
- $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 = 'year' 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']); +
+
+
Upcoming Expirations (within 90 days)
+
+
- $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 = 'month' 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); + 0 + || mysqli_num_rows($sql_certificates_expiring) > 0 + || mysqli_num_rows($sql_asset_warranties_expiring) > 0 + || mysqli_num_rows($sql_asset_retire) > 0 + || mysqli_num_rows($sql_licenses_expiring) > 0 + ) { - if ($config_module_enable_ticketing && $config_module_enable_accounting) { - $sql_unbilled_tickets = mysqli_query($mysqli, "SELECT COUNT(ticket_id) AS unbilled_tickets FROM tickets WHERE ticket_closed_at IS NOT NULL AND ticket_billable = 1 AND ticket_invoice_id = 0 AND YEAR(ticket_created_at) = $year"); - $row = mysqli_fetch_array($sql_unbilled_tickets); - $unbilled_tickets = intval($row['unbilled_tickets']); - } else { - $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']); - } + while ($row = mysqli_fetch_array($sql_domains_expiring)) { + $domain_id = intval($row['domain_id']); + $client_id = intval($row['domain_client_id']); + $domain_name = nullable_htmlentities($row['domain_name']); + $domain_expire = nullable_htmlentities($row['domain_expire']); + $domain_expire_human = timeAgo($row['domain_expire']); - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(client_id) AS clients_added FROM clients WHERE YEAR(client_created_at) = $year AND client_archived_at IS NULL")); - $clients_added = intval($row['clients_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 AND vendor_archived_at IS NULL")); - $vendors_added = intval($row['vendors_added']); -?> -
- - - + while ($row = mysqli_fetch_array($sql_certificates_expiring)) { + $certificate_id = intval($row['certificate_id']); + $client_id = intval($row['certificate_client_id']); + $certificate_name = nullable_htmlentities($row['certificate_name']); + $certificate_expire = nullable_htmlentities($row['certificate_expire']); + $certificate_expire_human = timeAgo($row['certificate_expire']); - - + ?> +

+ + + -- +

+ - - + - - -
-

-

Monthly Recurring Expense

-
-
- -
-
-
- + while ($row = mysqli_fetch_array($sql_asset_warranties_expiring)) { + $asset_id = intval($row['asset_id']); + $client_id = intval($row['asset_client_id']); + $asset_name = nullable_htmlentities($row['asset_name']); + $asset_warranty_expire = nullable_htmlentities($row['asset_warranty_expire']); + $asset_warranty_expire_human = timeAgo($row['asset_warranty_expire']); - - - - - + ?> +

+ + + -- +

- - - - - - - + -
-
-
-

Cash Flow

-
- - - - -
-
-
- -
-
-
+ 0) { + echo "
Retired Assets
"; + } + while ($row = mysqli_fetch_array($sql_asset_retire)) { + $asset_id = intval($row['asset_id']); + $client_id = intval($row['asset_client_id']); + $asset_name = nullable_htmlentities($row['asset_name']); + $asset_install_date = nullable_htmlentities($row['asset_install_date']); + $asset_install_date_human = timeAgo($row['asset_install_date']); -
-
-
-

Income by Category (Top 5)

-
- -
-
-
- -
-
-
+ ?> +

+ + + -- +

-
-
-
-

Expenses by Category (Top 5)

-
- -
-
-
- -
-
-
+ -
-
-
-

Expenses by Vendor (Top 5)

-
- -
-
-
- -
-
-
+ -
-
-

Account Balances

-
- -
-
-
- - - - - - - - - - -
-
-
-
+ while ($row = mysqli_fetch_array($sql_licenses_expiring)) { + $software_id = intval($row['software_id']); + $client_id = intval($row['software_client_id']); + $software_name = nullable_htmlentities($row['software_name']); + $software_expire = nullable_htmlentities($row['software_expire']); + $software_expire_human = timeAgo($row['software_expire']); -
-
-
-

Latest Income

-
- -
-
-
- - - - - - - - - - - - - - - - - - - -
DateCustomerInvoiceAmount
-
-
-
+ ?> +

+ + + -- +

-
-
-
-

Latest Expenses

-
- -
-
-
- - - - - - - - - - - - - - - - - - - -
DateVendorCategoryAmount
-
-
-
+ -
-
-
-

Trip Flow

-
- - - - -
-
-
- -
-
-
- - - - + + -
- -
-

-

Active Tickets

-
-
- -
-
-
- + +
+ +
+

+

Active Tickets

+
+
+ +
+
+
+ +