DashboardService.php 969 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App\Services;
  3. use App\Enums\UserStatusEnum;
  4. use App\Enums\UserTypeEnum;
  5. use App\Models\PartnerAgreement;
  6. use App\Models\User;
  7. class DashboardService
  8. {
  9. public function getStats(): array
  10. {
  11. return [
  12. 'total_associados' => User::where('type', UserTypeEnum::ASSOCIADO)->count(),
  13. 'associados_ativos' => User::where('type', UserTypeEnum::ASSOCIADO)->where('status', UserStatusEnum::ACTIVE)->count(),
  14. 'parceiros' => PartnerAgreement::count(),
  15. 'contratos_a_vencer' => PartnerAgreement::whereNotNull('contract_end')
  16. ->whereBetween('contract_end', [now()->toDateString(), now()->addDays(30)->toDateString()])
  17. ->count(),
  18. 'novos_mes' => PartnerAgreement::whereMonth('created_at', now()->month)->whereYear('created_at', now()->year)->count(),
  19. 'associados_pendentes' => User::where('type', UserTypeEnum::ASSOCIADO)->where('status', UserStatusEnum::PENDING)->count(),
  20. ];
  21. }
  22. }