ldc-boutique-cnc-sable/infra/Adapters/Services/EloquentEmployeeStatisticsService.php
2026-10-27 09:58:12 +01:00

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Infrastructure\Adapters\Services;
use App\Models\Order;
use Carbon\CarbonInterface;
use Domain\Enums\OrderStatus;
use Domain\Models\ValueObjects\Matricule;
use Domain\Ports\Services\EmployeeStatisticsService;
use Money\Currency;
use Money\Money;
class EloquentEmployeeStatisticsService implements EmployeeStatisticsService
{
private Currency $appDefaultCurrency;
public function __construct()
{
$currencyCode = config()->string('app.currency');
if ($currencyCode === '') {
$currencyCode = 'EUR';
}
/** @var non-empty-string $currencyCode */
$this->appDefaultCurrency = new Currency($currencyCode);
}
public function getWeeklyTotalForEmployee(Matricule $matricule, CarbonInterface $start, CarbonInterface $end): Money
{
$weekTotal = Order::query()
->where('employee_matricule', $matricule->value)
->where('status', OrderStatus::VALIDATED)
->whereBetween('pickup_day', [$start, $end])
->sum('total');
return new Money((int) $weekTotal, $this->appDefaultCurrency);
}
}