<?php
namespace App\Entity;
use App\Repository\InvoiceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=InvoiceRepository::class)
*/
class Invoice
{
const TYPE_INVOICE = 'facture';
const TYPE_CREDIT = 'avoir';
const SEND_TO_CUSTOMER = 'invoice_send_to_customer';
const SEND_TO_SPECIFIC = 'invoice_send_to_specific';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=10)
*/
private ?string $reference;
/**
* @ORM\Column(type="string", length=20)
*/
private ?string $type;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $filePath;
/**
* @ORM\Column(type="datetime_immutable")
*/
private ?\DateTimeImmutable $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=Invoice::class, inversedBy="cancelledBy", cascade={"persist"})
*/
private ?Invoice $cancels = null;
/**
* @ORM\OneToMany(targetEntity=Invoice::class, mappedBy="cancels", cascade={"persist"})
*/
private Collection $cancelledBy;
/**
* @ORM\ManyToOne(targetEntity=SaleOrder::class, inversedBy="invoices")
*/
private ?SaleOrder $saleOrder;
/**
* @ORM\ManyToMany(targetEntity=PointTransaction::class, inversedBy="invoices")
*/
private Collection $transactionPoints;
public function __construct()
{
$this->transactionPoints = new ArrayCollection();
$this->cancelledBy = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getInvoiceNumber(): ?string
{
return strtoupper(substr($this->getType(),0,1)) . '-' . (str_pad($this->reference, 10, "0", STR_PAD_LEFT));
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getFilePath(): ?string
{
return $this->filePath;
}
public function setFilePath(?string $filePath): self
{
$this->filePath = $filePath;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCancels(): ?self
{
return $this->cancels;
}
public function setCancels(?self $cancels): self
{
$this->cancels = $cancels;
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getCancelledBy(): Collection
{
return $this->cancelledBy;
}
public function addCancelledBy(Invoice $invoice): self
{
if (!$this->cancelledBy->contains($invoice)) {
$this->cancelledBy[] = $invoice;
$invoice->setCancels($this);
}
return $this;
}
public function removeCancelledBy(Invoice $invoice): self
{
if ($this->cancelledBy->removeElement($invoice)) {
if ($invoice->getCancels() === $this) {
$invoice->setCancels(null);
}
}
return $this;
}
public function getSaleOrder(): ?SaleOrder
{
return $this->saleOrder;
}
public function setSaleOrder(?SaleOrder $saleOrder): self
{
$this->saleOrder = $saleOrder;
return $this;
}
/**
* @return Collection<int, PointTransaction>
*/
public function getPointTransactions(): Collection
{
return $this->transactionPoints;
}
public function addPointTransaction(PointTransaction $transactionPoint): self
{
if (!$this->transactionPoints->contains($transactionPoint)) {
$this->transactionPoints[] = $transactionPoint;
}
return $this;
}
public function removePointTransaction(PointTransaction $transactionPoint): self
{
$this->transactionPoints->removeElement($transactionPoint);
return $this;
}
}