@foreach($displayDates as $i => $displayDate)
@php
//skip dates and decrement skip count.
if (($skip -1) > 0) {
$skip--;
continue;
}
$formattedDate = $displayDate->format('Y-m-d');
$booking = $bookings->where('BeginDate','<=', $formattedDate)
->where('EndDate','>=', $formattedDate)
->where('_RoomId', $roomId)
->where('_RoomTypeId', $roomTypeId)
->first();
@endphp
@if($booking)
@php
$bookingId = $booking->BookingId;
$beginDate = get_carbon($booking->BeginDate);
$endDate = get_carbon($booking->EndDate);
$zeroNight = $beginDate->eq($endDate);
$bookingStatus = $booking->BookingStatusId;
$booking->setAttribute('_RoomName', $room->RoomName);
$booking->setAttribute('_RoomTypeName', $room->roomType->RoomTypeName);
$bookings->forget($bookingId);
//check if there is a booking that matches the
//current booking's EndDate with it's BeginDate.
$nextBooking = $bookings->where('_RoomId', $roomId)
->where('_RoomTypeId', $roomTypeId)
->where('BeginDate', $endDate->format('Y-m-d'))
->where('EndDate', '>', $endDate->format('Y-m-d'))
->first();
//opposite concept as $nextBooking.
$prevBooking = $prevBookings->where('_RoomId', $roomId)
->where('_RoomTypeId', $roomTypeId)
->where('EndDate', $beginDate->format('Y-m-d'))
->first();
//count booking days so we know how many indexes (dates)
//we need to skip.
$diffDays = $endDate->diffInDays($formattedDate);
$skip = $diffDays > 0 ? $diffDays : 1;
//calculate colspan for current booking cell.
if ((count($displayDates) - ($i)) < $skip) {
//days count is higher that dates so we will
//set the colspan to available dates.
$skip = (count($displayDates) - ($i));
}
$cellWidth = $skip * 160;
//we want just one condition to execute so we are using
//elseif instead two if statements.
if ($bookingStatus == 7 && $zeroNight && $nextBooking) {
$cellWidth -= 80;
} else if ($zeroNight && $beginDate->eq(now()->startOfDay())) {
$cellWidth -= 80;
}
$prevBookings->push($booking);
@endphp
@component('admin.reservations.includes.booking-details',[
'roomId' => $roomId,
'roomTypeId' => $roomTypeId,
'booking' => $booking,
'cellWidth' => $cellWidth,
'displayDate' => $displayDate->format('Y-m-d'),
'folioChargeTypes' => $folioChargeTypes,
'folioPaymentTypes' => $folioPaymentTypes,
'folioCardTypes' => $folioCardTypes,
'isCalendar' => true,
])
@endcomponent
@if($nextBooking && get_carbon($nextBooking->BeginDate)->eq(get_carbon($booking->BeginDate)))
@component('admin.reservations.includes.booking-details',[
'roomId' => $roomId,
'roomTypeId' => $roomTypeId,
'booking' => $nextBooking,
'cellWidth' => 80,
'displayDate' => $displayDate->format('Y-m-d'),
'folioChargeTypes' => $folioChargeTypes,
'folioPaymentTypes' => $folioPaymentTypes,
'folioCardTypes' => $folioCardTypes,
'isCalendar' => true,
])
@endcomponent
@php
$bookings->forget($nextBooking->BookingId);
$prevBookings->forget($booking->BookingId);
$prevBookings->push($nextBooking)
@endphp
@elseif($zeroNight && now()->subDays(1)->lt($displayDate))
@endif
@php $cells += $skip; @endphp
@else
subDays(1)->lt($displayDate))
class="booking-cell td-no-booking"
data-room-id="{{$room->RoomId}}"
data-roomtype-id="{{$room->RoomTypeId}}"
data-date="{{$displayDate->format('Y-m-d')}}"
style="cursor: pointer"
@else
class="booking-cell td-no-booking grey lighten-3"
readonly
@endif
>
@php $cells++; @endphp
@endif
@if($cells >= 30)
@php
//we are at the last cell (by count) so reset the
//cells count to 0 and stop the loop and go to next index.
$cells = 0;
$skip = 0;
break;
@endphp
@endif
@endforeach