<?php
namespace App\Entity;
use App\Entity\Club1895\TransactionCheck as Club1895TransactionCheck;
use App\Entity\Traits\Timestampable;
use App\Repository\CheckRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CheckRepository::class)]
#[ORM\Table(name: 'payment_check')]
class Check implements CancellableInterface
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\OneToMany(mappedBy: 'check', targetEntity: TransactionCheck::class)]
private $transactionChecks;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $bank;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $drawer;
#[ORM\Column(type: 'float')]
private $amount;
#[ORM\ManyToOne(targetEntity: Envelope::class, inversedBy: 'checks')]
private $envelope;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private $parent;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private $children;
#[ORM\Column(type: 'string', length: 255)]
private $number;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $date;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $isCancelled = false;
#[ORM\OneToMany(mappedBy: 'check', targetEntity: BenefactorTransactionCheck::class)]
private Collection $benefactorTransactionChecks;
#[ORM\OneToMany(mappedBy: 'check', targetEntity: Club1895TransactionCheck::class)]
private Collection $club1895TransactionChecks;
public function __construct()
{
$this->transactionChecks = new ArrayCollection();
$this->children = new ArrayCollection();
$this->benefactorTransactionChecks = new ArrayCollection();
$this->club1895TransactionChecks = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, TransactionCheck>
*/
public function getTransactionChecks(): Collection
{
return $this->transactionChecks;
}
public function addTransactionCheck(TransactionCheck $transactionCheck): self
{
if (!$this->transactionChecks->contains($transactionCheck)) {
$this->transactionChecks[] = $transactionCheck;
$transactionCheck->setCheck($this);
}
return $this;
}
public function removeTransactionCheck(TransactionCheck $transactionCheck): self
{
if ($this->transactionChecks->removeElement($transactionCheck)) {
// set the owning side to null (unless already changed)
if ($transactionCheck->getCheck() === $this) {
$transactionCheck->setCheck(null);
}
}
return $this;
}
public function getBank(): ?string
{
return $this->bank;
}
public function setBank(?string $bank): self
{
$this->bank = $bank;
return $this;
}
public function getDrawer(): ?string
{
return $this->drawer;
}
public function setDrawer(?string $drawer): self
{
$this->drawer = $drawer;
return $this;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getEnvelope(): ?Envelope
{
return $this->envelope ?? $this->getParent()?->getEnvelope();
}
public function setEnvelope(?Envelope $envelope): self
{
$this->envelope = $envelope;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getNumber(): ?string
{
return $this->number;
}
public function setNumber(string $number): self
{
$this->number = $number;
return $this;
}
public function getDate(): ?\DateTimeImmutable
{
return $this->date;
}
public function setDate(?\DateTimeImmutable $date): self
{
$this->date = $date;
return $this;
}
public function isIsCancelled(): ?bool
{
return $this->isCancelled;
}
public function setIsCancelled(bool $isCancelled): self
{
$this->isCancelled = $isCancelled;
return $this;
}
public function getCancelReason(): ?string
{
$transaction = $this->getTransactionChecks()->first();
if ($transaction) {
return $transaction->getCancelReason();
}
return null;
}
/**
* @return Collection<int, BenefactorTransactionCheck>
*/
public function getBenefactorTransactionChecks(): Collection
{
return $this->benefactorTransactionChecks;
}
public function addBenefactorTransactionCheck(BenefactorTransactionCheck $benefactorTransactionCheck): self
{
if (!$this->benefactorTransactionChecks->contains($benefactorTransactionCheck)) {
$this->benefactorTransactionChecks->add($benefactorTransactionCheck);
$benefactorTransactionCheck->setCheck($this);
}
return $this;
}
public function removeBenefactorTransactionCheck(BenefactorTransactionCheck $benefactorTransactionCheck): self
{
if ($this->benefactorTransactionChecks->removeElement($benefactorTransactionCheck)) {
// set the owning side to null (unless already changed)
if ($benefactorTransactionCheck->getCheck() === $this) {
$benefactorTransactionCheck->setCheck(null);
}
}
return $this;
}
/**
* @return Collection<int, TransactionCheck>
*/
public function getClub1895TransactionChecks(): Collection
{
return $this->club1895TransactionChecks;
}
public function addClub1895TransactionCheck(TransactionCheck $club1895TransactionCheck): self
{
if (!$this->club1895TransactionChecks->contains($club1895TransactionCheck)) {
$this->club1895TransactionChecks->add($club1895TransactionCheck);
$club1895TransactionCheck->setCheck($this);
}
return $this;
}
public function removeClub1895TransactionCheck(TransactionCheck $club1895TransactionCheck): self
{
if ($this->club1895TransactionChecks->removeElement($club1895TransactionCheck)) {
// set the owning side to null (unless already changed)
if ($club1895TransactionCheck->getCheck() === $this) {
$club1895TransactionCheck->setCheck(null);
}
}
return $this;
}
}