CotisationApiResourcesRepository.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repository\Cotisation;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\Query\ResultSetMapping;
  6. class CotisationApiResourcesRepository
  7. {
  8. public function __construct(private EntityManagerInterface $adminassosEntityManager)
  9. {
  10. }
  11. /**
  12. * Récupère l'état de la cotisation pour une structure et une année
  13. * @param int $organizationId
  14. * @param int $year
  15. * @return int|null
  16. */
  17. public function getAffiliationState(int $organizationId, int $year): int|null {
  18. $rsm = new ResultSetMapping();
  19. $rsm->addScalarResult('oa_miscellaneous_state_sta', 'oa_miscellaneous_state_sta');
  20. $sql = sprintf('SELECT oa_miscellaneous_state_sta as oa_miscellaneous_state_sta '
  21. . ' FROM oa_assos_state '
  22. . ' WHERE pid = %s AND year_sta = %s', $organizationId, $year);
  23. $query = $this->adminassosEntityManager->createNativeQuery($sql, $rsm);
  24. $result = $query->getOneOrNullResult();
  25. if (!empty($result)) {
  26. return intval($result['oa_miscellaneous_state_sta']);
  27. }
  28. return null;
  29. }
  30. /**
  31. * Retourne vrai si la structure n'a pas rempli son assurance pour une année
  32. * @param int $organizationId
  33. * @param int $year
  34. * @return bool
  35. */
  36. public function isInsuranceNotDone(int $organizationId, int $year): bool {
  37. $rsm = new ResultSetMapping();
  38. $rsm->addScalarResult('done', 'done');
  39. $sql = sprintf('SELECT done as done '
  40. . ' FROM oa_contribution_fede_insurance '
  41. . ' INNER JOIN oa_assos ON oa_contribution_fede_insurance.pid = oa_assos.pid '
  42. . ' INNER JOIN dgv_assurance ON declare_nb_fed_aso = id_unique_dgv '
  43. . ' WHERE oa_contribution_fede_insurance.pid = %s AND year_cfi = %s ', $organizationId, $year);
  44. $query = $this->adminassosEntityManager->createNativeQuery($sql, $rsm);
  45. $result = $query->getOneOrNullResult();
  46. if (!empty($result)) {
  47. return $result['done'] == 0;
  48. } else {
  49. return false;
  50. }
  51. }
  52. /**
  53. * Retourne vrai si la structure n'est pas un client DGV
  54. * @param int $organizationId
  55. * @return bool
  56. */
  57. public function isNotDGVCustomer(int $organizationId):bool {
  58. $rsm = new ResultSetMapping();
  59. $rsm->addScalarResult('total', 'total');
  60. $sql = sprintf('SELECT COUNT(*) as total '
  61. . ' FROM dgv_assurance '
  62. . ' INNER JOIN oa_assos ON declare_nb_fed_aso = id_unique_dgv '
  63. . ' WHERE pid = %s ', $organizationId);
  64. $query = $this->adminassosEntityManager->createNativeQuery($sql, $rsm);
  65. $result = $query->getOneOrNullResult();
  66. if (!empty($result)) {
  67. return $result['total'] == 0;
  68. } else {
  69. return true;
  70. }
  71. }
  72. }