| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Services;
- use App\Enums\UserStatusEnum;
- use App\Enums\UserTypeEnum;
- use App\Models\PartnerAgreement;
- use App\Models\User;
- use App\Models\Appointment;
- use Illuminate\Support\Facades\Auth;
- class DashboardService
- {
- public function getStats(): array
- {
- return [
- 'total_associados' => User::where('type', UserTypeEnum::ASSOCIADO)->count(),
- 'associados_ativos' => User::where('type', UserTypeEnum::ASSOCIADO)->where('status', UserStatusEnum::ACTIVE)->count(),
- 'parceiros' => PartnerAgreement::count(),
- 'contratos_a_vencer' => PartnerAgreement::whereNotNull('contract_end')
- ->whereBetween('contract_end', [now()->toDateString(), now()->addDays(30)->toDateString()])
- ->count(),
- 'novos_mes' => PartnerAgreement::whereMonth('created_at', now()->month)->whereYear('created_at', now()->year)->count(),
- 'associados_pendentes' => User::where('type', UserTypeEnum::ASSOCIADO)->where('status', UserStatusEnum::PENDING)->count(),
- ];
- }
- public function getPartnerStats(): array
- {
- $partnerAgreementId = PartnerAgreement::where('user_id', Auth::id())->value('id');
- return [
- 'authorization' => Appointment::where('partner_agreement_id', $partnerAgreementId)
- ->where('status', 'pendente')
- ->count(),
- 'scheduling' => Appointment::query()
- ->leftJoin(
- 'partner_agreement_services',
- 'partner_agreement_services.id',
- '=',
- 'appointments.partner_agreement_service_id'
- )
- ->where('appointments.partner_agreement_id', $partnerAgreementId)
- ->where('partner_agreement_services.requires_scheduling', true)
- ->where('appointments.status', 'pendente')
- ->count(),
- //aqui e o count total sem status e sem nada
- 'completed' => Appointment::where('partner_agreement_id', $partnerAgreementId)
- ->count(),
- //status recusado
- 'not_authorized' => Appointment::where('partner_agreement_id', $partnerAgreementId)
- ->where('status', 'recusado')
- ->count(),
- ];
- }
- }
|