<td class="text-center">{{ $j . ':00'}}</td> @for($i = 0; $i < Auth::user()->visibleDays(); $i++) <td class="text-center"> {!! Form::open(['route' => 'cliente.reservas.store', 'method' => 'POST']) !!} <?php $fecha_inicio = new DateTime(); $fecha_inicio->setDate($anio, $mes, $dia + $i); $fecha_inicio->setTime($j, 0); $fecha_fin = new DateTime(); $fecha_fin->setDate($anio, $mes, $dia + $i); $fecha_fin->setTime($j + 1, 0); $reserva_aux = Reserva::createReserva($fecha_inicio, $fecha_fin, 1, Auth::user()->id); $estado = Reserva::getStatus($reserva_aux); $reservas_aux = Reserva::where('fecha_inicio', $fecha_inicio->format('Y-m-d H:i:s'))->get(); $count = $reservas_aux->count(); $count_max = Reserva::countMax($reserva_aux); ?> <div class="dropdown"> @if($estado == 'disponible') <div class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Disponible @if($count > 0) <span class="badge">{{$count_max}}</span> <span class="caret"/> @endif </div> @else <a class="btn btn-danger dropdown-toggle" data-toggle="dropdown">No Disponible @if($count > 0) <span class="badge">{{$count_max}}</span> <span class="caret"/> @endif </a> @endif
/** * @param : $reserva * @response : bool * true si la reserva esta disponible */ public static function available($reserva) { $actual = new \DateTime(); return Reserva::countMax($reserva) + $reserva->numero_canchas <= Utilidades::$numero_canchas && $reserva->fecha_inicio > $actual; }