src/MDS/VenuesBundle/Entity/ReservationProformaDeposit.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\MDS\VenuesBundle\Entity;
  3. use App\Entity\SageVatRates;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * ReservationProformaDeposit
  9.  *
  10.  * @ORM\Table(name="reservation_proforma_deposit")
  11.  * @ORM\Entity(repositoryClass="App\MDS\VenuesBundle\Repository\ReservationProformaDepositRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class ReservationProformaDeposit
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(name="prefix", type="string", length=255, nullable=true)
  28.      */
  29.     private $prefix;
  30.     /**
  31.      * @var string
  32.      *
  33.      * @ORM\Column(name="number", type="string", length=255, nullable=true)
  34.      */
  35.     private $number;
  36.     /**
  37.      * @var /datetime
  38.      *
  39.      * @ORM\Column(name="date_at", type="datetime")
  40.      */
  41.     private $dateAt;
  42.     /**
  43.      * @var int
  44.      *
  45.      * @ORM\Column(name="reservation_id", type="integer")
  46.      */
  47.     private $reservationId;
  48.     /**
  49.      * @var string
  50.      *
  51.      * @ORM\Column(name="name", type="string", length=255)
  52.      */
  53.     private $name;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="amount", type="string", length=255)
  58.      */
  59.     private $amount;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(name="iva", type="string", length=255)
  64.      */
  65.     private $iva;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity=SageVatRates::class)
  68.      * @ORM\JoinColumn(name="sage_iva", referencedColumnName="id", onDelete="SET NULL")
  69.      */
  70.     private $sageIva;
  71.     /**
  72.      * @var string
  73.      *
  74.      * @ORM\Column(name="total", type="string", length=255)
  75.      */
  76.     private $total;
  77.     /**
  78.      * @var \DateTime
  79.      *
  80.      * @ORM\Column(name="created_at", type="datetime")
  81.      */
  82.     private $createdAt;
  83.     /**
  84.      * @var int
  85.      *
  86.      * @ORM\Column(name="created_id", type="integer")
  87.      */
  88.     private $createdId;
  89.     /**
  90.      * @var \DateTime
  91.      *
  92.      * @ORM\Column(name="updated_at", type="datetime")
  93.      */
  94.     private $updatedAt;
  95.     /**
  96.      * @var int
  97.      *
  98.      * @ORM\Column(name="updated_id", type="integer")
  99.      */
  100.     private $updatedId;
  101.     /**
  102.      * @ORM\OneToMany(
  103.      *   targetEntity="App\MDS\VenuesBundle\Entity\ReservationDeposit",
  104.      *   mappedBy="proformaDeposit",
  105.      *   cascade={"persist"},
  106.      *   orphanRemoval=false
  107.      * )
  108.      */
  109.     private $deposits;
  110.     /**
  111.      * @ORM\OneToOne(
  112.      *   targetEntity="App\MDS\VenuesBundle\Entity\ReservationInvoice",
  113.      *   inversedBy="proformaDeposit",
  114.      *   cascade={"persist"}
  115.      * )
  116.      * @ORM\JoinColumn(
  117.      *   name="reservation_invoice_id",
  118.      *   referencedColumnName="id",
  119.      *   nullable=true,
  120.      *   onDelete="SET NULL",
  121.      *   unique=true
  122.      * )
  123.      */
  124.     private $invoice;
  125.     public function __construct()
  126.     {
  127.         $this->deposits = new ArrayCollection();
  128.     }
  129.     /**
  130.      * Get id
  131.      *
  132.      * @return int
  133.      */
  134.     public function getId()
  135.     {
  136.         return $this->id;
  137.     }
  138.     /**
  139.      * Set prefix
  140.      *
  141.      * @param string $prefix
  142.      *
  143.      * @return ReservationProformaDeposit
  144.      */
  145.     public function setPrefix($prefix)
  146.     {
  147.         $this->prefix $prefix;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get prefix
  152.      *
  153.      * @return string
  154.      */
  155.     public function getPrefix()
  156.     {
  157.         return $this->prefix;
  158.     }
  159.     /**
  160.      * Set number
  161.      *
  162.      * @param string $number
  163.      *
  164.      * @return ReservationProformaDeposit
  165.      */
  166.     public function setNumber($number)
  167.     {
  168.         $this->number $number;
  169.         return $this;
  170.     }
  171.     /**
  172.      * Get number
  173.      *
  174.      * @return string
  175.      */
  176.     public function getNumber()
  177.     {
  178.         return $this->number;
  179.     }
  180.     /**
  181.      * Set dateAt
  182.      *
  183.      * @param \DateTime $dateAt
  184.      *
  185.      * @return ReservationProformaDeposit
  186.      */
  187.     public function setDateAt($dateAt)
  188.     {
  189.         $this->dateAt $dateAt;
  190.         return $this;
  191.     }
  192.     /**
  193.      * Get dateAt
  194.      *
  195.      * @return \DateTime
  196.      */
  197.     public function getDateAt()
  198.     {
  199.         return $this->dateAt;
  200.     }
  201.     /**
  202.      * Set reservationId
  203.      *
  204.      * @param integer $reservationId
  205.      *
  206.      * @return ReservationProformaDeposit
  207.      */
  208.     public function setReservationId($reservationId)
  209.     {
  210.         $this->reservationId $reservationId;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Get reservationId
  215.      *
  216.      * @return integer
  217.      */
  218.     public function getReservationId()
  219.     {
  220.         return $this->reservationId;
  221.     }
  222.     /**
  223.      * Set name
  224.      *
  225.      * @param string $name
  226.      *
  227.      * @return ReservationProformaDeposit
  228.      */
  229.     public function setName($name)
  230.     {
  231.         $this->name $name;
  232.         return $this;
  233.     }
  234.     /**
  235.      * Get name
  236.      *
  237.      * @return string
  238.      */
  239.     public function getName()
  240.     {
  241.         return $this->name;
  242.     }
  243.     /**
  244.      * Set amount
  245.      *
  246.      * @param string $amount
  247.      *
  248.      * @return ReservationProformaDeposit
  249.      */
  250.     public function setAmount($amount)
  251.     {
  252.         $this->amount $amount;
  253.         return $this;
  254.     }
  255.     /**
  256.      * Get amount
  257.      *
  258.      * @return string
  259.      */
  260.     public function getAmount()
  261.     {
  262.         return $this->amount;
  263.     }
  264.     /**
  265.      * Set iva
  266.      *
  267.      * @param string $iva
  268.      *
  269.      * @return ReservationProformaDeposit
  270.      */
  271.     public function setIva($iva)
  272.     {
  273.         $this->iva $iva;
  274.         return $this;
  275.     }
  276.     /**
  277.      * Get iva
  278.      *
  279.      * @return string
  280.      */
  281.     public function getIva()
  282.     {
  283.         return $this->iva;
  284.     }
  285.     public function getSageIva(): ?SageVatRates
  286.     {
  287.         return $this->sageIva;
  288.     }
  289.     public function setSageIva(?SageVatRates $sageIva): self
  290.     {
  291.         $this->sageIva $sageIva;
  292.         return $this;
  293.     }
  294.     /**
  295.      * Set createdAt
  296.      *
  297.      * @param \DateTime $createdAt
  298.      *
  299.      * @return ReservationProformaDeposit
  300.      */
  301.     public function setCreatedAt($createdAt)
  302.     {
  303.         $this->createdAt $createdAt;
  304.         return $this;
  305.     }
  306.     /**
  307.      * Get createdAt
  308.      *
  309.      * @return \DateTime
  310.      */
  311.     public function getCreatedAt()
  312.     {
  313.         return $this->createdAt;
  314.     }
  315.     /**
  316.      * Set createdId
  317.      *
  318.      * @param integer $createdId
  319.      *
  320.      * @return ReservationProformaDeposit
  321.      */
  322.     public function setCreatedId($createdId)
  323.     {
  324.         $this->createdId $createdId;
  325.         return $this;
  326.     }
  327.     /**
  328.      * Get createdId
  329.      *
  330.      * @return integer
  331.      */
  332.     public function getCreatedId()
  333.     {
  334.         return $this->createdId;
  335.     }
  336.     /**
  337.      * Set updatedAt
  338.      *
  339.      * @param \DateTime $updatedAt
  340.      *
  341.      * @return ReservationProformaDeposit
  342.      */
  343.     public function setUpdatedAt($updatedAt)
  344.     {
  345.         $this->updatedAt $updatedAt;
  346.         return $this;
  347.     }
  348.     /**
  349.      * Get updatedAt
  350.      *
  351.      * @return \DateTime
  352.      */
  353.     public function getUpdatedAt()
  354.     {
  355.         return $this->updatedAt;
  356.     }
  357.     /**
  358.      * Set updatedId
  359.      *
  360.      * @param integer $updatedId
  361.      *
  362.      * @return ReservationProformaDeposit
  363.      */
  364.     public function setUpdatedId($updatedId)
  365.     {
  366.         $this->updatedId $updatedId;
  367.         return $this;
  368.     }
  369.     /**
  370.      * Get updatedId
  371.      *
  372.      * @return integer
  373.      */
  374.     public function getUpdatedId()
  375.     {
  376.         return $this->updatedId;
  377.     }
  378.     /**
  379.      * Set total
  380.      *
  381.      * @param string $total
  382.      *
  383.      * @return ReservationProformaDeposit
  384.      */
  385.     public function setTotal($total)
  386.     {
  387.         $this->total $total;
  388.         return $this;
  389.     }
  390.     /**
  391.      * Get total
  392.      *
  393.      * @return string
  394.      */
  395.     public function getTotal()
  396.     {
  397.         return $this->total;
  398.     }
  399.     public function getDeposits(): Collection
  400.     {
  401.         return $this->deposits;
  402.     }
  403.     /** helpers para sincronizar ambos lados */
  404.     public function addDeposit(ReservationDeposit $deposit): self
  405.     {
  406.         if (!$this->deposits->contains($deposit)) {
  407.             $this->deposits[] = $deposit;
  408.             $deposit->setProformaDeposit($this);
  409.         }
  410.         return $this;
  411.     }
  412.     public function removeDeposit(ReservationDeposit $deposit): self
  413.     {
  414.         if ($this->deposits->removeElement($deposit) && $deposit->getProformaDeposit() === $this) {
  415.             $deposit->setProformaDeposit(null);
  416.         }
  417.         return $this;
  418.     }
  419.     /** Atajo útil para la vista */
  420.     public function getPaidTotal(): string
  421.     {
  422.         $sum 0.0;
  423.         foreach ($this->deposits as $d) {
  424.             $sum += (float)$d->getAmount();
  425.         }
  426.         return number_format($sum2'.''');
  427.     }
  428.     /** Solo depósitos completados */
  429.     public function getDepositsIsDone(): Collection
  430.     {
  431.         return $this->deposits->filter(function ($deposit) {
  432.             return $deposit->getIsDone();
  433.         });
  434.     }
  435.     public function getInvoice(): ?ReservationInvoice
  436.     {
  437.         return $this->invoice;
  438.     }
  439.     public function setInvoice(?ReservationInvoice $invoice): self
  440.     {
  441.         $this->invoice $invoice;
  442.         // Sincroniza el lado inverso
  443.         if ($invoice && $invoice->getProformaDeposit() !== $this) {
  444.             $invoice->setProformaDeposit($this);
  445.         }
  446.         return $this;
  447.     }
  448.     /**
  449.      * @ORM\PrePersist
  450.      */
  451.     public function prePersist()
  452.     {
  453.         $this->createdAt = new \DateTime();
  454.         $this->updatedAt = new \DateTime();
  455.     }
  456.     /**
  457.      * @ORM\PreUpdate
  458.      */
  459.     public function preUpdate()
  460.     {
  461.         $this->updatedAt = new \DateTime();
  462.     }
  463. }