src/Entity/PagoTPV.php line 16
- <?php
- namespace App\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\Validator\Constraints as Assert;
- /**
- * PagoTPV
- *
- * @ORM\Table(name="pago_tpv")
- * @ORM\HasLifecycleCallbacks
- * @ORM\Entity
- */
- class PagoTPV
- {
- const EN_PASARELA_DE_PAGO = "En pasarela de pago";
- const PAGADO = "Pagado";
- const PENDIENTE_DE_PAGO = "Pendiente de pago";
- const CANCELADO = "Cancelado";
- const DEVUELTO = "Devuelto";
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var float
- *
- * @ORM\Column(name="total", type="float")
- */
- private $total=0;
- /**
- * @var string
- *
- * @ORM\Column(name="ticket", type="string", length=255)
- */
- private $ticket;
- /**
- * @var string
- *
- * @ORM\Column(name="estado", type="string", length=255)
- */
- private $estado;
- /**
- * @ORM\ManyToOne(targetEntity="App\Entity\User")
- * @ORM\JoinColumn(name="usuario", referencedColumnName="id")
- */
- private $usuario;
- /**
- * @var string
- *
- * @ORM\Column(name="hash", type="string", length=255)
- */
- private $hash;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fecha_creado", type="datetime", nullable=true)
- */
- private $fechaCreado;
- /**
- * @var string
- *
- * @ORM\Column(name="comentario", type="text", nullable=true)
- */
- private $comentario;
- /**
- * @var boolean
- *
- * @ORM\Column(name="revisado", type="boolean", options={"default":0})
- */
- private $revisado=false;
- /**
- * @var float
- *
- * @ORM\Column(name="devuelto", type="float")
- */
- private $devuelto=0;
- /**
- * @var ArrayCollection
- *
- * @ORM\OneToMany(targetEntity="HistorialDevolucion", mappedBy="pagoTpv")
- */
- protected $historialDevoluciones;
- public function __construct() {
- $this->estado = self::PENDIENTE_DE_PAGO;
- $this->fechaCreado = new \DateTime();
- $this->historialDevoluciones = new ArrayCollection();
- }
- public function __toString() {
- return $this->getId()."-".$this->getTicket();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- public function getTotal(): ?float
- {
- return $this->total;
- }
- public function setTotal(float $total): self
- {
- $this->total = $total;
- return $this;
- }
- public function getTicket(): ?string
- {
- return $this->ticket;
- }
- public function setTicket(string $ticket): self
- {
- $this->ticket = $ticket;
- return $this;
- }
- public function getEstado(): ?string
- {
- return $this->estado;
- }
- public function setEstado(string $estado): self
- {
- $this->estado = $estado;
- return $this;
- }
- public function getUsuario(): ?User
- {
- return $this->usuario;
- }
- public function setUsuario(?User $usuario): self
- {
- $this->usuario = $usuario;
- return $this;
- }
- public function getHash(): ?string
- {
- return $this->hash;
- }
- public function setHash(string $hash): self
- {
- $this->hash = $hash;
- return $this;
- }
- public static function generateHash($pagoTPV) {
- return md5("GR".$pagoTPV->getTicket().$pagoTPV->getTotal()."HT");
- }
- /**
- * @ORM\PrePersist
- */
- public function actualizarHash() {
- $this->setHash(self::generateHash($this));
- }
- public function isPendiente() {
- return ($this->getEstado() == self::PENDIENTE_DE_PAGO or $this->getEstado() == self::EN_PASARELA_DE_PAGO);
- }
- public function isPagado() {
- return ($this->getEstado() == self::PAGADO);
- }
- public function puedeDevolver() {
- return ($this->getEstado() == self::DEVUELTO and $this->getTotal() > $this->getDevuelto());
- }
- public function setFechaCreado($fechaCreado)
- {
- $this->fechaCreado = $fechaCreado;
- return $this;
- }
- public function getFechaCreado()
- {
- return $this->fechaCreado;
- }
- public function getComentario()
- {
- return $this->comentario;
- }
- public function setComentario($comentario)
- {
- $this->comentario = $comentario;
- return $this;
- }
- public function getRevisado()
- {
- return $this->revisado;
- }
- public function setRevisado($revisado)
- {
- $this->revisado = $revisado;
- return $this;
- }
- public function getDevuelto()
- {
- return $this->devuelto;
- }
- public function setDevuelto(float $devuelto)
- {
- $this->devuelto = $devuelto;
- return $this;
- }
- public function getHistorialDevoluciones()
- {
- return $this->historialDevoluciones;
- }
- public function addHistorialDevolucion($historialDevolucion)
- {
- if (!$this->historialDevoluciones->contains($historialDevolucion)) {
- $this->historialDevoluciones->add($historialDevolucion);
- $historialDevolucion->setPagoTpv($this);
- }
- return $this;
- }
- public function removeHistorialDevolucion($historialDevolucion)
- {
- if ($this->historialDevoluciones->removeElement($historialDevolucion)) {
- // set the owning side to null (unless already changed)
- if ($historialDevolucion->getPagoTpv() === $this) {
- $historialDevolucion->setPagoTpv(null);
- }
- }
- return $this;
- }
- }