|
@@ -97,8 +97,10 @@ class ScheduleService
|
|
|
|
|
|
|
|
public function update($id, array $data)
|
|
public function update($id, array $data)
|
|
|
{
|
|
{
|
|
|
- $schedule = Schedule::findOrFail($id);
|
|
|
|
|
|
|
|
|
|
|
|
+ unset($data['status']);
|
|
|
|
|
+
|
|
|
|
|
+ $schedule = Schedule::with(['provider.user', 'client.user', 'address'])->findOrFail($id);
|
|
|
if (isset($data['provider_id']) || isset($data['period_type'])) {
|
|
if (isset($data['provider_id']) || isset($data['period_type'])) {
|
|
|
$providerId = $data['provider_id'] ?? $schedule->provider_id;
|
|
$providerId = $data['provider_id'] ?? $schedule->provider_id;
|
|
|
$periodType = $data['period_type'] ?? $schedule->period_type;
|
|
$periodType = $data['period_type'] ?? $schedule->period_type;
|
|
@@ -273,10 +275,10 @@ class ScheduleService
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
- $schedule = Schedule::findOrFail($id);
|
|
|
|
|
|
|
+ $schedule = Schedule::with(['provider.user','client.user','address'])->findOrFail($id);
|
|
|
|
|
|
|
|
$allowedTransitions = [
|
|
$allowedTransitions = [
|
|
|
- 'pending' => ['accepted', 'rejected'],
|
|
|
|
|
|
|
+ 'pending' => ['accepted', 'rejected', 'cancelled'],
|
|
|
'accepted' => ['paid', 'cancelled'],
|
|
'accepted' => ['paid', 'cancelled'],
|
|
|
'paid' => ['cancelled', 'started'],
|
|
'paid' => ['cancelled', 'started'],
|
|
|
'started' => ['finished'],
|
|
'started' => ['finished'],
|
|
@@ -296,33 +298,67 @@ class ScheduleService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$schedule->update(['status' => $status]);
|
|
$schedule->update(['status' => $status]);
|
|
|
|
|
+ $schedule->refresh();
|
|
|
|
|
+
|
|
|
|
|
|
|
|
switch ($status) {
|
|
switch ($status) {
|
|
|
|
|
|
|
|
case 'pending':
|
|
case 'pending':
|
|
|
-
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 'accepted':
|
|
case 'accepted':
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
- // CLIENTE
|
|
|
|
|
- $notificationService->create([
|
|
|
|
|
- 'title' => 'Agendamento aceito!',
|
|
|
|
|
|
|
+ switch (Auth::user()->type) {
|
|
|
|
|
|
|
|
- 'description' =>
|
|
|
|
|
- $schedule->provider->user->name .
|
|
|
|
|
- ' aceitou sua solicitação de diária.',
|
|
|
|
|
|
|
+ case 'provider':
|
|
|
|
|
|
|
|
- 'origin' => 'schedule',
|
|
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Agendamento aceito!',
|
|
|
|
|
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ $schedule->provider->user->name .
|
|
|
|
|
+ ' aceitou sua solicitação de diária.',
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_ACCEPTED->value,
|
|
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
|
|
|
- 'user_id' => $schedule->client->user_id,
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_ACCEPTED->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->client->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'client':
|
|
|
|
|
+
|
|
|
|
|
+ if ($schedule->provider_id) {
|
|
|
|
|
+
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Proposta aceita!',
|
|
|
|
|
+
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O cliente aceitou sua proposta de diária.',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -330,21 +366,55 @@ class ScheduleService
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
- // CLIENTE
|
|
|
|
|
- $notificationService->create([
|
|
|
|
|
- 'title' => 'Agendamento recusado!',
|
|
|
|
|
|
|
+ switch (Auth::user()->type) {
|
|
|
|
|
|
|
|
- 'description' =>
|
|
|
|
|
- 'O diarista não poderá atender. Veja outros profissionais disponíveis.',
|
|
|
|
|
|
|
|
|
|
- 'origin' => 'schedule',
|
|
|
|
|
|
|
+ case 'provider':
|
|
|
|
|
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Agendamento recusado!',
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
|
|
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O diarista não poderá atender. Veja outros profissionais disponíveis.',
|
|
|
|
|
|
|
|
- 'user_id' => $schedule->client->user_id,
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->client->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'client':
|
|
|
|
|
+
|
|
|
|
|
+ if ($schedule->provider_id) {
|
|
|
|
|
+
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Proposta recusada!',
|
|
|
|
|
+
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O cliente recusou sua proposta de diária.',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -352,23 +422,33 @@ class ScheduleService
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
- // PRESTADOR
|
|
|
|
|
- if ($schedule->provider_id) {
|
|
|
|
|
|
|
+ switch (Auth::user()->type) {
|
|
|
|
|
+
|
|
|
|
|
+ case 'client':
|
|
|
|
|
+
|
|
|
|
|
+ if ($schedule->provider_id) {
|
|
|
|
|
+
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Pagamento confirmado!',
|
|
|
|
|
|
|
|
- $notificationService->create([
|
|
|
|
|
- 'title' => 'Pagamento confirmado!',
|
|
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O cliente confirmou o pagamento da diária.',
|
|
|
|
|
|
|
|
- 'description' =>
|
|
|
|
|
- 'O cliente confirmou o pagamento da diária.',
|
|
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
|
|
|
- 'origin' => 'schedule',
|
|
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
|
|
|
|
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$date_cleaned = Carbon::parse($schedule->date)
|
|
$date_cleaned = Carbon::parse($schedule->date)
|
|
@@ -387,22 +467,24 @@ class ScheduleService
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
switch (Auth::user()->type) {
|
|
switch (Auth::user()->type) {
|
|
|
|
|
+
|
|
|
case 'client':
|
|
case 'client':
|
|
|
|
|
|
|
|
- // PRESTADOR
|
|
|
|
|
if ($schedule->provider_id) {
|
|
if ($schedule->provider_id) {
|
|
|
|
|
|
|
|
- $notificationService->create(['title' => 'Agendamento cancelado!',
|
|
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
|
|
- 'description' =>'O cliente cancelou a diária.',
|
|
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O cliente cancelou a diária.',
|
|
|
|
|
|
|
|
'origin' => 'schedule',
|
|
'origin' => 'schedule',
|
|
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
|
|
|
|
|
'user_id' => $schedule->provider->user_id,
|
|
'user_id' => $schedule->provider->user_id,
|
|
|
]);
|
|
]);
|
|
@@ -412,7 +494,6 @@ class ScheduleService
|
|
|
|
|
|
|
|
case 'provider':
|
|
case 'provider':
|
|
|
|
|
|
|
|
- // CLIENTE
|
|
|
|
|
$notificationService->create([
|
|
$notificationService->create([
|
|
|
'title' => 'Agendamento cancelado!',
|
|
'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
|
@@ -424,7 +505,8 @@ class ScheduleService
|
|
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
|
|
|
|
|
|
'user_id' => $schedule->client->user_id,
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
]);
|
|
@@ -441,7 +523,6 @@ class ScheduleService
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
- // CLIENTE
|
|
|
|
|
$notificationService->create([
|
|
$notificationService->create([
|
|
|
'title' => 'Diarista a caminho!',
|
|
'title' => 'Diarista a caminho!',
|
|
|
|
|
|
|
@@ -454,18 +535,35 @@ class ScheduleService
|
|
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_COMING->value,
|
|
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_COMING->value,
|
|
|
|
|
|
|
|
'user_id' => $schedule->client->user_id,
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Você iniciou o deslocamento!',
|
|
|
|
|
+
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'O cliente foi avisado que você está a caminho.',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 'finished':
|
|
case 'finished':
|
|
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
- // CLIENTE
|
|
|
|
|
$notificationService->create([
|
|
$notificationService->create([
|
|
|
'title' => 'Diária finalizada!',
|
|
'title' => 'Diária finalizada!',
|
|
|
|
|
|
|
@@ -476,14 +574,32 @@ class ScheduleService
|
|
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_FINISHED->value,
|
|
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_FINISHED->value,
|
|
|
|
|
|
|
|
'user_id' => $schedule->client->user_id,
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+ $notificationService->create([
|
|
|
|
|
+ 'title' => 'Diária concluída!',
|
|
|
|
|
+
|
|
|
|
|
+ 'description' =>
|
|
|
|
|
+ 'A diária foi finalizada com sucesso.',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin' => 'schedule',
|
|
|
|
|
+
|
|
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
|
|
+
|
|
|
|
|
+ 'type' =>
|
|
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
|
|
|
|
|
+
|
|
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
|
|
|
|
|
return $schedule->fresh(['client.user', 'provider.user', 'address']);
|
|
return $schedule->fresh(['client.user', 'provider.user', 'address']);
|
|
@@ -508,11 +624,12 @@ class ScheduleService
|
|
|
$cancelled_by = Auth::user()->type;
|
|
$cancelled_by = Auth::user()->type;
|
|
|
|
|
|
|
|
$schedule->update([
|
|
$schedule->update([
|
|
|
- 'status' => 'cancelled',
|
|
|
|
|
'cancel_text' => $cancelText,
|
|
'cancel_text' => $cancelText,
|
|
|
'cancelled_by' => $cancelled_by,
|
|
'cancelled_by' => $cancelled_by,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+ $this->updateStatus($schedule->id, 'cancelled');
|
|
|
|
|
+
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
|
|
|
|
|
return $schedule->fresh(['client.user', 'provider.user', 'address']);
|
|
return $schedule->fresh(['client.user', 'provider.user', 'address']);
|