|
|
<?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) { |
|
|
|
|
|
$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' |
|
|
)); |
|
|
} |
|
|
} |
|
|
|