File size: 1,333 Bytes
70ba896
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace App\Http\Controllers;

use App\Services\AnalyticsService;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    protected AnalyticsService $analyticsService;

    public function __construct(AnalyticsService $analyticsService)
    {
        $this->analyticsService = $analyticsService;
    }

    public function index()
    {
        try {
            $todayRevenue = $this->analyticsService->getTodayRevenue();
            $profitData = $this->analyticsService->getProfitData('today');
            $customerAnalytics = $this->analyticsService->getCustomerAnalytics();
            $orderStats = $this->analyticsService->getOrderStats();
        } catch (\Exception $e) {
            // Fallback values if service fails
            $todayRevenue = ['current' => 0, 'previous' => 0, 'percentage_change' => 0, 'trend' => 'up'];
            $profitData = ['profit_margin' => 0, 'percentage_change' => 0, 'trend' => 'up'];
            $customerAnalytics = ['total_customers' => 0, 'active_today' => 0];
            $orderStats = ['current' => 0, 'previous' => 0, 'percentage_change' => 0, 'trend' => 'up'];
        }

        return view('dashboard', compact(
            'todayRevenue',
            'profitData', 
            'customerAnalytics',
            'orderStats'
        ));
    }
}