ldc-boutique-cnc-sable/app/Http/Controllers/Bo/DashboardController.php

55 lines
1.6 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\Contracts\Directories\EmployeeDirectory;
2020-11-03 15:53:07 +01:00
use App\Http\Controllers\Controller;
2026-06-14 21:32:07 +02:00
use App\Http\Requests\Bo\Dashboard\DashboardRequest;
use App\Services\StatsService;
use Domain\Enums\StatsCustomerType;
use Domain\Enums\StatsShopType;
2020-11-03 15:53:07 +01:00
class DashboardController extends Controller
{
public function __construct(
private readonly EmployeeDirectory $employeeDirectory,
) {
}
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 = $this->employeeDirectory->countActiveEmployees();
$customersLinkedToEmployeeCount = $this->employeeDirectory->countActiveRegisteredEmployees();
2026-06-14 21:32:07 +02:00
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
}
}