|
|
@@ -16,6 +16,8 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ScheduleService
|
|
|
{
|
|
|
+ private const EXCLUDED_STATUSES = ['cancelled', 'rejected'];
|
|
|
+
|
|
|
public function getAll()
|
|
|
{
|
|
|
return Schedule::with(['client.user', 'provider.user', 'address'])
|
|
|
@@ -271,10 +273,10 @@ class ScheduleService
|
|
|
$date_cleaned = Carbon::parse($schedule->date)->format('Y-m-d');
|
|
|
$date_time_dispatch = Carbon::parse($date_cleaned . ' ' . $schedule->start_time);
|
|
|
|
|
|
- StartScheduleJob::dispatch($schedule->id)->delay($date_time_dispatch);
|
|
|
+ // StartScheduleJob::dispatch($schedule->id)->delay($date_time_dispatch);
|
|
|
|
|
|
// dispatch de teste em local
|
|
|
- // StartScheduleJob::dispatch($schedule->id)->delay(now()->addSeconds(15));
|
|
|
+ StartScheduleJob::dispatch($schedule->id)->delay(now()->addSeconds(15));
|
|
|
break;
|
|
|
case 'cancelled':
|
|
|
break;
|
|
|
@@ -319,5 +321,45 @@ class ScheduleService
|
|
|
Log::error("Erro ao cancelar agendamento: " . $e->getMessage());
|
|
|
throw new \Exception("Não foi possível cancelar o agendamento.");
|
|
|
}
|
|
|
+ }
|
|
|
+ public function getClientProviderBlocks(int $clientId, int $providerId): array
|
|
|
+ {
|
|
|
+ $today = Carbon::today()->format('Y-m-d');
|
|
|
+
|
|
|
+ $schedules = Schedule::where('client_id', $clientId)
|
|
|
+ ->where('provider_id', $providerId)
|
|
|
+ ->whereNotIn('status', self::EXCLUDED_STATUSES)
|
|
|
+ ->whereDate('date', '>=', $today)
|
|
|
+ ->orderBy('date')
|
|
|
+ ->orderBy('start_time')
|
|
|
+ ->get(['id', 'date', 'start_time', 'end_time', 'status']);
|
|
|
+
|
|
|
+ $existingSchedules = $schedules->map(function ($schedule) {
|
|
|
+ return [
|
|
|
+ 'id' => $schedule->id,
|
|
|
+ 'date' => Carbon::parse($schedule->date)->format('Y-m-d'),
|
|
|
+ 'start_time' => $schedule->start_time,
|
|
|
+ 'end_time' => $schedule->end_time,
|
|
|
+ 'status' => $schedule->status,
|
|
|
+ ];
|
|
|
+ })->values();
|
|
|
+
|
|
|
+ $fullyBlockedWeeks = $schedules
|
|
|
+ ->groupBy(function ($schedule) {
|
|
|
+ return Carbon::parse($schedule->date)
|
|
|
+ ->startOfWeek(Carbon::SUNDAY)
|
|
|
+ ->format('Y-m-d');
|
|
|
+ })
|
|
|
+ ->filter(function ($weekSchedules) {
|
|
|
+ return $weekSchedules->count() >= 2;
|
|
|
+ })
|
|
|
+ ->keys()
|
|
|
+ ->values();
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'existing_schedules' => $existingSchedules,
|
|
|
+ 'fully_blocked_weeks' => $fullyBlockedWeeks,
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
+
|