diff --git a/agent/dashboard.php b/agent/dashboard.php index 7355b1925..de218b403 100644 --- a/agent/dashboard.php +++ b/agent/dashboard.php @@ -1025,14 +1025,40 @@ if ($user_config_dashboard_technical_enable == 1) { data: { labels: [ 0 + UNION ALL + SELECT revenue_category_id AS income_category_id, revenue_amount AS amount + FROM revenues + WHERE YEAR(revenue_date) = $year AND revenue_category_id > 0) AS income + INNER JOIN categories ON category_id = income.income_category_id + GROUP BY category_name, category_id + ORDER BY total_income DESC LIMIT 5"); $sql_categories = mysqli_query($mysqli, "SELECT category_name FROM TopCategories"); while ($row = mysqli_fetch_assoc($sql_categories)) { $category_name = json_encode($row['category_name']); echo "$category_name,"; } - $sql_other_categories = mysqli_query($mysqli, "SELECT SUM(invoices.invoice_amount) AS other_income FROM categories LEFT JOIN TopCategories ON categories.category_id = TopCategories.category_id INNER JOIN invoices ON categories.category_id = invoices.invoice_category_id WHERE TopCategories.category_id IS NULL AND invoice_status = 'Paid' AND YEAR(invoice_date) = $year"); + $sql_other_categories = mysqli_query($mysqli, "SELECT SUM(income.amount) AS other_income + FROM (SELECT invoice_category_id AS income_category_id, payment_amount AS amount + FROM payments + INNER JOIN invoices ON invoice_id = payment_invoice_id + WHERE YEAR(payment_date) = $year AND invoice_category_id > 0 + UNION ALL + SELECT revenue_category_id AS income_category_id, revenue_amount AS amount + FROM revenues + WHERE YEAR(revenue_date) = $year AND revenue_category_id > 0) AS income + LEFT JOIN TopCategories ON TopCategories.category_id = income.income_category_id + WHERE TopCategories.category_id IS NULL"); $row = mysqli_fetch_assoc($sql_other_categories); $other_income = floatval($row['other_income']); if ($other_income > 0) {