ldc-cocotte/app/Http/Controllers/Bo/DashboardController.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2020-11-03 15:53:07 +01:00
<?php
2026-06-14 21:32:07 +02:00
declare(strict_types=1);
2020-11-03 15:53:07 +01:00
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
2026-06-14 21:32:07 +02:00
use App\Http\Requests\Bo\Dashboard\DashboardRequest;
use App\Models\Customer;
use App\Models\Employee;
use App\Services\StatsService;
use Domain\Enums\StatsCustomerType;
use Domain\Enums\StatsShopType;
2020-11-03 15:53:07 +01:00
class DashboardController extends Controller
{
2022-09-08 13:02:16 +02:00
/**
* Dashboard Page
*
* @return \Illuminate\Contracts\View\View
*/
2026-06-14 21:32:07 +02:00
public function index(DashboardRequest $request, StatsService $statsService)
2020-11-03 15:53:07 +01:00
{
$statsShop = [];
2026-06-14 21:32:07 +02:00
$adhesion = $statsService->getMembershipPercentage();
$statsCustomer = [];
$prevDates = [];
2023-08-30 08:03:04 +00:00
2026-06-14 21:32:07 +02:00
$start = $request->getStart();
$end = $request->getEnd();
2026-06-14 21:32:07 +02:00
if ($start && $end) {
$prevDates = $statsService->getPreviousPeriod($start, $end);
$statsShop = $statsService->getStats(StatsShopType::cases(), $start, $end);
$statsCustomer = $statsService->getStats(StatsCustomerType::cases(), $start, $end);
2023-08-30 08:03:04 +00:00
}
2026-06-14 21:32:07 +02:00
$employeeCount = Employee::query()->count();
$customersLinkedToEmployeeCount = Customer::query()->has('employee')->count();
return view('bo.dashboard', compact(
'prevDates',
'statsShop',
'statsCustomer',
2026-06-14 21:32:07 +02:00
'adhesion',
'employeeCount',
'customersLinkedToEmployeeCount',
));
2020-11-03 15:53:07 +01:00
}
}