/** * Display a listing of the resource. * * @return Response */ public function index() { $availabilities = Availability::where('is_booked', false)->get(); if (!$availabilities) { $availabilities = ''; } return View::make('availabilities.index', compact(['availabilities'])); }
public function index() { $availabilitiesByDay = Availability::select(DB::raw('COUNT(availabilities.id) as count'), 'days.date as date')->leftJoin('availability_day', 'availabilities.id', '=', 'availability_day.availability_id')->leftJoin('days', 'availability_day.day_id', '=', 'days.id')->leftJoin('availability_advisor', 'availabilities.id', '=', 'availability_advisor.availability_id')->leftJoin('advisors', 'availability_advisor.advisor_id', '=', 'advisors.id')->whereBetween('days.date', [Carbon::now()->subDays(4)->toDateString(), Carbon::now()->addDays(4)->toDateString()])->groupBy('days.id')->orderBy('days.id', 'asc')->get(); $availabilitiesByAdvisor = Availability::select(DB::raw('COUNT(availabilities.id) as count'), DB::raw('CONCAT(advisors.first_name, " ", advisors.last_name) as advisor_name'), 'advisors.email as advisor_email')->leftJoin('availability_day', 'availabilities.id', '=', 'availability_day.availability_id')->leftJoin('days', 'availability_day.day_id', '=', 'days.id')->leftJoin('availability_advisor', 'availabilities.id', '=', 'availability_advisor.availability_id')->leftJoin('advisors', 'availability_advisor.advisor_id', '=', 'advisors.id')->whereBetween('days.date', [Carbon::now()->subDays(4)->toDateString(), Carbon::now()->addDays(5)->toDateString()])->groupBy('advisors.id')->orderBy('count', 'asc')->get(); $availabilitiesByLocation = Availability::select(DB::raw('COUNT(availabilities.id) as count'), 'locations.name as location_name')->leftJoin('availability_day', 'availabilities.id', '=', 'availability_day.availability_id')->leftJoin('days', 'availability_day.day_id', '=', 'days.id')->leftJoin('availability_location', 'availabilities.id', '=', 'availability_location.availability_id')->leftJoin('locations', 'availability_location.location_id', '=', 'locations.id')->whereBetween('days.date', [Carbon::now()->subDays(4)->toDateString(), Carbon::now()->addDays(5)->toDateString()])->groupBy('locations.id')->orderBy('count', 'asc')->get(); //var_dump($availabilitiesByDay); //dd($availabilitiesByAdvisor); //exit; return View::make('admin.index', compact(['availabilitiesByDay', 'availabilitiesByAdvisor', 'availabilitiesByLocation'])); }
public function seeBookedAvailabilities() { $availabilityIds = []; foreach (Availability::all() as $availability) { if ($availability->hasRequests()) { $availabilityIds[] = $availability->id; } } if (!$availabilityIds) { $availabilities = null; return View::make('admin.active-availabilities', compact(['availabilities'])); } $availabilities = DB::table('availabilities')->select('advisors.first_name as advisor_first_name', 'advisors.last_name as advisor_last_name', 'advisors.email as advisor_email', 'advisors.profile_img as advisor_profile_img', 'requestees.name as requestee_name', 'requestees.email as requestee_email', 'requestees.phone as requestee_phone', 'requestees.notes as requestee_notes', 'availability_day.time as time', 'days.date as date', 'locations.name as location', 'meetings.status as status')->leftJoin('availability_day', 'availabilities.id', '=', 'availability_day.availability_id')->leftJoin('availability_advisor', 'availabilities.id', '=', 'availability_advisor.availability_id')->leftJoin('availability_location', 'availabilities.id', '=', 'availability_location.availability_id')->leftJoin('meeting_availability', 'availabilities.id', '=', 'meeting_availability.availability_id')->leftJoin('meetings', 'meeting_availability.meeting_id', '=', 'meetings.id')->leftJoin('meeting_requestee', 'meetings.id', '=', 'meeting_requestee.meeting_id')->leftJoin('days', 'availability_day.day_id', '=', 'days.id')->leftJoin('advisors', 'availability_advisor.advisor_id', '=', 'advisors.id')->leftJoin('locations', 'availability_location.location_id', '=', 'locations.id')->leftJoin('requestees', 'meeting_requestee.requestee_id', '=', 'requestees.id')->whereIn('availabilities.id', $availabilityIds)->where('availabilities.expired', 0)->orderBy('days.date')->get(); return View::make('admin.active-availabilities', compact(['availabilities'])); }
/** * Execute the console command. * * @return mixed */ public function fire() { $availabilities = []; foreach (Availability::where('reminder_sent', false)->where('is_booked', true)->get() as $availability) { if ($availability->reminder_sent == true) { continue; } $date = $availability->days()->first()->date; $time = $availability->days()->first()->pivot->time; $dt = Carbon::parse($date . ' ' . $availability->timeToTimeStamp($time)); if (Carbon::now()->diffInHours($dt, false) < 48) { $availabilities[] = $availability; } } foreach ($availabilities as $avail) { $this->info($avail->reminder_sent); $meeting = $avail->meetings()->first(); $advisorEmail = $avail->advisors()->first()->email; $adviseeEmail = $avail->meetings()->first()->requestees()->first()->email; $advisor = $meeting->advisors()->first(); $requestee = $meeting->requestees()->first(); $avail = $meeting->availabilities()->first(); $advisorName = $advisor->first_name . ' ' . $advisor->last_name; $advisorEmail = $advisor->email; $data = ['requestee_name' => $requestee->name, 'requestee_email' => $requestee->email, 'requestee_notes' => $requestee->notes, 'requestee_phone' => $requestee->phone, 'advisorName' => $advisor->first_name . ' ' . $advisor->last_name, 'locationWebsite' => $avail->locations()->first()->website, 'locationName' => $avail->locations()->first()->name, 'availabilityTime' => $avail->days()->first()->prettyPrint() . ' at ' . $availability->days()->first()->pivot->time]; \Mail::queue('emails.reminder.advisor', $data, function ($message) use($advisorEmail, $advisorName) { $message->to($advisorEmail, $advisorName)->subject('Reminder: Your Office Hours meeting is tomorrow.'); }); $this->info($advisorEmail . ' emailed.'); \Mail::queue('emails.reminder.requestee', $data, function ($message) use($requestee) { $message->to($requestee->email, $requestee->name)->subject('Reminder: Your Office Hours meeting is tomorrow.'); }); $this->info($requestee->email . ' emailed.'); $avail->reminder_sent = true; $avail->save(); } $this->info('end.'); }
public function showBookedRequest() { $availability = Availability::find(\Input::get('availability_id')); $meeting = $availability->meetings()->where('status', '1')->first(); return View::make('user.availabilities.booked-request', compact(['meeting'])); }
public function scrubExpiredAvailabilities() { $expiredAvailabilities = []; foreach (Availability::all() as $availability) { if ($availability->days()->first() == null) { continue; } //$time = $availability->days()->first()->pivot->date; $time = $availability->days()->first()->pivot->time; $date = $availability->days()->first()['date']; $dt = Carbon::parse($date . ' ' . $availability->timeToTimeStamp($time)); if (Carbon::now()->diffInMinutes($dt, false) < 0) { $expiredAvailabilities[] = $availability; } } foreach ($expiredAvailabilities as $expAvail) { $expAvail->expired = 1; $expAvail->save(); } }
public static function sendRequestInitializationEmail($day_id, $service_id, $advisor_id, $location_id, $availability_id, $requestee_name, $requestee_email, $requestee_notes, $requestee_phone) { $advisor = Advisor::find($advisor_id); $availability = Availability::find($availability_id); $advisorName = $advisor->first_name . ' ' . $advisor->last_name; $advisorEmail = $advisor->email; $data = ['day_id' => $day_id, 'service_id' => $service_id, 'advisor_id' => $advisor_id, 'location_id' => $location_id, 'availabilitiy_id' => $availability_id, 'requestee_name' => $requestee_name, 'requestee_email' => $requestee_email, 'requestee_notes' => $requestee_notes, 'requestee_phone' => $requestee_phone, 'advisor' => $advisor, 'advisorName' => $advisor->first_name . ' ' . $advisor->last_name, 'locationWebsite' => $availability->locations()->first()->website, 'locationName' => $availability->locations()->first()->name, 'availability' => $availability, 'availabilityTime' => $availability->days()->first()->prettyPrint() . ' at ' . $availability->days()->first()->pivot->time]; \Mail::queue('emails.requests.requestee', $data, function ($message) use($day_id, $service_id, $advisor_id, $location_id, $availability_id, $requestee_name, $requestee_email, $requestee_notes, $requestee_phone) { $message->to($requestee_email, $requestee_name)->subject('Your request has been submitted!'); }); \Mail::queue('emails.requests.advisor', $data, function ($message) use($day_id, $service_id, $advisor_id, $location_id, $availability_id, $requestee_name, $requestee_email, $requestee_notes, $requestee_phone, $advisorName, $advisorEmail) { $message->to($advisorEmail, $advisorName)->subject('You have been requested for an availability!'); }); }
/** * Execute the console command. * * @return mixed */ public function fire() { $recurringAvailabilities = RecurringAvailability::all(); $today = Day::where('date', Carbon::today())->first(); $daysInNextTwoWeeks = Day::whereBetween('id', [$today->id, (int) $today->id + 14])->lists('date'); $advisors = Advisor::all(); foreach ($advisors as $advisor) { if ($advisor->recurringAvailabilities()->count() == 0) { continue; } $availabilitiesInNextTwoWeeks = []; foreach ($advisor->availabilities()->get() as $avail) { if (in_array($avail->days()->first()->date, $daysInNextTwoWeeks)) { if (count(explode(':', $avail->days()->first()->pivot->time)) == 1) { if (explode(' ', $avail->days()->first()->pivot->time)[1] == 'AM') { if (explode(' ', $avail->days()->first()->pivot->time)[0] == '12') { $time = 0; } else { $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0]; } } else { if (explode(' ', $avail->days()->first()->pivot->time)[0] == '12') { $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0]; } else { $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0] + 12; } } } else { if (explode(' ', explode(':', $avail->days()->first()->pivot->time)[1])[1] == 'AM') { if (explode(':', $avail->days()->first()->pivot->time)[0] == '12') { $time = 0; } else { $time = (int) explode(':', $avail->days()->first()->pivot->time)[0]; } } else { if (explode(':', $avail->days()->first()->pivot->time)[0] == '12') { $time = (int) explode(':', $avail->days()->first()->pivot->time)[0]; } else { $time = (int) explode(':', $avail->days()->first()->pivot->time)[0] + 12; } } } $availabilitiesInNextTwoWeeks[] = ['date' => $avail->days()->first()->date, 'time' => $time]; } } $recurringAvailabilitiesInNextTwoWeeks = []; foreach ($advisor->recurringAvailabilities()->get() as $recurAvail) { $difference = $recurAvail->day_of_week - Carbon::parse($today->date)->dayOfWeek; $this->info($difference); $dayOfWeekOfRecurAvail = Day::find($today->id + $difference); $nextWeeksDay = Day::find($today->id + $difference + 7); $timeOfRecurAvail = $recurAvail->time; if ($this->in_array_r([$dayOfWeekOfRecurAvail->date, $recurAvail->time], $availabilitiesInNextTwoWeeks)) { echo 'intersection of RecurAvail ID ' . $recurAvail->id . ' at date ' . $dayOfWeekOfRecurAvail->date . "\n"; } else { // Create it for this Week if ($difference > 0) { Availability::createRecurringAvailability($timeOfRecurAvail, $dayOfWeekOfRecurAvail->id, $advisor->id, Service::where('name', '25 Minute Free Consultation')->first()->id, $recurAvail->location_id); } if (!$this->in_array_r([$nextWeeksDay->date, $recurAvail->time], $availabilitiesInNextTwoWeeks)) { // Create it for next week Availability::createRecurringAvailability($timeOfRecurAvail, (int) $dayOfWeekOfRecurAvail->id + 7, $advisor->id, Service::where('name', '25 Minute Free Consultation')->first()->id, $recurAvail->location_id); } } } } }
public function getAllAvailabilities() { $availabilities = Availability::all(); return \Response::json($availabilities); }