DolibarrAccount.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\ApiResources\Dolibarr;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\ApiResources\ApiResourcesInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use JetBrains\PhpStorm\Pure;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. /**
  12. * Données de l'organization retournées par l'API Dolibarr
  13. * (aussi nommé 'ThirdParty' ou 'Society' dans dolibarr)
  14. */
  15. #[ApiResource(
  16. collectionOperations:[],
  17. itemOperations: [
  18. 'get' => [
  19. 'security' => '(is_granted("ROLE_ADMIN_CORE") or
  20. is_granted("ROLE_ADMINISTRATIF_MANAGER_CORE") or
  21. is_granted("ROLE_PEDAGOGICS_MANAGER_CORE") or
  22. is_granted("ROLE_FINANCIAL_MANAGER_CORE")
  23. ) and object.getOrganizationId() == user.getOrganization().getId()',
  24. 'method' => 'GET',
  25. 'path' => '/dolibarr/account/{organizationId}',
  26. 'requirements' => ['organizationId' => '\d+'],
  27. 'normalization_context' => [
  28. 'groups' => ['dolibarr_get']
  29. ],
  30. ],
  31. ],
  32. compositeIdentifier: false,
  33. )]
  34. class DolibarrAccount implements ApiResourcesInterface
  35. {
  36. #[ApiProperty(identifier: true)]
  37. #[Groups('dolibarr_get')]
  38. private int $organizationId;
  39. /**
  40. * Dolibarr societies pk
  41. */
  42. #[Groups('dolibarr_get')]
  43. private ?int $socId = null;
  44. /**
  45. * Opentalent client ref
  46. */
  47. #[Groups('dolibarr_get')]
  48. private string $clientNumber = "";
  49. /**
  50. * Opentalent product owned
  51. */
  52. #[Groups('dolibarr_get')]
  53. private string $product = "";
  54. /**
  55. * Contract and services currently active
  56. */
  57. #[Groups('dolibarr_get')]
  58. private ?DolibarrContract $contract = null;
  59. /**
  60. * Last bills
  61. */
  62. #[Groups('dolibarr_get')]
  63. private Collection $bills;
  64. #[Pure]
  65. public function __construct()
  66. {
  67. $this->bills = new ArrayCollection();
  68. }
  69. public function getOrganizationId(): int
  70. {
  71. return $this->organizationId;
  72. }
  73. public function setOrganizationId(int $organizationId): self
  74. {
  75. $this->organizationId = $organizationId;
  76. return $this;
  77. }
  78. public function getSocId(): ?int
  79. {
  80. return $this->socId;
  81. }
  82. public function setSocId(?int $socId): self
  83. {
  84. $this->socId = $socId;
  85. return $this;
  86. }
  87. public function getClientNumber(): string
  88. {
  89. return $this->clientNumber;
  90. }
  91. public function setClientNumber(string $clientNumber): self
  92. {
  93. $this->clientNumber = $clientNumber;
  94. return $this;
  95. }
  96. public function getProduct(): string
  97. {
  98. return $this->product;
  99. }
  100. public function setProduct(string $product): self
  101. {
  102. $this->product = $product;
  103. return $this;
  104. }
  105. public function getContract(): ?object
  106. {
  107. return $this->contract;
  108. }
  109. public function setContract(?object $contract): self
  110. {
  111. $this->contract = $contract;
  112. return $this;
  113. }
  114. public function getBills(): Collection
  115. {
  116. return $this->bills;
  117. }
  118. public function addBill(DolibarrBill $bill): self
  119. {
  120. $this->bills[] = $bill;
  121. return $this;
  122. }
  123. public function removeBill(DolibarrBill $bill): self
  124. {
  125. $this->bills->removeElement($bill);
  126. return $this;
  127. }
  128. }