2026-10-01 10:28:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Queries\Dashboard;
|
|
|
|
|
|
|
|
|
|
use App\Contracts\Query;
|
|
|
|
|
use App\Contracts\QueryInput;
|
2026-10-01 11:25:05 +02:00
|
|
|
use App\Models\Employee;
|
2026-10-01 10:28:08 +02:00
|
|
|
use App\Services\StatsService;
|
|
|
|
|
use Domain\Enums\StatsCustomerType;
|
|
|
|
|
use Domain\Enums\StatsShopType;
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @implements \App\Contracts\Query<\App\Queries\Dashboard\GetBoDashboardQueryInput, \App\Queries\Dashboard\GetBoDashboardQueryOutput>
|
|
|
|
|
*/
|
|
|
|
|
final readonly class GetBoDashboardQuery implements Query
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private StatsService $statsService,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function __invoke(QueryInput $input): GetBoDashboardQueryOutput
|
|
|
|
|
{
|
|
|
|
|
Assert::isInstanceOf($input, GetBoDashboardQueryInput::class);
|
|
|
|
|
|
|
|
|
|
$statsShop = [];
|
|
|
|
|
$adhesion = $this->statsService->getMembershipPercentage();
|
|
|
|
|
$statsCustomer = [];
|
|
|
|
|
$prevDates = null;
|
|
|
|
|
|
|
|
|
|
if ($input->start !== null && $input->end !== null) {
|
|
|
|
|
$prevDates = $this->statsService->getPreviousPeriod($input->start, $input->end);
|
|
|
|
|
$statsShop = $this->statsService->getStats(StatsShopType::cases(), $input->start, $input->end);
|
|
|
|
|
$statsCustomer = $this->statsService->getStats(StatsCustomerType::cases(), $input->start, $input->end);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
$employeeCount = Employee::query()->active()->count();
|
|
|
|
|
$customersLinkedToEmployeeCount = Employee::query()->active()->whereHas('customer')->count();
|
2026-10-01 10:28:08 +02:00
|
|
|
|
|
|
|
|
return new GetBoDashboardQueryOutput(
|
|
|
|
|
employeeCount: $employeeCount,
|
|
|
|
|
customersLinkedToEmployeeCount: $customersLinkedToEmployeeCount,
|
|
|
|
|
adhesion: $adhesion,
|
|
|
|
|
prevDates: $prevDates,
|
|
|
|
|
statsShop: $statsShop,
|
|
|
|
|
statsCustomer: $statsCustomer,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|