/** * post Store. * * @param Request $request Input data of booking form * * @return Response Redirect to Appointments listing */ public function postStore(Request $request) { $this->log->info(__METHOD__); ////////////////// // FOR REFACTOR // ////////////////// $issuer = auth()->user(); $business = Business::findOrFail($request->input('businessId')); $contact = $issuer->getContactSubscribedTo($business->id); $service = Service::find($request->input('service_id')); $strDateTime = $request->input('_date') . ' ' . $business->pref('start_at'); $datetime = Carbon::parse($strDateTime . ' ' . $business->timezone)->setTimezone('UTC'); $comments = $request->input('comments'); $this->concierge->setBusiness($business); $appointment = $this->concierge->makeReservation($issuer, $business, $contact, $service, $datetime, $comments); if (false === $appointment) { $this->log->info('[ADVICE] Unable to book'); Flash::warning(trans('user.booking.msg.store.error')); return redirect()->route('user.agenda'); } if (!$appointment->exists) { $this->log->info('[ADVICE] Appointment is duplicated'); Flash::warning(trans('user.booking.msg.store.sorry_duplicated', ['code' => $appointment->code])); return redirect()->route('user.agenda'); } $this->log->info('Appointment saved successfully'); event(new NewBooking($issuer, $appointment)); Flash::success(trans('user.booking.msg.store.success', ['code' => $appointment->code])); return redirect()->route('user.agenda'); }
/** * Get available times. * * @param int $businessId * @param int $serviceId * @param string $date * * @return Symfony\Component\HttpFoundation\JsonResponse */ public function getTimes($businessId, $serviceId, $date) { logger()->info(__METHOD__); logger()->info("businessId:{$businessId} serviceId:{$serviceId} date:{$date}"); $business = Business::findOrFail($businessId); $service = Service::findOrFail($serviceId); $vacancies = $business->vacancies()->forDate(Carbon::parse($date))->get(); $times = $this->splitTimes($vacancies, $service); return response()->json(['business' => $businessId, 'service' => ['id' => $service->id, 'duration' => $service->duration], 'date' => $date, 'times' => $times], 200); }
/** * Execute the console command. * * @return mixed */ public function handle() { $businessId = $this->argument('business'); if ($businessId === null) { $this->info('Scanning all businesses...'); $this->scanBusinesses(); } else { $this->info("Sending to specified businessId:{$businessId}"); $business = Business::findOrFail($businessId); $this->sendBusinessReport($business); } }