Files
app3/resources/views/admin/hotels/_calendar.blade.php
2026-01-26 09:06:06 +00:00

97 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div>
@if($roomTypes->isEmpty())
<p>Нет типов номеров. <a href="{{ route('admin.room-types.create') }}">Создать тип номера</a></p>
@else
@foreach($roomTypes as $type)
<div style="margin-bottom: 25px; padding: 15px; border: 1px solid #eee; border-radius: 6px;">
<h3>{{ $type->name }}</h3>
<!-- Форма добавления периода -->
<form class="availability-form" data-room-type-id="{{ $type->id }}" style="margin-bottom: 15px;">
@csrf
<div style="display: flex; gap: 10px; margin-bottom: 10px;">
<input type="date" name="start_date" required style="flex:1; padding:6px; border:1px solid #ccc; border-radius:4px;">
<input type="date" name="end_date" required style="flex:1; padding:6px; border:1px solid #ccc; border-radius:4px;">
</div>
<div style="margin-bottom: 10px;">
<label>
<input type="checkbox" name="is_available" value="1" checked> Доступен
</label>
</div>
<div style="margin-bottom: 10px;">
<input type="number" name="price" step="0.01" placeholder="Цена" style="width:100%; padding:6px; border:1px solid #ccc; border-radius:4px;">
</div>
<button type="submit" class="btn" style="padding:6px 12px;">Сохранить</button>
</form>
<!-- Список периодов -->
@if($type->availabilities->isEmpty())
<p>Нет периодов.</p>
@else
<table style="width:100%; font-size:0.9rem;">
<thead>
<tr>
<th>С</th>
<th>По</th>
<th>Статус</th>
<th>Цена</th>
<th>Действие</th>
</tr>
</thead>
<tbody>
@foreach($type->availabilities as $period)
<tr>
<td>{{ $period->start_date }}</td>
<td>{{ $period->end_date }}</td>
<td>
@if($period->is_available)
<span style="color:green;">Доступен</span>
@else
<span style="color:red;">Недоступен</span>
@endif
</td>
<td>{{ $period->price ? number_format($period->price, 2) : '-' }}</td>
<td>
<form method="POST" action="/admin/availability/{{ $period->id }}" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger" style="padding:4px 8px; font-size:0.8rem;" onclick="return confirm('Удалить период?')">
Удалить
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
@endforeach
@endif
</div>
<script>
document.querySelectorAll('.availability-form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const roomTypeId = form.dataset.roomTypeId;
try {
const response = await fetch(`/admin/room-types/${roomTypeId}/availability`, {
method: 'POST',
body: formData,
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
if (response.ok) {
location.reload(); // Обновить модалку
} else {
alert('Ошибка сохранения');
}
} catch (error) {
alert('Ошибка сети');
}
});
});
</script>