From dc6eb18a73141ce43e90e22520c4a0411a6a08e3 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 14 Oct 2024 15:17:54 +0200 Subject: [PATCH] Add wallet statement entity --- src/Entity/WalletStatement.php | 129 +++++++++++++++++++ src/Entity/WalletStatementDirection.php | 16 +++ src/Repository/WalletStatementRepository.php | 75 +++++++++++ 3 files changed, 220 insertions(+) create mode 100644 src/Entity/WalletStatement.php create mode 100644 src/Entity/WalletStatementDirection.php create mode 100644 src/Repository/WalletStatementRepository.php diff --git a/src/Entity/WalletStatement.php b/src/Entity/WalletStatement.php new file mode 100644 index 0000000..24f2e4f --- /dev/null +++ b/src/Entity/WalletStatement.php @@ -0,0 +1,129 @@ + + */ + #[ORM\ManyToMany(targetEntity: WalletStatement::class, mappedBy: 'financesTo')] + private Collection $financedBy; + + /** + * The Statements that drawed money out of this Statement for their Transactions.\ + * Inverse of `financedBy`. + * + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: WalletStatement::class, inversedBy: 'financedBy')] + private Collection $financesTo; + + public function __construct() + { + $this->financedBy = new ArrayCollection(); + $this->financesTo = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getTransaction(): ?AccountingTransaction + { + return $this->transaction; + } + + public function setTransaction(AccountingTransaction $transaction): static + { + $this->transaction = $transaction; + + return $this; + } + + public function getDirection(): ?WalletStatementDirection + { + return $this->direction; + } + + public function setDirection(WalletStatementDirection $direction): static + { + $this->direction = $direction; + + return $this; + } + + /** + * @return Collection + */ + public function getFinancedBy(): Collection + { + return $this->financedBy; + } + + public function addFinancedBy(WalletStatement $financedBy): static + { + if (!$this->financedBy->contains($financedBy)) { + $this->financedBy->add($financedBy); + $financedBy->addFinanceTo($this); + } + + return $this; + } + + public function removeFinancedBy(WalletStatement $financedBy): static + { + if ($this->financedBy->removeElement($financedBy)) { + $financedBy->removeFinanceTo($this); + } + + return $this; + } + + /** + * @return Collection + */ + public function getFinancesTo(): Collection + { + return $this->financesTo; + } + + public function addFinanceTo(WalletStatement $finance): static + { + if (!$this->financesTo->contains($finance)) { + $this->financesTo->add($finance); + } + + return $this; + } + + public function removeFinanceTo(WalletStatement $finance): static + { + $this->financesTo->removeElement($finance); + + return $this; + } +} diff --git a/src/Entity/WalletStatementDirection.php b/src/Entity/WalletStatementDirection.php new file mode 100644 index 0000000..f9dd281 --- /dev/null +++ b/src/Entity/WalletStatementDirection.php @@ -0,0 +1,16 @@ + + */ +class WalletStatementRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, WalletStatement::class); + } + + /** + * @return WalletStatement[] + */ + public function findByOrigin(Accounting $accounting): array + { + return $this->createQueryBuilder('w') + ->join('w.transaction', 'wt', Join::WITH, 'wt.id = w.transaction') + ->andWhere('wt.origin = :val') + ->setParameter('val', $accounting->getId()) + ->orderBy('w.id', 'ASC') + ->getQuery() + ->getResult() + ; + } + + /** + * @return WalletStatement[] + */ + public function findByTarget(Accounting $accounting): array + { + return $this->createQueryBuilder('w') + ->join('w.transaction', 'wt', Join::WITH, 'wt.id = w.transaction') + ->andWhere('wt.target = :val') + ->setParameter('val', $accounting->getId()) + ->orderBy('w.id', 'ASC') + ->getQuery() + ->getResult() + ; + } + + // /** + // * @return WalletStatement[] Returns an array of WalletStatement objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('w') + // ->andWhere('w.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('w.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?WalletStatement + // { + // return $this->createQueryBuilder('w') + // ->andWhere('w.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}