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 #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');
        }
    }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id, Request $request)
 {
     $roomtype = RoomType::findOrFail($id);
     $roomtype->removePictures();
     $message = "";
     try {
         $roomtype->delete();
         $message = trans('appstrings.item_removed', ['item' => $roomtype->name]);
         Session::flash('message_type', 'success');
     } catch (\PDOException $e) {
         $message = trans('sqlmessages.' . $e->getCode());
         if ($message == 'sqlmessages.' . $e->getCode()) {
             $message = trans('sqlmessages.undefined');
         }
         if ($request->ajax()) {
             return ['code' => 'error', 'message' => $message];
         }
         Session::flash('message_type', 'error');
     }
     if ($request->ajax()) {
         return ['code' => 'ok', 'message' => $message];
     }
     Session::flash('message', $message);
     return redirect()->route('admin.room_types.index');
 }