| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?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 = Auth::user()->partner_agreement_id;
- $partnerAgreementId = 1;
- 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(),
- ];
- }
- }
|