65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Contracts\Repositories\OrderRepository;
|
|
use App\Models\Order;
|
|
use Carbon\CarbonInterface;
|
|
use Domain\Enums\OrderStatus;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Ramsey\Uuid\UuidInterface;
|
|
|
|
class EloquentOrderRepository implements OrderRepository
|
|
{
|
|
/** @return array<int, Order> */
|
|
public function getAll(): array
|
|
{
|
|
return Order::query()->get()->all();
|
|
}
|
|
|
|
public function find(UuidInterface $id): ?Order
|
|
{
|
|
return Order::query()->find($id->toString());
|
|
}
|
|
|
|
public function persist(Order $order): void
|
|
{
|
|
$order->save();
|
|
}
|
|
|
|
public function delete(Order $order): void
|
|
{
|
|
$order->delete();
|
|
}
|
|
|
|
/** @return array<int, Order> */
|
|
public function getValidatedOrdersForPickupDay(CarbonInterface $pickupDay): array
|
|
{
|
|
return Order::query()
|
|
->whereDate('pickup_day', $pickupDay->format('Y-m-d'))
|
|
->where('status', OrderStatus::VALIDATED)
|
|
->get()
|
|
->all();
|
|
}
|
|
|
|
public function hasValidatedOrderForPickupDay(Matricule $matricule, CarbonInterface $pickupDay): bool
|
|
{
|
|
return Order::query()
|
|
->where('employee_matricule', $matricule->value)
|
|
->whereDate('pickup_day', $pickupDay->format('Y-m-d'))
|
|
->where('status', OrderStatus::VALIDATED)
|
|
->exists();
|
|
}
|
|
|
|
/** @return array<int, Order> */
|
|
public function getOrdersWithLinesAndShopForPickupDay(CarbonInterface $pickupDay): array
|
|
{
|
|
return Order::query()
|
|
->with(['lines', 'shop'])
|
|
->whereDate('pickup_day', $pickupDay->format('Y-m-d'))
|
|
->get()
|
|
->all();
|
|
}
|
|
}
|