Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\BookingStatus;
|
|
use App\Models\Booking;
|
|
use App\Models\Guest;
|
|
use App\Models\Property;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<Booking>
|
|
*/
|
|
class BookingFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$arrival = now()->addDays(fake()->numberBetween(30, 200))->startOfDay();
|
|
|
|
return [
|
|
'property_id' => Property::factory(),
|
|
'guest_id' => Guest::factory(),
|
|
'status' => BookingStatus::Confirmed,
|
|
'arrival' => $arrival->toDateString(),
|
|
'departure' => $arrival->copy()->addDays(7)->toDateString(),
|
|
'guests' => 2,
|
|
'quote' => [],
|
|
'total' => 80000,
|
|
'deposit' => 20000,
|
|
'balance_due_on' => $arrival->copy()->subDays(28)->toDateString(),
|
|
];
|
|
}
|
|
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (Booking $booking): void {
|
|
Guest::withoutGlobalScope('tenant')
|
|
->whereKey($booking->guest_id)
|
|
->where('tenant_id', '!=', $booking->tenant_id)
|
|
->update(['tenant_id' => $booking->tenant_id]);
|
|
});
|
|
}
|
|
|
|
public function reserved(?\DateTimeInterface $holdExpiresAt = null): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'status' => BookingStatus::Reserved,
|
|
'hold_expires_at' => $holdExpiresAt ?? now()->addHours(48),
|
|
]);
|
|
}
|
|
}
|