Deploy on 2026-06-05 16:08:53
This commit is contained in:
@@ -20,9 +20,6 @@ class DashboardController extends Controller
|
||||
|
||||
public function index(Request $request, Response $response): string
|
||||
{
|
||||
$user = $request->routeParam('_authenticated_user');
|
||||
$lang = $this->session->get('lang', 'en');
|
||||
|
||||
// Real stats from database
|
||||
$orgCount = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE deleted_at IS NULL")->fetchColumn();
|
||||
$vcCount = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE type='vc' AND deleted_at IS NULL")->fetchColumn();
|
||||
@@ -31,6 +28,8 @@ class DashboardController extends Controller
|
||||
$contactCount = (int)$this->pdo->query("SELECT COUNT(*) FROM contacts WHERE deleted_at IS NULL")->fetchColumn();
|
||||
$sourceCount = (int)$this->pdo->query("SELECT COUNT(*) FROM sources WHERE status='active'")->fetchColumn();
|
||||
$todayOpps = (int)$this->pdo->query("SELECT COUNT(*) FROM opportunities WHERE DATE(created_at) = CURDATE()")->fetchColumn();
|
||||
$todayContacts = (int)$this->pdo->query("SELECT COUNT(*) FROM contacts WHERE DATE(created_at) = CURDATE() AND deleted_at IS NULL")->fetchColumn();
|
||||
$todayOrgs = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE DATE(created_at) = CURDATE() AND deleted_at IS NULL")->fetchColumn();
|
||||
|
||||
// Recent opportunities
|
||||
$stmt = $this->pdo->query(
|
||||
@@ -50,14 +49,45 @@ class DashboardController extends Controller
|
||||
$stmt = $this->pdo->query("SELECT * FROM activity_logs ORDER BY created_at DESC LIMIT 10");
|
||||
$recentActivities = $stmt->fetchAll() ?: [];
|
||||
|
||||
$langFile = __DIR__ . "/../../resources/lang/{$lang}.php";
|
||||
$t = file_exists($langFile) ? require $langFile : [];
|
||||
// 6-month growth data
|
||||
$months = [];
|
||||
$opportunityMonthly = [];
|
||||
$interactionMonthly = [];
|
||||
for ($i = 5; $i >= 0; $i--) {
|
||||
$date = new \DateTime("-$i months");
|
||||
$key = $date->format('Y-m');
|
||||
$name = $date->format('M');
|
||||
$months[$key] = $name;
|
||||
$opportunityMonthly[$key] = 0;
|
||||
$interactionMonthly[$key] = 0;
|
||||
}
|
||||
|
||||
$oppsQuery = $this->pdo->query(
|
||||
"SELECT DATE_FORMAT(created_at, '%Y-%m') as month, COUNT(*) as count
|
||||
FROM opportunities
|
||||
WHERE deleted_at IS NULL AND created_at >= DATE_SUB(NOW(), INTERVAL 6 MONTH)
|
||||
GROUP BY month"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR) ?: [];
|
||||
|
||||
$interQuery = $this->pdo->query(
|
||||
"SELECT DATE_FORMAT(created_at, '%Y-%m') as month, COUNT(*) as count
|
||||
FROM interactions
|
||||
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 6 MONTH)
|
||||
GROUP BY month"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR) ?: [];
|
||||
|
||||
foreach ($oppsQuery as $monthKey => $count) {
|
||||
if (isset($opportunityMonthly[$monthKey])) {
|
||||
$opportunityMonthly[$monthKey] = (int)$count;
|
||||
}
|
||||
}
|
||||
foreach ($interQuery as $monthKey => $count) {
|
||||
if (isset($interactionMonthly[$monthKey])) {
|
||||
$interactionMonthly[$monthKey] = (int)$count;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/dashboard', [
|
||||
'user' => $user,
|
||||
'title' => $t['dashboard'] ?? 'Dashboard',
|
||||
't' => $t,
|
||||
'lang' => $lang,
|
||||
'stats' => [
|
||||
'organizations' => $orgCount,
|
||||
'vc' => $vcCount,
|
||||
@@ -66,10 +96,15 @@ class DashboardController extends Controller
|
||||
'contacts' => $contactCount,
|
||||
'sources' => $sourceCount,
|
||||
'today' => $todayOpps,
|
||||
'today_contacts' => $todayContacts,
|
||||
'today_orgs' => $todayOrgs,
|
||||
],
|
||||
'recent_opportunities' => $recentOpps,
|
||||
'opportunities_by_type' => $byType,
|
||||
'recent_activities' => $recentActivities,
|
||||
'growth_labels' => array_values($months),
|
||||
'growth_opportunities' => array_values($opportunityMonthly),
|
||||
'growth_interactions' => array_values($interactionMonthly),
|
||||
], 'admin');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user