feat: establish reservation portal foundation
This commit is contained in:
32
app/Domain/Reservations/Services/AvailabilityService.php
Normal file
32
app/Domain/Reservations/Services/AvailabilityService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reservations\Services;
|
||||
|
||||
use App\Domain\Inventory\Models\SnipeAsset;
|
||||
use App\Domain\Reservations\Enums\ReservationItemStatus;
|
||||
use DateTimeInterface;
|
||||
|
||||
class AvailabilityService
|
||||
{
|
||||
public function isAvailable(SnipeAsset $asset, DateTimeInterface $startsAt, DateTimeInterface $endsAt): bool
|
||||
{
|
||||
if (! $asset->active || ! $asset->requestable || $asset->assigned_id !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hasReservationConflict = $asset->reservationItems()
|
||||
->whereIn('status', ReservationItemStatus::blockingValues())
|
||||
->where('starts_at', '<', $endsAt)
|
||||
->where('ends_at', '>', $startsAt)
|
||||
->exists();
|
||||
|
||||
if ($hasReservationConflict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $asset->blocks()
|
||||
->where('starts_at', '<', $endsAt)
|
||||
->where('ends_at', '>', $startsAt)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user