|
@@ -329,7 +329,15 @@ class CustomScheduleService
|
|
|
)
|
|
)
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId) {
|
|
|
|
|
|
|
+ $proposedScheduleIds = ScheduleProposal::where('provider_id', $providerId)
|
|
|
|
|
+ ->pluck('schedule_id')
|
|
|
|
|
+ ->flip();
|
|
|
|
|
+
|
|
|
|
|
+ $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId, $proposedScheduleIds) {
|
|
|
|
|
+ if ($proposedScheduleIds->has($opportunity->id)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
return $this->checkProviderAvailability($providerId, $opportunity);
|
|
return $this->checkProviderAvailability($providerId, $opportunity);
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -337,7 +345,7 @@ class CustomScheduleService
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $availableOpportunities->each(function ($opportunity) use ($providerAddress) {
|
|
|
|
|
|
|
+ $availableOpportunities->each(function ($opportunity) use ($providerAddress, $proposedScheduleIds) {
|
|
|
$opportunity->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
$opportunity->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
$providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null,
|
|
$providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null,
|
|
|
$providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null,
|
|
$providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null,
|
|
@@ -352,6 +360,8 @@ class CustomScheduleService
|
|
|
$opportunity->customer_photo = $photoPath
|
|
$opportunity->customer_photo = $photoPath
|
|
|
? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
|
|
? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
|
|
|
: null;
|
|
: null;
|
|
|
|
|
+
|
|
|
|
|
+ $opportunity->proposal_sent = $proposedScheduleIds->has($opportunity->id);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return $availableOpportunities->values();
|
|
return $availableOpportunities->values();
|