<?php
namespace App\Entity;
use App\Enum\Transaction\Status;
use App\Enum\Transaction\Type;
use App\Repository\TransactionRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TransactionRepository::class)
*/
class Transaction
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="enum", options={"values"="transaction_enum", "default"="new"})
*/
private $status = Status::STATUS_NEW;
/**
* @ORM\Column(type="enum", options={"values"="transaction_enum"})
*/
private $type;
/**
* @ORM\Column(type="integer")
*/
private $amount = 0;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $bankStatementRow;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date;
/**
* @ORM\ManyToOne(targetEntity=Candidate::class)
* @ORM\JoinColumn(nullable=true)
*/
private $candidate;
/**
* @ORM\OneToOne(targetEntity=Invoice::class, mappedBy="transaction", cascade={"persist", "remove"})
*/
private $invoice;
/**
* @ORM\ManyToOne(targetEntity=FinanceCategory::class)
* @ORM\JoinColumn(nullable=true)
*/
private $financeCategory;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*/
private $person;
/**
* @ORM\OneToOne(targetEntity=Payment::class, mappedBy="transaction", cascade={"persist", "remove"})
*/
private $payment;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status): self
{
$this->status = $status;
return $this;
}
public function getStatusText(): string
{
return Status::getText($this->status);
}
public function getStatusCss($prefix = null): string
{
return Status::getCssClass($this->status, $prefix);
}
public function isNewStatus(): bool
{
return $this->status === Status::STATUS_NEW;
}
public function isDeletedStatus(): bool
{
return $this->status === Status::STATUS_DELETED;
}
public function getType()
{
return $this->type;
}
public function setType($type): self
{
$this->type = $type;
return $this;
}
public function getTypeText(): string
{
return Type::getText($this->type);
}
public function getTypeCss($prefix = null): string
{
return Type::getCssClass($this->type, $prefix);
}
public function isCreditType(): bool
{
return $this->type === Type::TYPE_CREDIT;
}
public function isDebitType(): bool
{
return $this->type === Type::TYPE_DEBIT;
}
public function getAmount(): ?int
{
return $this->amount;
}
public function setAmount(int $amount): self
{
$this->amount = $amount;
return $this;
}
public function getBankStatementRow(): ?array
{
return json_decode($this->bankStatementRow, true);
}
public function setBankStatementRow(?array $bankStatementRow): self
{
$this->bankStatementRow = json_encode($bankStatementRow,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getCandidate(): ?Candidate
{
return $this->candidate;
}
public function setCandidate(?Candidate $candidate): self
{
$this->candidate = $candidate;
return $this;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(?Invoice $invoice): self
{
// unset the owning side of the relation if necessary
if ($invoice === null && $this->invoice !== null) {
$this->invoice->setTransaction(null);
}
// set the owning side of the relation if necessary
if ($invoice !== null && $invoice->getTransaction() !== $this) {
$invoice->setTransaction($this);
}
$this->invoice = $invoice;
return $this;
}
public function getFinanceCategory(): ?FinanceCategory
{
return $this->financeCategory;
}
public function setFinanceCategory(?FinanceCategory $financeCategory): self
{
$this->financeCategory = $financeCategory;
return $this;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function getPurposeEntity()
{
if ($this->getPayment()) {
return $this->getPayment()->getCalendarEvent();
} elseif ($this->getInvoice()) {
return $this->getInvoice()->getCandidate() && $this->getInvoice()->getCandidate()->getCalendarEvent()
? $this->getInvoice()->getCandidate()->getCalendarEvent() : null;
}
return null;
}
public function getPurposeText(): ?string
{
$entity = $this->getPurposeEntity();
if ($entity) {
return $entity->getName();
}
return null;
}
public function getPayment(): ?Payment
{
return $this->payment;
}
public function setPayment(?Payment $payment): self
{
// unset the owning side of the relation if necessary
if ($payment === null && $this->payment !== null) {
$this->payment->setTransaction(null);
}
// set the owning side of the relation if necessary
if ($payment !== null && $payment->getTransaction() !== $this) {
$payment->setTransaction($this);
}
$this->payment = $payment;
return $this;
}
}