src/Entity/Transaction.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\Transaction\Status;
  4. use App\Enum\Transaction\Type;
  5. use App\Repository\TransactionRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=TransactionRepository::class)
  9.  */
  10. class Transaction
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="datetime")
  20.      */
  21.     private $createdAt;
  22.     /**
  23.      * @ORM\Column(type="enum", options={"values"="transaction_enum", "default"="new"})
  24.      */
  25.     private $status Status::STATUS_NEW;
  26.     /**
  27.      * @ORM\Column(type="enum", options={"values"="transaction_enum"})
  28.      */
  29.     private $type;
  30.     /**
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private $amount 0;
  34.     /**
  35.      * @ORM\Column(type="text", nullable=true)
  36.      */
  37.     private $bankStatementRow;
  38.     /**
  39.      * @ORM\Column(type="datetime", nullable=true)
  40.      */
  41.     private $date;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=Candidate::class)
  44.      * @ORM\JoinColumn(nullable=true)
  45.      */
  46.     private $candidate;
  47.     /**
  48.      * @ORM\OneToOne(targetEntity=Invoice::class, mappedBy="transaction", cascade={"persist", "remove"})
  49.      */
  50.     private $invoice;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=FinanceCategory::class)
  53.      * @ORM\JoinColumn(nullable=true)
  54.      */
  55.     private $financeCategory;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity=Person::class)
  58.      */
  59.     private $person;
  60.     /**
  61.      * @ORM\OneToOne(targetEntity=Payment::class, mappedBy="transaction", cascade={"persist", "remove"})
  62.      */
  63.     private $payment;
  64.     public function __construct()
  65.     {
  66.         $this->createdAt = new \DateTime();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getCreatedAt(): ?\DateTimeInterface
  73.     {
  74.         return $this->createdAt;
  75.     }
  76.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  77.     {
  78.         $this->createdAt $createdAt;
  79.         return $this;
  80.     }
  81.     public function getStatus()
  82.     {
  83.         return $this->status;
  84.     }
  85.     public function setStatus($status): self
  86.     {
  87.         $this->status $status;
  88.         return $this;
  89.     }
  90.     public function getStatusText(): string
  91.     {
  92.         return Status::getText($this->status);
  93.     }
  94.     public function getStatusCss($prefix null): string
  95.     {
  96.         return Status::getCssClass($this->status$prefix);
  97.     }
  98.     public function isNewStatus(): bool
  99.     {
  100.         return $this->status === Status::STATUS_NEW;
  101.     }
  102.     public function isDeletedStatus(): bool
  103.     {
  104.         return $this->status === Status::STATUS_DELETED;
  105.     }
  106.     public function getType()
  107.     {
  108.         return $this->type;
  109.     }
  110.     public function setType($type): self
  111.     {
  112.         $this->type $type;
  113.         return $this;
  114.     }
  115.     public function getTypeText(): string
  116.     {
  117.         return Type::getText($this->type);
  118.     }
  119.     public function getTypeCss($prefix null): string
  120.     {
  121.         return Type::getCssClass($this->type$prefix);
  122.     }
  123.     public function isCreditType(): bool
  124.     {
  125.         return $this->type === Type::TYPE_CREDIT;
  126.     }
  127.     public function isDebitType(): bool
  128.     {
  129.         return $this->type === Type::TYPE_DEBIT;
  130.     }
  131.     public function getAmount(): ?int
  132.     {
  133.         return $this->amount;
  134.     }
  135.     public function setAmount(int $amount): self
  136.     {
  137.         $this->amount $amount;
  138.         return $this;
  139.     }
  140.     public function getBankStatementRow(): ?array
  141.     {
  142.         return json_decode($this->bankStatementRowtrue);
  143.     }
  144.     public function setBankStatementRow(?array $bankStatementRow): self
  145.     {
  146.         $this->bankStatementRow json_encode($bankStatementRow,
  147.             JSON_UNESCAPED_UNICODE JSON_UNESCAPED_SLASHES);
  148.         return $this;
  149.     }
  150.     public function getDate(): ?\DateTimeInterface
  151.     {
  152.         return $this->date;
  153.     }
  154.     public function setDate(?\DateTimeInterface $date): self
  155.     {
  156.         $this->date $date;
  157.         return $this;
  158.     }
  159.     public function getCandidate(): ?Candidate
  160.     {
  161.         return $this->candidate;
  162.     }
  163.     public function setCandidate(?Candidate $candidate): self
  164.     {
  165.         $this->candidate $candidate;
  166.         return $this;
  167.     }
  168.     public function getInvoice(): ?Invoice
  169.     {
  170.         return $this->invoice;
  171.     }
  172.     public function setInvoice(?Invoice $invoice): self
  173.     {
  174.         // unset the owning side of the relation if necessary
  175.         if ($invoice === null && $this->invoice !== null) {
  176.             $this->invoice->setTransaction(null);
  177.         }
  178.         // set the owning side of the relation if necessary
  179.         if ($invoice !== null && $invoice->getTransaction() !== $this) {
  180.             $invoice->setTransaction($this);
  181.         }
  182.         $this->invoice $invoice;
  183.         return $this;
  184.     }
  185.     public function getFinanceCategory(): ?FinanceCategory
  186.     {
  187.         return $this->financeCategory;
  188.     }
  189.     public function setFinanceCategory(?FinanceCategory $financeCategory): self
  190.     {
  191.         $this->financeCategory $financeCategory;
  192.         return $this;
  193.     }
  194.     public function getPerson(): ?Person
  195.     {
  196.         return $this->person;
  197.     }
  198.     public function setPerson(?Person $person): self
  199.     {
  200.         $this->person $person;
  201.         return $this;
  202.     }
  203.     public function getPurposeEntity()
  204.     {
  205.         if ($this->getPayment()) {
  206.             return $this->getPayment()->getCalendarEvent();
  207.         } elseif ($this->getInvoice()) {
  208.             return $this->getInvoice()->getCandidate() && $this->getInvoice()->getCandidate()->getCalendarEvent()
  209.                 ? $this->getInvoice()->getCandidate()->getCalendarEvent() : null;
  210.         }
  211.         return null;
  212.     }
  213.     public function getPurposeText(): ?string
  214.     {
  215.         $entity $this->getPurposeEntity();
  216.         if ($entity) {
  217.             return $entity->getName();
  218.         }
  219.         return null;
  220.     }
  221.     public function getPayment(): ?Payment
  222.     {
  223.         return $this->payment;
  224.     }
  225.     public function setPayment(?Payment $payment): self
  226.     {
  227.         // unset the owning side of the relation if necessary
  228.         if ($payment === null && $this->payment !== null) {
  229.             $this->payment->setTransaction(null);
  230.         }
  231.         // set the owning side of the relation if necessary
  232.         if ($payment !== null && $payment->getTransaction() !== $this) {
  233.             $payment->setTransaction($this);
  234.         }
  235.         $this->payment $payment;
  236.         return $this;
  237.     }
  238. }