<?php
namespace App\Entity;
use App\Repository\InvoicesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping\UniqueConstraint;
/**
* @ORM\Entity(repositoryClass=InvoicesRepository::class)
* @ORM\Table(
* name="invoices",
* uniqueConstraints={
* @ORM\UniqueConstraint(columns={"invoice_number"})
* }
* )
* @UniqueEntity(
* fields={"invoice_number"},
* message="Invoice already registered|Invoice %s already registered"
* )
*/
class Invoices
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "invoice@core",
* "invoice@base"
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=64, nullable=true)
* @Groups({
* "invoice@core",
* "invoice@base"
* })
*/
private $invoice_number;
/**
* @ORM\ManyToOne(targetEntity=PaymentCurrencyTypes::class, inversedBy="invoices")
* @ORM\JoinColumn(nullable=true )
* @Groups({
* "invoice@payment_currency"
* })
*/
private $currency;
/**
* @ORM\ManyToOne(targetEntity=InvoiceType::class, inversedBy="invoices")
* @ORM\JoinColumn(nullable=false)
* @Groups({
* "invoice@invoice_type"
* })
*/
private $invoice_type;
/**
* @ORM\Column(type="datetime_immutable")
* @Groups({
* "invoice@core"
* })
*/
private $created_at;
/**
* @ORM\ManyToOne(targetEntity=ProjectOwner::class, inversedBy="invoices")
* TODO Temporarily nullable=true otherwise is false
* @ORM\JoinColumn(nullable=false)
* @Groups({
* "invoice@customer"
* })
*/
private $customer;
/**
* @ORM\OneToMany(targetEntity=InvoicePositions::class, mappedBy="invoice", cascade={"persist"}, orphanRemoval=true)
* @Groups({
* "invoice@positions"
* })
*/
private $invoice_positions;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="invoices")
* @Groups({
* "invoice@adder"
* })
*/
private $adder;
/**
* @ORM\Column(type="date_immutable", nullable=true)
* @Groups({
* "invoice@core",
* "invoice@base"
* })
*/
private $approved_at;
/**
* @ORM\Column(type="date_immutable", nullable=true)
* @Groups({
* "invoice@core",
* "invoice@base"
* })
*/
private $paid_at;
/**
* Virtual column manage ove Subscriber
* @Groups({
* "invoice@core"
* })
*/
private $paid_status;
/**
* @ORM\OneToOne(targetEntity=Vouchers::class, cascade={"persist"})
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $ref_voucher;
/**
* @ORM\OneToOne(targetEntity=ProjectOrderInvoices::class, cascade={"persist"})
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $ref_project_order_invoice;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $note;
/**
* @see Virtual Column (Set in DoctrineSubscriber)
* @Groups({
* "invoice@core"
* })
*/
private $week_of_year;
/**
* @ORM\OneToOne(targetEntity=InvoiceMetrics::class, mappedBy="invoice", cascade={"persist", "remove"})
* @Groups({
* "invoice@invoice_metrics"
* })
*/
private $invoice_metrics;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({
* "invoice@core"
* })
*/
private $due_days;
/**
* @ORM\Column(type="date_immutable", nullable=true)
* @Groups({
* "invoice@core"
* })
*/
private $due_at;
public function getWeekOfYear() { return $this->week_of_year; }
public function setWeekOfYear($week_of_year): void { $this->week_of_year = $week_of_year; }
public function getPaidStatus() { return $this->paid_status; }
public function setPaidStatus($paid_status): void { $this->paid_status = $paid_status; }
public function __construct()
{
$this->invoice_positions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getInvoiceNumber(): ?string
{
return $this->invoice_number;
}
public function setInvoiceNumber(?string $invoice_number): self
{
$this->invoice_number = $invoice_number;
return $this;
}
public function getCurrency(): ?PaymentCurrencyTypes
{
return $this->currency;
}
public function setCurrency(?PaymentCurrencyTypes $currency): self
{
$this->currency = $currency;
return $this;
}
public function getInvoiceType(): ?InvoiceType
{
return $this->invoice_type;
}
public function setInvoiceType(?InvoiceType $invoice_type): self
{
$this->invoice_type = $invoice_type;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getCustomer(): ?ProjectOwner
{
return $this->customer;
}
public function setCustomer(?ProjectOwner $customer): self
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection<int, InvoicePositions>&Selectable
*/
public function getInvoicePositions(): Collection
{
return $this->invoice_positions;
}
public function addInvoicePosition(InvoicePositions $invoicePosition): self
{
if (!$this->invoice_positions->contains($invoicePosition)) {
$this->invoice_positions[] = $invoicePosition;
$invoicePosition->setInvoice($this);
}
return $this;
}
public function removeInvoicePosition(InvoicePositions $invoicePosition): self
{
if ($this->invoice_positions->removeElement($invoicePosition)) {
// set the owning side to null (unless already changed)
if ($invoicePosition->getInvoice() === $this) {
$invoicePosition->setInvoice(null);
}
}
return $this;
}
public function getAdder(): ?User
{
return $this->adder;
}
public function setAdder(?User $adder): self
{
$this->adder = $adder;
return $this;
}
public function getApprovedAt(): ?\DateTimeImmutable
{
return $this->approved_at;
}
public function setApprovedAt(?\DateTimeImmutable $approved_at): self
{
$this->approved_at = $approved_at;
return $this;
}
public function getPaidAt(): ?\DateTimeImmutable
{
return $this->paid_at;
}
public function setPaidAt(?\DateTimeImmutable $paid_at): self
{
$this->paid_at = $paid_at;
return $this;
}
public function getRefVoucher(): ?Vouchers
{
return $this->ref_voucher;
}
public function setRefVoucher(?Vouchers $ref_voucher): self
{
$this->ref_voucher = $ref_voucher;
return $this;
}
public function getRefProjectOrderInvoice(): ?ProjectOrderInvoices
{
return $this->ref_project_order_invoice;
}
public function setRefProjectOrderInvoice(?ProjectOrderInvoices $ref_project_order_invoice): self
{
$this->ref_project_order_invoice = $ref_project_order_invoice;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getInvoiceMetrics(): ?InvoiceMetrics
{
return $this->invoice_metrics;
}
public function setInvoiceMetrics(?InvoiceMetrics $invoice_metrics): self
{
// unset the owning side of the relation if necessary
if ($invoice_metrics === null && $this->invoice_metrics !== null) {
$this->invoice_metrics->setInvoice(null);
}
// set the owning side of the relation if necessary
if ($invoice_metrics !== null && $invoice_metrics->getInvoice() !== $this) {
$invoice_metrics->setInvoice($this);
}
$this->invoice_metrics = $invoice_metrics;
return $this;
}
public function getDueDays(): ?int
{
return $this->due_days;
}
public function setDueDays(?int $due_days): self
{
$this->due_days = $due_days;
return $this;
}
public function getDueAt(): ?\DateTimeImmutable
{
return $this->due_at;
}
public function setDueAt(?\DateTimeImmutable $due_at): self
{
$this->due_at = $due_at;
return $this;
}
}