<?php
namespace App\MDS\VenuesBundle\Entity;
use App\Entity\SageVatRates;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* ReservationProformaDeposit
*
* @ORM\Table(name="reservation_proforma_deposit")
* @ORM\Entity(repositoryClass="App\MDS\VenuesBundle\Repository\ReservationProformaDepositRepository")
* @ORM\HasLifecycleCallbacks()
*/
class ReservationProformaDeposit
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="prefix", type="string", length=255, nullable=true)
*/
private $prefix;
/**
* @var string
*
* @ORM\Column(name="number", type="string", length=255, nullable=true)
*/
private $number;
/**
* @var /datetime
*
* @ORM\Column(name="date_at", type="datetime")
*/
private $dateAt;
/**
* @var int
*
* @ORM\Column(name="reservation_id", type="integer")
*/
private $reservationId;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="amount", type="string", length=255)
*/
private $amount;
/**
* @var string
*
* @ORM\Column(name="iva", type="string", length=255)
*/
private $iva;
/**
* @ORM\ManyToOne(targetEntity=SageVatRates::class)
* @ORM\JoinColumn(name="sage_iva", referencedColumnName="id", onDelete="SET NULL")
*/
private $sageIva;
/**
* @var string
*
* @ORM\Column(name="total", type="string", length=255)
*/
private $total;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var int
*
* @ORM\Column(name="created_id", type="integer")
*/
private $createdId;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* @var int
*
* @ORM\Column(name="updated_id", type="integer")
*/
private $updatedId;
/**
* @ORM\OneToMany(
* targetEntity="App\MDS\VenuesBundle\Entity\ReservationDeposit",
* mappedBy="proformaDeposit",
* cascade={"persist"},
* orphanRemoval=false
* )
*/
private $deposits;
/**
* @ORM\OneToOne(
* targetEntity="App\MDS\VenuesBundle\Entity\ReservationInvoice",
* inversedBy="proformaDeposit",
* cascade={"persist"}
* )
* @ORM\JoinColumn(
* name="reservation_invoice_id",
* referencedColumnName="id",
* nullable=true,
* onDelete="SET NULL",
* unique=true
* )
*/
private $invoice;
public function __construct()
{
$this->deposits = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set prefix
*
* @param string $prefix
*
* @return ReservationProformaDeposit
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
return $this;
}
/**
* Get prefix
*
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}
/**
* Set number
*
* @param string $number
*
* @return ReservationProformaDeposit
*/
public function setNumber($number)
{
$this->number = $number;
return $this;
}
/**
* Get number
*
* @return string
*/
public function getNumber()
{
return $this->number;
}
/**
* Set dateAt
*
* @param \DateTime $dateAt
*
* @return ReservationProformaDeposit
*/
public function setDateAt($dateAt)
{
$this->dateAt = $dateAt;
return $this;
}
/**
* Get dateAt
*
* @return \DateTime
*/
public function getDateAt()
{
return $this->dateAt;
}
/**
* Set reservationId
*
* @param integer $reservationId
*
* @return ReservationProformaDeposit
*/
public function setReservationId($reservationId)
{
$this->reservationId = $reservationId;
return $this;
}
/**
* Get reservationId
*
* @return integer
*/
public function getReservationId()
{
return $this->reservationId;
}
/**
* Set name
*
* @param string $name
*
* @return ReservationProformaDeposit
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set amount
*
* @param string $amount
*
* @return ReservationProformaDeposit
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return string
*/
public function getAmount()
{
return $this->amount;
}
/**
* Set iva
*
* @param string $iva
*
* @return ReservationProformaDeposit
*/
public function setIva($iva)
{
$this->iva = $iva;
return $this;
}
/**
* Get iva
*
* @return string
*/
public function getIva()
{
return $this->iva;
}
public function getSageIva(): ?SageVatRates
{
return $this->sageIva;
}
public function setSageIva(?SageVatRates $sageIva): self
{
$this->sageIva = $sageIva;
return $this;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return ReservationProformaDeposit
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set createdId
*
* @param integer $createdId
*
* @return ReservationProformaDeposit
*/
public function setCreatedId($createdId)
{
$this->createdId = $createdId;
return $this;
}
/**
* Get createdId
*
* @return integer
*/
public function getCreatedId()
{
return $this->createdId;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return ReservationProformaDeposit
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set updatedId
*
* @param integer $updatedId
*
* @return ReservationProformaDeposit
*/
public function setUpdatedId($updatedId)
{
$this->updatedId = $updatedId;
return $this;
}
/**
* Get updatedId
*
* @return integer
*/
public function getUpdatedId()
{
return $this->updatedId;
}
/**
* Set total
*
* @param string $total
*
* @return ReservationProformaDeposit
*/
public function setTotal($total)
{
$this->total = $total;
return $this;
}
/**
* Get total
*
* @return string
*/
public function getTotal()
{
return $this->total;
}
public function getDeposits(): Collection
{
return $this->deposits;
}
/** helpers para sincronizar ambos lados */
public function addDeposit(ReservationDeposit $deposit): self
{
if (!$this->deposits->contains($deposit)) {
$this->deposits[] = $deposit;
$deposit->setProformaDeposit($this);
}
return $this;
}
public function removeDeposit(ReservationDeposit $deposit): self
{
if ($this->deposits->removeElement($deposit) && $deposit->getProformaDeposit() === $this) {
$deposit->setProformaDeposit(null);
}
return $this;
}
/** Atajo útil para la vista */
public function getPaidTotal(): string
{
$sum = 0.0;
foreach ($this->deposits as $d) {
$sum += (float)$d->getAmount();
}
return number_format($sum, 2, '.', '');
}
/** Solo depósitos completados */
public function getDepositsIsDone(): Collection
{
return $this->deposits->filter(function ($deposit) {
return $deposit->getIsDone();
});
}
public function getInvoice(): ?ReservationInvoice
{
return $this->invoice;
}
public function setInvoice(?ReservationInvoice $invoice): self
{
$this->invoice = $invoice;
// Sincroniza el lado inverso
if ($invoice && $invoice->getProformaDeposit() !== $this) {
$invoice->setProformaDeposit($this);
}
return $this;
}
/**
* @ORM\PrePersist
*/
public function prePersist()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
/**
* @ORM\PreUpdate
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
}