/** * get Home. * * @param Business $business Business to display * * @return Response Rendered view for desired Business */ public function getHome(Business $business, Concierge $concierge) { logger()->info(__METHOD__); logger()->info(sprintf("businessId:%s businessSlug:'%s'", $business->id, $business->slug)); $businessName = $business->name; Notifynder::category('user.visitedShowroom')->from('App\\Models\\User', auth()->user()->id)->to('Timegridio\\Concierge\\Models\\Business', $business->id)->url('http://localhost')->extra(compact('businessName'))->send(); $available = $concierge->business($business)->isBookable('today', 30); $appointment = $business->bookings()->forContacts(auth()->user()->contacts)->active()->first(); return view('user.businesses.show', compact('business', 'available', 'appointment')); }
public function getCalendar(Business $business) { logger()->info(__METHOD__); logger()->info(sprintf('businessId:%s', $business->id)); $this->authorize('manage', $business); $appointments = $this->concierge->business($business)->getUnservedAppointments(); $jsAppointments = []; foreach ($appointments as $appointment) { $jsAppointments[] = ['title' => $appointment->contact->firstname . ' / ' . $appointment->service->name, 'color' => $appointment->service->color, 'start' => $appointment->start_at->timezone($business->timezone)->toIso8601String(), 'end' => $appointment->finish_at->timezone($business->timezone)->toIso8601String()]; } $slotDuration = count($appointments) > 5 ? '0:15' : '0:30'; unset($appointments); JavaScript::put(['minTime' => $business->pref('start_at'), 'maxTime' => $business->pref('finish_at'), 'events' => $jsAppointments, 'lang' => session()->get('language'), 'slotDuration' => $slotDuration]); return view('manager.businesses.appointments.calendar', compact('business')); }
/** * 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(); $business = Business::findOrFail($request->input('business')); $appointment = Appointment::findOrFail($request->input('appointment')); $action = $request->input('action'); $widgetType = $request->input('widget'); ///////////////////////////////////////////// // AUTHORIZATION : AlterAppointmentRequest // ///////////////////////////////////////////// // (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, $business->id, $appointment->id)); $this->concierge->business($business); $appointmentManager = $this->concierge->booking()->appointment($appointment->hash); switch ($action) { case 'cancel': $appointment = $appointmentManager->cancel(); event(new AppointmentWasCanceled($issuer, $appointment)); break; case 'confirm': $appointment = $appointmentManager->confirm(); event(new AppointmentWasConfirmed($issuer, $appointment)); break; case 'serve': $appointment = $appointmentManager->serve(); break; default: # code... break; } $contents = ['appointment' => $appointment->load('contact'), '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]); }
/** * post Store. * * @param Request $request Input data of booking form * * @return Response Redirect to Appointments listing */ public function postStore(Request $request) { logger()->info(__METHOD__); ////////////////// // FOR REFACTOR // ////////////////// $business = Business::findOrFail($request->input('businessId')); $issuer = auth()->user(); $isOwner = $issuer->isOwner($business->id); if ($request->input('contact_id') && $isOwner) { $contact = $business->contacts()->find($request->input('contact_id')); } else { $contact = $issuer->getContactSubscribedTo($business->id); } // Authorize contact is subscribed to Business // ... $service = $business->services()->find($request->input('service_id')); $date = Carbon::parse($request->input('_date'))->toDateString(); $time = Carbon::parse($request->input('_time'))->toTimeString(); $timezone = $request->input('_timezone') ?: $business->timezone; $comments = $request->input('comments'); $reservation = ['issuer' => $issuer->id, 'contact' => $contact, 'service' => $service, 'date' => $date, 'time' => $time, 'timezone' => $timezone, 'comments' => $comments]; logger()->info('issuer:' . $issuer->id); logger()->info('business:' . $business->id); logger()->info('contact:' . $contact->id); logger()->info('service:' . $service->id); logger()->info('date:' . $date); logger()->info('time:' . $time); logger()->info('timezone:' . $timezone); try { $appointment = $this->concierge->business($business)->takeReservation($reservation); } catch (DuplicatedAppointmentException $e) { $code = $this->concierge->appointment()->code; logger()->info('DUPLICATED Appointment with CODE:' . $code); flash()->warning(trans('user.booking.msg.store.sorry_duplicated', ['code' => $code])); if ($isOwner) { return redirect()->route('manager.business.agenda.index', compact('business')); } return redirect()->route('user.agenda'); } if (false === $appointment) { logger()->info('[ADVICE] Unable to book'); flash()->warning(trans('user.booking.msg.store.error')); return redirect()->back(); } logger()->info('Appointment saved successfully'); event(new NewAppointmentWasBooked($issuer, $appointment)); flash()->success(trans('user.booking.msg.store.success', ['code' => $appointment->code])); if ($isOwner) { return redirect()->route('manager.business.agenda.index', compact('business')); } return redirect()->route('user.agenda', '#' . $appointment->code); }
/** * send Business Report. * * @param Business $business * * @return void */ protected function sendBusinessReport(Business $business) { $this->info(__METHOD__); $this->info("Sending to businessId:{$business->id}"); $appointments = $this->concierge->business($business)->getActiveAppointments(); if ($this->skipReport($business, count($appointments))) { $this->info("Skipped report"); return false; } $owner = $business->owners()->first(); // Mail to User $header = ['email' => $owner->email, 'name' => $owner->name]; $this->transmail->locale($business->locale)->template('appointments.manager._schedule')->subject('manager.business.report.subject', ['date' => date('Y-m-d'), 'business' => $business->name])->send($header, compact('business', 'appointments')); return true; }
/** * Show the published vacancies timetable. * * @return Response */ public function show(Business $business) { logger()->info(__METHOD__); logger()->info(sprintf('businessId:%s', $business->id)); $this->authorize('manageVacancies', $business); // BEGIN ////////////////// // FOR REFACTOR // ////////////////// $daysQuantity = $business->pref('vacancy_edit_days_quantity', config('root.vacancy_edit_days')); $vacancies = $business->vacancies()->with('Appointments')->get(); $timetable = $this->concierge->business($business)->timetable()->buildTimetable($vacancies, 'today', $daysQuantity); if ($business->services->isEmpty()) { flash()->warning(trans('manager.vacancies.msg.edit.no_services')); } return view('manager.businesses.vacancies.show', compact('business', 'timetable')); }
/** * send Business Report. * * @param Business $business * * @return void */ protected function publishVacancies(Business $business) { $this->info(__METHOD__); $this->info("Publishing vacancies for businessId:{$business->id}"); $publishedVacancies = $this->vacancyParser->parseStatements($this->recallStatements($business->id)); if (!$this->autopublishVacancies($business)) { $this->info('Skipped autopublishing vacancies'); return false; } if (!$this->concierge->business($business)->vacancies()->updateBatch($business, $publishedVacancies)) { return false; } // $owner = $business->owners()->first(); // Mail to User // $header = [ // 'email' => $owner->email, // 'name' => $owner->name, // ]; // $this->transmail->locale($business->locale) // ->template('appointments.manager._schedule') // ->subject('manager.business.report.subject', ['date' => date('Y-m-d'), 'business' => $business->name]) // ->send($header, compact('business', 'appointments')); return true; }