|
|
@@ -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) {
|