public function delete(Request $request, $id)
 {
     $viewingSchedule = ViewingSchedule::findOrFail($id);
     $user = Auth::user();
     if (!$user->is('administrator')) {
         abort(401, 'Unauthorized action.');
     }
     $viewingSchedule->delete();
     return redirect($request->get('backUrl', route('admin.viewing_schedule.index')))->with('messages', ['Viewing Schedule has been deleted.']);
 }
 public function quickEdit(Request $request, $id)
 {
     $viewingSchedule = ViewingSchedule::findOrFail($id);
     if ($request->isMethod('POST')) {
         $rules = ['viewing_from' => 'required|date_format:Y-m-d H:i|after:now', 'viewing_until' => 'required|date_format:Y-m-d H:i|after:now', 'status' => 'required|in:' . implode(',', array_keys(ViewingSchedule::getStatusLabel()))];
         $this->validate($request, $rules);
         $viewingSchedule->update(['viewing_from' => \DateTime::createFromFormat('Y-m-d H:i', $request->input('viewing_from'))->format('Y-m-d H:i:s'), 'viewing_until' => \DateTime::createFromFormat('Y-m-d H:i', $request->input('viewing_until'))->format('Y-m-d H:i:s'), 'status' => $request->input('status')]);
         return redirect($request->get('backUrl', route('agent.viewing_schedule.index')))->with('messages', ['Viewing schedule is updated.']);
     }
     return view('agent.viewing_schedules.quick_edit_form', ['viewingSchedule' => $viewingSchedule]);
 }
Example #3
0
 public function getViewingsMyPropertiesData(Request $request)
 {
     $user = Auth::user();
     $myProperties = $user->properties->lists('id');
     $viewingSchedules = ViewingSchedule::confirmed()->whereIn('property_id', $myProperties->all())->where('viewing_from', '>=', \DateTime::createFromFormat('Y-m-d', $request->input('start')))->where('viewing_until', '<=', \DateTime::createFromFormat('Y-m-d', $request->input('end')))->get();
     $return = [];
     foreach ($viewingSchedules as $viewingSchedule) {
         $return[] = ['title' => $viewingSchedule->property->property_name, 'start' => $viewingSchedule->viewing_from->toIso8601String(), 'end' => $viewingSchedule->viewing_until->toIso8601String(), 'className' => 'bg-yellow'];
     }
     return response()->json($return);
 }
 public function postScheduleViewing(Request $request, $id)
 {
     $user = Auth::user();
     $property = Property::findOrFail($id);
     $property->load('agentList');
     $allowedTime = array_keys(Property::getViewingTimeLabel());
     $rules = ['viewing_date' => 'required|date_format:Y-m-d', 'viewing_time' => ['required', 'in:' . implode(',', $allowedTime)]];
     $this->validate($request, $rules);
     $viewingTime = str_replace('_', ':', $request->input('viewing_time'));
     $viewingFrom = \DateTime::createFromFormat('Y-m-d H:i', $request->input('viewing_date') . ' ' . $viewingTime);
     $viewingTo = clone $viewingFrom;
     $viewingTo->modify('+2 hours');
     $viewingSchedule = ViewingSchedule::where('user_id', $user->id)->where('property_id', $property->id)->first();
     if ($property->agentList) {
         $agent = $property->agentList;
     } else {
         $agent = ProjectHelper::getDefaultAgent();
     }
     if (!$viewingSchedule) {
         $viewingSchedule = new ViewingSchedule();
         $viewingSchedule->user()->associate($user);
         $viewingSchedule->property()->associate($property);
         if ($agent) {
             $viewingSchedule->agent()->associate($agent);
         }
         $reschedule = FALSE;
     } else {
         $reschedule = TRUE;
     }
     $viewingSchedule->fill(['viewing_from' => $viewingFrom->format('Y-m-d H:i:s'), 'viewing_until' => $viewingTo->format('Y-m-d H:i:s')]);
     $viewingSchedule->status = ViewingSchedule::STATUS_PENDING;
     $viewingSchedule->save();
     if ($reschedule) {
         Event::fire(new ViewingScheduleEvent($viewingSchedule, 'reschedule'));
     } else {
         Event::fire(new ViewingScheduleEvent($viewingSchedule, 'new'));
     }
     $conversation = $user->getPropertyConversation($property);
     if (!$conversation) {
         $user->createPropertyConversation($property, $agent);
     }
     if ($reschedule) {
         $message = trans('property.schedule_viewing.reschedule_success_message');
     } else {
         $message = trans('property.schedule_viewing.success_message');
     }
     return redirect()->back()->with('messages', [$message]);
 }