Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $people = \DB::table('people')->lists('id');
     $properties = \DB::table('property_settings')->lists('id');
     $roomTypes = \DB::table('room_types')->lists('id');
     $ratePlans = \DB::table('rates')->lists('id');
     for ($i = 0; $i < 10; $i++) {
         $checkIn = $faker->dateTimeBetween('now', '+6 months')->format("Y-m-d");
         $checkOut = date('Y-m-d', strtotime($checkIn) + 345600);
         $reference_code;
         do {
             $reference_code = str_random(10);
         } while (count(Booking::where('reference_code', $reference_code)->get()) > 0);
         \DB::table('bookings')->insert(array('id_property' => $properties[array_rand($properties, 1)], 'id_user' => 2, 'person' => $people[array_rand($people, 1)], 'date' => date('Y-m-d'), 'check_in' => $checkIn, 'check_out' => $checkOut, 'arrival_time' => $faker->time($format = 'H:i:s', $max = 'now'), 'comments_and_requests' => "", 'id_room_type' => $roomTypes[array_rand($roomTypes, 1)], 'number_of_rooms' => 2, 'adults' => 1, 'children' => 0, 'pets' => 0, 'rate_plan' => $ratePlans[array_rand($ratePlans, 1)], 'notification' => 'none', 'reference_code' => $reference_code));
     }
 }
Example #2
0
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //dd($this->getRouter()->current()->getAction()["as"]);
        if (session('current_property') !== null) {
            $lastBookings = Booking::where('id_property', session('current_property')->id)->where('status', 'a')->orderBy('check_in', 'desc')->take(10)->get();
            $currentOccupiedRooms = count(Booking::where('check_in', '<=', date('Y-m-d'))->where('check_out', '>=', date('Y-m-d'))->where('id_property', session('current_property')->id)->where('status', 'a')->get());
            $activeBookings = count(Booking::where('status', 'a')->where('id_property', session('current_property')->id)->get());
            $canceledBookings = count(Booking::where('status', 'c')->where('id_property', session('current_property')->id)->get());
            $disabledRooms = count(RoomType::where('available', 0)->where('id_property', session('current_property')->id)->get());
            $year = date('Y');
            $bookingsByMonth = \DB::select('SELECT Month(check_in) as name,count(*) as value 
	    									FROM bookings 
	    									where id_property=' . session('current_property')->id . ' and 
	    										  check_in >= "' . $year . '-01-01" and 
	    										  check_in <= "' . $year . '-12-31"
	    									group by Month(check_in)');
            $biggestValue = 0;
            foreach ($bookingsByMonth as $booking) {
                $booking->name = DateHelper::$mons[$booking->name];
                if ($booking->value > $biggestValue) {
                    $biggestValue = $booking->value;
                }
            }
            $data['lastBookings'] = $lastBookings;
            $data['occupiedRooms'] = $currentOccupiedRooms;
            $data['activeBookings'] = $activeBookings;
            $data['canceledBookings'] = $canceledBookings;
            $data['disabledRooms'] = $disabledRooms;
            $data['bookingsByMonth'] = $bookingsByMonth;
            $data['biggestValue'] = $biggestValue;
            return view('admin.dashboard.index', compact('data'));
        } else {
            $message = trans('appstrings.property_required');
            Session::flash('message', $message);
            //return redirect()->route('admin.dashboardindex');
            return view('admin.dashboard.index');
        }
    }
 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;
 }
Example #4
0
 private function checkAvailability($request, $id = null)
 {
     $booking = Booking::where("id_room_type", $request->get("id_room_type"))->where('id_property', session('current_property')->id)->where("check_in", ">=", $request->get("check_in"))->where("check_in", "<=", $request->get("check_out"))->first();
     if ($booking !== null && $booking->id != $id) {
         $message = "Room already reserved for given dates";
         if ($request->ajax()) {
             return $message;
         }
         Session::flash('message', $message);
         return redirect()->route('admin.booking.create');
     }
 }