public function listAll($fromDate, $toDate) { $bookingList = array(); $bookings = Booking::where('check_in', ">=", $fromDate)->where('check_out', "<=", $toDate)->where('id_property', session('current_property')->id)->get(); $rooms = RoomType::all(); if ($bookings->count() > 0 && count($rooms) > 0) { foreach ($rooms as $room) { $bookingsByRoom = $bookings->where('id_room_type', $room->id); foreach ($bookingsByRoom as $booking) { if ($booking !== null) { $roomId = $booking->roomType->id; $roomName = $booking->roomType->name; //send the date along with the hour because the gantt widget needs it, otherwise //it gets confused with the timezone according to reports in the provider's bug tracker $checkIn = "/Date(" . strtotime($booking->check_in . "23:59:00") * 1000 . ")/"; $checkOut = "/Date(" . strtotime($booking->check_out . "23:59:00") * 1000 . ")/"; $person = $booking->personData->full_name; $registeredListItem = false; for ($i = 0; $i < count($bookingList); $i++) { if ($bookingList[$i]['name'] === $roomName) { $bookingList[$i]['values'][] = ["from" => $checkIn, "to" => $checkOut, "label" => $person, "customClass" => "ganttRed"]; $registeredListItem = true; break; } } if (!$registeredListItem) { $bookingList[] = ["name" => $roomName, "id" => $roomId, "values" => [["from" => $checkIn, "to" => $checkOut, "label" => $person, "customClass" => "ganttRed"]]]; } } else { $bookingList[] = ["name" => $room->name, "id" => $room->id, "values" => []]; } } } } $bookingList[] = ["name" => "", "values" => [["from" => $fromDate, "to" => $toDate, "label" => "", "customClass" => "control-element"]]]; return json_encode($bookingList); //return $fromDate . " " . $toDate; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $room_types = RoomType::all(); return view('admin.room_types.index', compact('room_types')); }