Beispiel #1
0
 public function actionAll()
 {
     $model = new Appointment();
     $HOSPCODE = \Yii::$app->request->post('HOSPCODE');
     $PID = \Yii::$app->request->post('PID');
     $result = $model->get_appoint_all($HOSPCODE, $PID);
     return $this->renderPartial('all', ['result' => $result]);
 }
 public function generateAppointment(User $issuer, Business $business, Contact $contact, Service $service, Carbon $datetime, $comments = null)
 {
     $appointment = new Appointment();
     $appointment->doReserve();
     $appointment->setStartAtAttribute($datetime);
     $appointment->setFinishAtAttribute($datetime->copy()->addMinutes($service->duration));
     $appointment->duration = $service->duration;
     $appointment->business()->associate($business);
     $appointment->issuer()->associate($issuer);
     $appointment->contact()->associate($contact);
     $appointment->service()->associate($service);
     $appointment->comments = $comments;
     $appointment->doHash();
     return $appointment;
 }
Beispiel #3
0
 /**
  * post Action for booking.
  *
  * @param AlterAppointmentRequest $request
  *
  * @return JSON Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     logger()->info(__METHOD__);
     //////////////////
     // FOR REFACOTR //
     //////////////////
     $issuer = auth()->user();
     $businessId = $request->input('business');
     $appointment = Appointment::findOrFail($request->input('appointment'));
     $action = $request->input('action');
     $widgetType = $request->input('widget');
     ///////////////////////////////////
     // TODO: AUTHORIZATION GOES HERE //
     ///////////////////////////////////
     // AUTHORIZE:
     //  (A) auth()->user() is owner of $business
     // OR
     //  (B) auth()->user() is issuer of $appointment
     logger()->info(sprintf('postAction.request:[issuer:%s, action:%s, business:%s, appointment:%s]', $issuer->email, $action, $businessId, $appointment->id));
     try {
         $appointment = $this->concierge->requestAction(auth()->user(), $appointment, $action);
     } catch (\Exception $e) {
         return response()->json(['code' => 'ERROR', 'html' => '']);
     }
     $contents = ['appointment' => $appointment, 'user' => auth()->user()];
     $viewKey = "widgets.appointment.{$widgetType}._body";
     if (!view()->exists($viewKey)) {
         return response()->json(['code' => 'ERROR', 'html' => '']);
     }
     // Widgets MUST be rendered before being returned on Response as they need to be interpreted as HTML
     $html = view($viewKey, $contents)->render();
     logger()->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $appointmentId = $this->get('appointment');
     $businessId = $this->get('business');
     $issuer = auth()->user();
     $appointment = Appointment::find($appointmentId);
     $authorize = $appointment->issuer->id == $issuer->id || $issuer->isOwner($businessId);
     return $authorize;
 }
 public function getAppointments()
 {
     $appointments = Appointment::all();
     $calendarAppointments = array();
     foreach ($appointments as $a) {
         $customer = Customer::find($a['customer_id']);
         $customer = $customer->first_name . ' ' . $customer->last_name;
         $event = array('title' => 'Appointment with ' . $customer, 'start' => $a['appointment_datetime']);
         array_push($calendarAppointments, $event);
     }
     return response()->json($calendarAppointments);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 2, 'user_id' => 1, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 1, 'user_id' => 2, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 3, 'user_id' => 3, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 1, 'user_id' => 1, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 2, 'user_id' => 2, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 3, 'user_id' => 3, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 4, 'user_id' => 4, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 5, 'user_id' => 5, 'appointment_date' => time()]);
     \App\Models\Appointment::create(['clinic_id' => 1, 'service_id' => 6, 'user_id' => 6, 'appointment_date' => time()]);
 }
 /**
  * post Action for booking
  *
  * @param  AlterAppointmentRequest $request
  * @return JSON                    Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     $this->log->info(__METHOD__);
     //////////////////
     // FOR REFACOTR //
     //////////////////
     $issuer = auth()->user();
     $businessId = $request->input('business');
     $appointmentId = $request->input('appointment');
     $action = $request->input('action');
     $widget = $request->input('widget');
     $this->log->info(sprintf("AJAX postAction.request:[issuer:%s, action:%s, business:%s, appointment:%s]", $issuer->email, $action, $businessId, $appointmentId));
     $appointment = Appointment::find($appointmentId);
     switch ($action) {
         case 'annulate':
             $appointment->doAnnulate();
             break;
         case 'confirm':
             $appointment->doConfirm();
             break;
         case 'serve':
             $appointment->doServe();
             break;
         default:
             // Ignore Invalid Action
             $this->log->warning('Invalid Action request');
             return response()->json(['code' => 'ERROR', 'html' => '']);
             break;
     }
     /**
      * Widgets MUST be rendered before being returned on Response
      * as they need to be interpreted as HTML
      */
     switch ($widget) {
         case 'row':
             $html = Widget::AppointmentsTableRow(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
         case 'panel':
         default:
             $html = Widget::AppointmentPanel(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
     }
     $appointmentPresenter = $appointment->getPresenter();
     $date = $appointment->start_at->toDateString();
     $code = $appointmentPresenter->code();
     Notifynder::category('appointment.' . $action)->from('App\\Models\\User', auth()->user()->id)->to('App\\Models\\Business', $appointment->business->id)->url('http://localhost')->extra(compact('code', 'action', 'date'))->send();
     $this->log->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }
 public function GetAllAppointments()
 {
     $appointments = Appointment::all();
     $calendarAppointments = array();
     foreach ($appointments as $a) {
         $customer = Customer::find($a['customer_id']);
         $customer = $customer->first_name . ' ' . $customer->last_name;
         $package = Package::find($a['appointment_type']);
         $startDate = date_create($a['appointment_datetime']);
         $endDate = date_create($a['appointment_datetime']);
         $time = (string) $package->package_time . ' hours';
         $endDate = date_add($endDate, date_interval_create_from_date_string($time));
         $event = array('id' => $a['id'], 'title' => 'Appointment with ' . $customer, 'start' => $startDate->format('Y-m-d\\TH:i:s'), 'end' => $endDate->format('Y-m-d\\TH:i:s'));
         array_push($calendarAppointments, $event);
     }
     return response()->json($calendarAppointments);
 }
Beispiel #9
0
 /**
  * is holding given Appointment
  *
  * ToDo: Remove from here as needs knowledge from Appointment
  *
  * @param  Appointment $appointment Appointment to check against
  * @return boolean                  Appointment is held by the Vacancy
  */
 public function isHolding(Appointment $appointment)
 {
     return $appointment->isActive() && $this->start_at <= $appointment->start_at && $this->finish_at >= $appointment->finish_at && $this->service_id == $appointment->service_id && $this->business_id == $appointment->business_id;
 }
Beispiel #10
0
 /**
  * Attempt an action over an indicated Appointment.
  *
  * @param User        $user
  * @param Appointment $appointment
  * @param string      $action
  *
  * @throws Exception
  *
  * @return App\Models\Appointment
  */
 public function requestAction(User $user, Appointment $appointment, $action)
 {
     switch ($action) {
         case 'annulate':
             $appointment->doAnnulate();
             break;
         case 'confirm':
             $appointment->doConfirm();
             break;
         case 'serve':
             $appointment->doServe();
             break;
         default:
             // Ignore Invalid Action
             logger()->warning('Invalid Action request');
             throw new \Exception('Invalid Action Request');
             break;
     }
     // REFACTOR: $this->notify(notificationCategory, user, business, extraArgs)
     $date = $appointment->date;
     $code = $appointment->code;
     Notifynder::category('appointment.' . $action)->from('App\\Models\\User', $user->id)->to('App\\Models\\Business', $appointment->business->id)->url('http://localhost')->extra(compact('code', 'action', 'date'))->send();
     return $appointment->fresh();
 }
Beispiel #11
0
 public static function addAppointment($customerID)
 {
     $info = Session::get('appointmentInfo');
     Appointment::create(array('customer_id' => $customerID, 'appointment_type' => $info['package_id'], 'appointment_datetime' => $info['datetime']));
 }
 public function GetAppointmentInfo($id)
 {
     $appointment = Appointment::with('customer')->find($id);
     return response()->json($appointment);
 }
Beispiel #13
0
 private function getAppointments($expression)
 {
     $this->results['appointments'] = Appointment::whereIn('business_id', $this->scope['businessesIds'])->where('hash', 'like', $expression . '%')->get();
 }
 /**
  * Function to retrieve times available for a given date
  *
  * View is returned in JSON format
  *
  **/
 public function getTimes()
 {
     // We get the data from AJAX for the day selected, then we get all available times for that day
     $selectedDay = Input::get('selectedDay');
     $availableTimes = DB::table('booking_datetimes')->get();
     // We will now create an array of all booking datetimes that belong to the selected day
     // WE WILL NOT filter this in the query because we want to maintain compatibility with every database (ideally)
     // PSEUDO CODE
     // Get package duration of the chosen package
     $package = Package::find(Session::get('packageID'));
     $packageTime = $package->package_time;
     // For each available time...
     foreach ($availableTimes as $t => $value) {
         $startTime = new DateTime($value->booking_datetime);
         if ($startTime->format("Y-m-d") == $selectedDay) {
             $endTime = new DateTime($value->booking_datetime);
             date_add($endTime, date_interval_create_from_date_string($packageTime . ' hours'));
             // Try to grab any appointments between the start time and end time
             $result = Appointment::timeBetween($startTime->format("Y-m-d H:i"), $endTime->format("Y-m-d H:i"));
             // If no records are returned, the time is okay, if not, we must remove it from the array
             if ($result->first()) {
                 unset($availableTimes[$t]);
             }
         } else {
             unset($availableTimes[$t]);
         }
     }
     return response()->json($availableTimes);
 }