|
@@ -341,78 +341,7 @@ class DashboardService
|
|
|
->values();
|
|
->values();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $pendingSchedules = Schedule::with([
|
|
|
|
|
- 'address:district,address,number,source_id,source,id,address_type',
|
|
|
|
|
- ])
|
|
|
|
|
- ->where('schedules.client_id', $cliente->id)
|
|
|
|
|
- ->whereIn('schedules.status', ['pending', 'accepted'])
|
|
|
|
|
- ->where('schedules.schedule_type', 'default')
|
|
|
|
|
- ->whereDate('schedules.date', '>=', now()->toDateString())
|
|
|
|
|
- ->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
|
|
|
|
|
- ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
|
|
- ->select(
|
|
|
|
|
- 'schedules.id',
|
|
|
|
|
- 'schedules.provider_id',
|
|
|
|
|
- 'provider_user.name as provider_name',
|
|
|
|
|
- 'providers.gender',
|
|
|
|
|
- 'schedules.date',
|
|
|
|
|
- 'schedules.address_id',
|
|
|
|
|
- 'schedules.status',
|
|
|
|
|
- 'schedules.total_amount',
|
|
|
|
|
- 'schedules.start_time',
|
|
|
|
|
- 'schedules.end_time',
|
|
|
|
|
-
|
|
|
|
|
- DB::raw("
|
|
|
|
|
- CASE
|
|
|
|
|
- WHEN (NOW() - schedules.created_at) < INTERVAL '1 hour' THEN
|
|
|
|
|
- CONCAT(
|
|
|
|
|
- ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 60),
|
|
|
|
|
- 'min'
|
|
|
|
|
- )
|
|
|
|
|
- WHEN (NOW() - schedules.created_at) < INTERVAL '1 day' THEN
|
|
|
|
|
- CONCAT(
|
|
|
|
|
- ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 3600),
|
|
|
|
|
- 'h'
|
|
|
|
|
- )
|
|
|
|
|
- ELSE
|
|
|
|
|
- CONCAT(
|
|
|
|
|
- ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 86400),
|
|
|
|
|
- 'd'
|
|
|
|
|
- )
|
|
|
|
|
- END AS time_since_request
|
|
|
|
|
- "),
|
|
|
|
|
-
|
|
|
|
|
- DB::raw("
|
|
|
|
|
- (
|
|
|
|
|
- SELECT spi.service_package_id
|
|
|
|
|
- FROM service_package_items spi
|
|
|
|
|
- WHERE spi.schedule_id = schedules.id
|
|
|
|
|
- LIMIT 1
|
|
|
|
|
- ) AS service_package_id
|
|
|
|
|
- "),
|
|
|
|
|
-
|
|
|
|
|
- DB::raw("
|
|
|
|
|
- (
|
|
|
|
|
- SELECT COUNT(*)
|
|
|
|
|
- FROM service_package_items spi_count
|
|
|
|
|
- JOIN schedules s_count ON s_count.id = spi_count.schedule_id
|
|
|
|
|
- AND s_count.status NOT IN ('cancelled', 'rejected')
|
|
|
|
|
- AND s_count.schedule_type = 'default'
|
|
|
|
|
- WHERE spi_count.service_package_id = (
|
|
|
|
|
- SELECT spi.service_package_id
|
|
|
|
|
- FROM service_package_items spi
|
|
|
|
|
- WHERE spi.schedule_id = schedules.id
|
|
|
|
|
- LIMIT 1
|
|
|
|
|
- )
|
|
|
|
|
- ) AS service_package_items_count
|
|
|
|
|
- "),
|
|
|
|
|
- )
|
|
|
|
|
- ->orderBy('schedules.date', 'asc')
|
|
|
|
|
- ->get();
|
|
|
|
|
-
|
|
|
|
|
- $pendingSchedules->each(function ($item) {
|
|
|
|
|
- $item->gender_label = GenderEnum::labelFor($item->gender);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ $pendingSchedules = $this->clientPendingSchedules($cliente);
|
|
|
|
|
|
|
|
$proposalsDistanceSelect = DistanceService::sqlExpression(
|
|
$proposalsDistanceSelect = DistanceService::sqlExpression(
|
|
|
$providersCloseLatitude,
|
|
$providersCloseLatitude,
|
|
@@ -645,16 +574,7 @@ class DashboardService
|
|
|
|
|
|
|
|
$hasPaymentMethods = ClientPaymentMethod::where('client_id', $cliente->id)->exists();
|
|
$hasPaymentMethods = ClientPaymentMethod::where('client_id', $cliente->id)->exists();
|
|
|
|
|
|
|
|
- $pendingServicePackages = ServicePackage::query()
|
|
|
|
|
- ->where('client_id', $cliente->id)
|
|
|
|
|
- ->where('status', ServicePackageStatusEnum::OPEN->value)
|
|
|
|
|
- ->whereHas('items.schedule', fn($q) => $q->where('status', 'accepted'))
|
|
|
|
|
- ->whereDoesntHave('items.schedule', fn($q) => $q->where('status', 'pending'))
|
|
|
|
|
- ->with(['items.schedule' => function ($query) {
|
|
|
|
|
- $query->with(['provider.user', 'address']);
|
|
|
|
|
- }])
|
|
|
|
|
- ->with('provider.user')
|
|
|
|
|
- ->get();
|
|
|
|
|
|
|
+ $pendingServicePackages = $this->clientPendingServicePackages($cliente);
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
'headerBar' => $headerBar,
|
|
'headerBar' => $headerBar,
|
|
@@ -813,15 +733,24 @@ class DashboardService
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $providerPhotoUrls = $this->providerPhotoUrls($schedulesProposals->pluck('provider_id'));
|
|
|
|
|
|
|
+ $pendingSchedules = $this->clientPendingSchedules($cliente);
|
|
|
|
|
|
|
|
- $schedulesProposals->each(function ($item) use ($providerPhotoUrls) {
|
|
|
|
|
- $item->provider_photo = $providerPhotoUrls->get($item->provider_id);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ $providerPhotoUrls = $this->providerPhotoUrls(
|
|
|
|
|
+ $schedulesProposals->pluck('provider_id')
|
|
|
|
|
+ ->merge($pendingSchedules->pluck('provider_id')),
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ collect([$schedulesProposals, $pendingSchedules])->each(
|
|
|
|
|
+ fn (Collection $items) => $items->each(function ($item) use ($providerPhotoUrls) {
|
|
|
|
|
+ $item->provider_photo = $providerPhotoUrls->get($item->provider_id);
|
|
|
|
|
+ }),
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
'schedulesProposals' => $schedulesProposals,
|
|
'schedulesProposals' => $schedulesProposals,
|
|
|
'customSchedulesNoProposals' => $customSchedulesNoProposals,
|
|
'customSchedulesNoProposals' => $customSchedulesNoProposals,
|
|
|
|
|
+ 'pendingSchedules' => $pendingSchedules,
|
|
|
|
|
+ 'pendingServicePackages' => $this->clientPendingServicePackages($cliente),
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1212,6 +1141,108 @@ class DashboardService
|
|
|
|
|
|
|
|
// gera urls apenas para fotos verificadas ou visiveis ao proprio prestador.
|
|
// gera urls apenas para fotos verificadas ou visiveis ao proprio prestador.
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Agendamentos padrão do cliente ainda pendentes ou já aceitos aguardando pagamento.
|
|
|
|
|
+ * Compartilhado entre a dashboard e a tela de pedidos.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function clientPendingSchedules(Client $cliente): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ $pendingSchedules = Schedule::with([
|
|
|
|
|
+ 'address:district,address,number,source_id,source,id,address_type',
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->where('schedules.client_id', $cliente->id)
|
|
|
|
|
+ ->whereIn('schedules.status', ['pending', 'accepted'])
|
|
|
|
|
+ ->where('schedules.schedule_type', 'default')
|
|
|
|
|
+ ->whereDate('schedules.date', '>=', now()->toDateString())
|
|
|
|
|
+ ->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
|
|
|
|
|
+ ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
|
|
+ ->select(
|
|
|
|
|
+ 'schedules.id',
|
|
|
|
|
+ 'schedules.provider_id',
|
|
|
|
|
+ 'provider_user.name as provider_name',
|
|
|
|
|
+ 'providers.gender',
|
|
|
|
|
+ 'schedules.date',
|
|
|
|
|
+ 'schedules.address_id',
|
|
|
|
|
+ 'schedules.status',
|
|
|
|
|
+ 'schedules.total_amount',
|
|
|
|
|
+ 'schedules.start_time',
|
|
|
|
|
+ 'schedules.end_time',
|
|
|
|
|
+
|
|
|
|
|
+ DB::raw("
|
|
|
|
|
+ CASE
|
|
|
|
|
+ WHEN (NOW() - schedules.created_at) < INTERVAL '1 hour' THEN
|
|
|
|
|
+ CONCAT(
|
|
|
|
|
+ ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 60),
|
|
|
|
|
+ 'min'
|
|
|
|
|
+ )
|
|
|
|
|
+ WHEN (NOW() - schedules.created_at) < INTERVAL '1 day' THEN
|
|
|
|
|
+ CONCAT(
|
|
|
|
|
+ ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 3600),
|
|
|
|
|
+ 'h'
|
|
|
|
|
+ )
|
|
|
|
|
+ ELSE
|
|
|
|
|
+ CONCAT(
|
|
|
|
|
+ ROUND(EXTRACT(EPOCH FROM (NOW() - schedules.created_at)) / 86400),
|
|
|
|
|
+ 'd'
|
|
|
|
|
+ )
|
|
|
|
|
+ END AS time_since_request
|
|
|
|
|
+ "),
|
|
|
|
|
+
|
|
|
|
|
+ DB::raw("
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT spi.service_package_id
|
|
|
|
|
+ FROM service_package_items spi
|
|
|
|
|
+ WHERE spi.schedule_id = schedules.id
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ ) AS service_package_id
|
|
|
|
|
+ "),
|
|
|
|
|
+
|
|
|
|
|
+ DB::raw("
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT COUNT(*)
|
|
|
|
|
+ FROM service_package_items spi_count
|
|
|
|
|
+ JOIN schedules s_count ON s_count.id = spi_count.schedule_id
|
|
|
|
|
+ AND s_count.status NOT IN ('cancelled', 'rejected')
|
|
|
|
|
+ AND s_count.schedule_type = 'default'
|
|
|
|
|
+ WHERE spi_count.service_package_id = (
|
|
|
|
|
+ SELECT spi.service_package_id
|
|
|
|
|
+ FROM service_package_items spi
|
|
|
|
|
+ WHERE spi.schedule_id = schedules.id
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ )
|
|
|
|
|
+ ) AS service_package_items_count
|
|
|
|
|
+ "),
|
|
|
|
|
+ )
|
|
|
|
|
+ ->orderBy('schedules.date', 'asc')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ $pendingSchedules->each(function ($item) {
|
|
|
|
|
+ $item->gender_label = GenderEnum::labelFor($item->gender);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return $pendingSchedules;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Pacotes abertos cujos agendamentos já foram todos aceitos — é o que
|
|
|
|
|
+ * dispara o bloco "realize o pagamento para" no app do cliente.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function clientPendingServicePackages(Client $cliente): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ $pendingServicePackages = ServicePackage::query()
|
|
|
|
|
+ ->where('client_id', $cliente->id)
|
|
|
|
|
+ ->where('status', ServicePackageStatusEnum::OPEN->value)
|
|
|
|
|
+ ->whereHas('items.schedule', fn($q) => $q->where('status', 'accepted'))
|
|
|
|
|
+ ->whereDoesntHave('items.schedule', fn($q) => $q->where('status', 'pending'))
|
|
|
|
|
+ ->with(['items.schedule' => function ($query) {
|
|
|
|
|
+ $query->with(['provider.user', 'address']);
|
|
|
|
|
+ }])
|
|
|
|
|
+ ->with('provider.user')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ return $pendingServicePackages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private function providerPhotoUrls(iterable $providerIds): Collection
|
|
private function providerPhotoUrls(iterable $providerIds): Collection
|
|
|
{
|
|
{
|
|
|
return Provider::query()
|
|
return Provider::query()
|