@php
$affectations = \App\Models\ReservationChambreTente::where('reservation_id', $reservationId)->get();
$total_aff_male = $affectations->sum('male_personnes');
$total_aff_female = $affectations->sum('female_personnes');
$allAssigned = ($total_aff_male >= $male) && ($total_aff_female >= $female);
$hasAnyAffectation = $affectations->count() > 0;
@endphp
تاريخ الوصول: {{ \Carbon\Carbon::parse($reservation->date_arrive)->format('Y-m-d') }} —
تاريخ المغادرة: {{ \Carbon\Carbon::parse($reservation->date_depart)->format('Y-m-d') }}
عدد الذكور: {{ $male }}
عدد الاناث: {{ $female }}
المجموع: {{ $reservation->nbr_personnes }}
اختر غرفة مناسبة من القائمة التالية.
@forelse($chambres as $ch)
@php
$aff = \App\Models\ReservationChambreTente::where('chambre_tente_id',$ch->id_chambre_tente)->sum('total_personnes');
$reste = $ch->capacite - $aff;
// Récupérer les affectations actuelles de cette chambre pour CETTE réservation
$currentAffectation = \App\Models\ReservationChambreTente::where('chambre_tente_id', $ch->id_chambre_tente)
->where('reservation_id', $reservationId)
->first();
$hasCurrentAssignment = $currentAffectation ? true : false;
$currentMale = $currentAffectation ? $currentAffectation->male_personnes : 0;
$currentFemale = $currentAffectation ? $currentAffectation->female_personnes : 0;
// Récupérer toutes les affectations de cette chambre (toutes réservations)
$allAffectationsChambre = \App\Models\ReservationChambreTente::where('chambre_tente_id', $ch->id_chambre_tente)->get();
$totalMaleInRoom = $allAffectationsChambre->sum('male_personnes');
$totalFemaleInRoom = $allAffectationsChambre->sum('female_personnes');
$remainMale = $male - $total_aff_male;
$remainFemale = $female - $total_aff_female;
// Vérifier si la chambre peut être assignée (disponible et besoins restants)
$canAssignRoom = ($reste > 0) && !$allAssigned;
@endphp
الغرفة رقم: {{ $ch->num_chambre }}
الطاقة الإجمالية: {{ $ch->capacite }}
@if($totalMaleInRoom > 0 || $totalFemaleInRoom > 0)
المشغول حالياً:
@if($totalMaleInRoom > 0)
{{ $totalMaleInRoom }} رجال
@endif
@if($totalFemaleInRoom > 0)
{{ $totalFemaleInRoom }} نساء
@endif
@endif
@if($hasCurrentAssignment)
تعيينك الحالي:
@if($currentMale > 0)
{{ $currentMale }} رجال
@endif
@if($currentFemale > 0)
{{ $currentFemale }} نساء
@endif
@endif
الطاقة المتبقية: {{ $reste }}
@if($canAssignRoom)
@else
@endif
@empty
لا توجد غرف متاحة حاليا في هذا المركب.
@endforelse