Quellcode durchsuchen

fix prestadores para nao aparecer oportunidades se estao sem conta bancaria

Gustavo Zanatta vor 3 Tagen
Ursprung
Commit
3f8c02469a
4 geänderte Dateien mit 20 neuen und 0 gelöschten Zeilen
  1. 17 0
      app/Services/CustomScheduleService.php
  2. 1 0
      lang/en/messages.php
  3. 1 0
      lang/es/messages.php
  4. 1 0
      lang/pt/messages.php

+ 17 - 0
app/Services/CustomScheduleService.php

@@ -271,6 +271,10 @@ class CustomScheduleService
     {
         $provider = Provider::find($providerId);
 
+        if (! $provider || ! self::providerHasActivePrimaryBankAccount($providerId)) {
+            return collect();
+        }
+
         $providerAddress = Address::where('source', 'provider')
             ->where('source_id', $providerId)
             ->orderBy('is_primary', 'desc')
@@ -458,6 +462,10 @@ class CustomScheduleService
     {
         $schedule = Schedule::findOrFail($scheduleId);
 
+        if (! self::providerHasActivePrimaryBankAccount($providerId)) {
+            throw new \Exception(__('messages.provider_missing_bank_account'));
+        }
+
         if ($schedule->provider_id) {
             throw new \Exception(__('validation.custom.opportunity.already_assigned'));
         }
@@ -899,6 +907,14 @@ class CustomScheduleService
     /**
      * @return Collection<int, int>
      */
+    private static function providerHasActivePrimaryBankAccount($providerId): bool
+    {
+        return Provider::query()
+            ->where('providers.id', $providerId)
+            ->whereExists(Provider::hasActivePrimaryBankAccount())
+            ->exists();
+    }
+
     private function getCandidateProviderIdsForOpportunity(Schedule $schedule): Collection
     {
         $address = Address::find($schedule->address_id);
@@ -959,6 +975,7 @@ class CustomScheduleService
         return Provider::query()
             ->join($providerAddressSubquery, 'provider_address.source_id', '=', 'providers.id')
             ->where('providers.approval_status', ApprovalStatusEnum::ACCEPTED->value)
+            ->whereExists(Provider::hasActivePrimaryBankAccount())
 
             ->where(function ($query) use ($cityId, $lat, $lng) {
                 if ($cityId !== null) {

+ 1 - 0
lang/en/messages.php

@@ -54,6 +54,7 @@ return [
     'only_clients_allowed'                         => 'Only clients may access this resource.',
     'only_providers_allowed'                       => 'Only providers may access this resource.',
     'provider_unavailable_for_schedule'            => 'Provider unavailable for this appointment.',
+    'provider_missing_bank_account'                => 'Register your primary bank account to accept services.',
     'invalid_current_status'                       => 'The current status is invalid.',
     'status_transition_not_allowed'                => 'Status transition not allowed.',
     'schedule_status_update_failed'                => 'The appointment status could not be updated.',

+ 1 - 0
lang/es/messages.php

@@ -54,6 +54,7 @@ return [
     'only_clients_allowed'                         => 'Solo los clientes pueden acceder a este recurso.',
     'only_providers_allowed'                       => 'Solo los prestadores pueden acceder a este recurso.',
     'provider_unavailable_for_schedule'            => 'Prestador no disponible para el servicio programado.',
+    'provider_missing_bank_account'                => 'Registra tu cuenta bancaria principal para aceptar servicios.',
     'invalid_current_status'                       => 'El estado actual es inválido.',
     'status_transition_not_allowed'                => 'Transición de estado no permitida.',
     'schedule_status_update_failed'                => 'No fue posible actualizar el estado del servicio programado.',

+ 1 - 0
lang/pt/messages.php

@@ -54,6 +54,7 @@ return [
     'only_clients_allowed'                         => 'Apenas clientes podem acessar este recurso.',
     'only_providers_allowed'                       => 'Apenas prestadores podem acessar este recurso.',
     'provider_unavailable_for_schedule'            => 'Prestador indisponível para agendamento.',
+    'provider_missing_bank_account'                => 'Cadastre sua conta bancária principal para aceitar serviços.',
     'invalid_current_status'                       => 'Status atual inválido.',
     'status_transition_not_allowed'                => 'Transição de status não permitida.',
     'schedule_status_update_failed'                => 'Não foi possível atualizar o status do agendamento.',