BankAccount.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Organization\Organization;
  6. use App\Entity\Person\Person;
  7. use App\Repository\Core\BankAccountRepository;
  8. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use JetBrains\PhpStorm\Pure;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * Données bancaire d'une Person ou d'une Organization
  16. */
  17. #[Auditable]
  18. #[ApiResource(
  19. itemOperations: [
  20. 'get' => [
  21. 'security' => 'is_granted("BANK_ACCOUNT_READ", object)'
  22. ],
  23. 'put' => [
  24. 'security' => 'is_granted("BANK_ACCOUNT_EDIT", object)'
  25. ],
  26. 'delete' => [
  27. 'security' => 'is_granted("BANK_ACCOUNT_DELETE", object)'
  28. ]
  29. ]
  30. )]
  31. #[ORM\Entity(repositoryClass: BankAccountRepository::class)]
  32. class BankAccount
  33. {
  34. #[ORM\Id]
  35. #[ORM\Column]
  36. #[ORM\GeneratedValue]
  37. private ?int $id = null;
  38. #[ORM\Column(length: 255, nullable: true)]
  39. private ?string $bankName = null;
  40. #[ORM\Column(length: 11, nullable: true)]
  41. #[Assert\Bic(message: 'invalid_bic')]
  42. private ?string $bic = null;
  43. #[ORM\Column(length: 255, nullable: true)]
  44. private ?string $bicInvalid = null;
  45. #[ORM\Column(length: 34, nullable: true)]
  46. #[Assert\Iban(message: 'invalid_iban')]
  47. private ?string $iban = null;
  48. #[ORM\Column(length: 255, nullable: true)]
  49. private ?string $ibanInvalid = null;
  50. #[ORM\Column(options: ['default'=>false])]
  51. private bool $holderIdDifferent = false;
  52. /**
  53. * 0 => jamais facturé, 1 => facturé 1 fois, 2 => facturé plusieurs fois
  54. */
  55. #[ORM\Column(options: ['default'=>0])]
  56. private ?int $countInvoiced = 0;
  57. #[ORM\Column(length: 255, nullable: true)]
  58. private ?string $holder = null;
  59. #[ORM\Column(options: ['default'=>false])]
  60. #[Assert\NotNull]
  61. private bool $principal = false;
  62. #[ORM\Column(type: 'text', nullable: true)]
  63. private ?string $debitAddress = null;
  64. #[ORM\Column(length: 35, unique: true, nullable: true)]
  65. private ?string $rum = null;
  66. #[ORM\Column(type: 'date', nullable: true)]
  67. private ?\DateTimeInterface $signatureDateSamplingMandate;
  68. #[ORM\ManyToMany(targetEntity: Organization::class, mappedBy: 'bankAccounts', cascade: ['persist'])]
  69. private Collection $organization;
  70. #[ORM\ManyToMany(targetEntity: Person::class, mappedBy: 'bankAccount', cascade: ['persist'])]
  71. private Collection $person;
  72. #[Pure] public function __construct()
  73. {
  74. $this->organization = new ArrayCollection();
  75. $this->person = new ArrayCollection();
  76. }
  77. public function getId(): ?int
  78. {
  79. return $this->id;
  80. }
  81. public function getBankName(): ?string
  82. {
  83. return $this->bankName;
  84. }
  85. public function setBankName(?string $bankName): self
  86. {
  87. $this->bankName = $bankName;
  88. return $this;
  89. }
  90. public function getBic(): ?string
  91. {
  92. return $this->bic;
  93. }
  94. public function setBic(?string $bic): self
  95. {
  96. $this->bic = $bic;
  97. return $this;
  98. }
  99. public function getBicInvalid(): ?string
  100. {
  101. return $this->bicInvalid;
  102. }
  103. public function setBicInvalid(?string $bicInvalid): self
  104. {
  105. $this->bicInvalid = $bicInvalid;
  106. return $this;
  107. }
  108. public function getIban(): ?string
  109. {
  110. return $this->iban;
  111. }
  112. public function setIban(?string $iban): self
  113. {
  114. $this->iban = $iban;
  115. return $this;
  116. }
  117. public function getIbanInvalid(): ?string
  118. {
  119. return $this->ibanInvalid;
  120. }
  121. public function setIbanInvalid(?string $ibanInvalid): self
  122. {
  123. $this->ibanInvalid = $ibanInvalid;
  124. return $this;
  125. }
  126. public function getHolderIdDifferent(): bool
  127. {
  128. return $this->holderIdDifferent;
  129. }
  130. public function setHolderIdDifferent(bool $holderIdDifferent): self
  131. {
  132. $this->holderIdDifferent = $holderIdDifferent;
  133. return $this;
  134. }
  135. public function getCountInvoiced(): int
  136. {
  137. return $this->countInvoiced;
  138. }
  139. public function setCountInvoiced(int $countInvoiced): self
  140. {
  141. $this->countInvoiced = $countInvoiced;
  142. return $this;
  143. }
  144. public function getHolder(): ?string
  145. {
  146. return $this->holder;
  147. }
  148. public function setHolder(?string $holder): self
  149. {
  150. $this->holder = $holder;
  151. return $this;
  152. }
  153. public function getPrincipal(): bool
  154. {
  155. return $this->principal;
  156. }
  157. public function setPrincipal(bool $principal): self
  158. {
  159. $this->principal = $principal;
  160. return $this;
  161. }
  162. public function getDebitAddress(): ?string
  163. {
  164. return $this->debitAddress;
  165. }
  166. public function setDebitAddress(?string $debitAddress): self
  167. {
  168. $this->debitAddress = $debitAddress;
  169. return $this;
  170. }
  171. public function getOrganization(): Collection
  172. {
  173. return $this->organization;
  174. }
  175. public function addOrganization(Organization $organization): self
  176. {
  177. if (!$this->organization->contains($organization)) {
  178. $this->organization[] = $organization;
  179. $organization->addBankAccount($this);
  180. }
  181. return $this;
  182. }
  183. public function removeOrganization(Organization $organization): self
  184. {
  185. if ($this->organization->removeElement($organization)) {
  186. $organization->removeBankAccount($this);
  187. }
  188. return $this;
  189. }
  190. public function getRum(): ?string
  191. {
  192. return $this->rum;
  193. }
  194. public function setRum(?string $rum): self
  195. {
  196. $this->rum = $rum;
  197. return $this;
  198. }
  199. public function getSignatureDateSamplingMandate(): ?\DateTimeInterface
  200. {
  201. return $this->signatureDateSamplingMandate;
  202. }
  203. public function setSignatureDateSamplingMandate(?\DateTimeInterface $signatureDateSamplingMandate): self
  204. {
  205. $this->signatureDateSamplingMandate = $signatureDateSamplingMandate;
  206. return $this;
  207. }
  208. /**
  209. * @return Collection<int, Person>
  210. */
  211. public function getPerson(): Collection
  212. {
  213. return $this->person;
  214. }
  215. public function addPerson(Person $person): self
  216. {
  217. if (!$this->person->contains($person)) {
  218. $this->person[] = $person;
  219. $person->addBankAccount($this);
  220. }
  221. return $this;
  222. }
  223. public function removePerson(Person $person): self
  224. {
  225. if ($this->person->removeElement($person)) {
  226. $person->removeBankAccount($this);
  227. }
  228. return $this;
  229. }
  230. }