src/Entity/PagoTPV.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7.  * PagoTPV
  8.  *
  9.  * @ORM\Table(name="pago_tpv")
  10.  * @ORM\HasLifecycleCallbacks 
  11.  * @ORM\Entity
  12.  */
  13. class PagoTPV 
  14. {
  15.     const EN_PASARELA_DE_PAGO   "En pasarela de pago";
  16.     const PAGADO                "Pagado";
  17.     const PENDIENTE_DE_PAGO     "Pendiente de pago";
  18.     const CANCELADO             "Cancelado";
  19.     const DEVUELTO              "Devuelto";
  20.     
  21.     /**
  22.      * @var integer
  23.      *
  24.      * @ORM\Column(name="id", type="integer")
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @var float
  31.      *
  32.      * @ORM\Column(name="total", type="float")
  33.      */
  34.     private $total=0;
  35.     
  36.     
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="ticket", type="string", length=255)
  41.      */
  42.     private $ticket;
  43.     
  44.     /**
  45.      * @var string
  46.      *
  47.      * @ORM\Column(name="estado", type="string", length=255)
  48.      */
  49.     private $estado;
  50.    
  51.     /**
  52.     * @ORM\ManyToOne(targetEntity="App\Entity\User")
  53.     * @ORM\JoinColumn(name="usuario", referencedColumnName="id")
  54.     */
  55.     private $usuario;
  56.     
  57.     
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="hash", type="string", length=255)
  62.      */
  63.     private $hash;
  64.     
  65.     /**
  66.      * @var \DateTime
  67.      *
  68.      * @ORM\Column(name="fecha_creado", type="datetime", nullable=true)
  69.      */
  70.     private $fechaCreado;
  71.     
  72.     /**
  73.      * @var string
  74.      *
  75.      * @ORM\Column(name="comentario", type="text", nullable=true)
  76.      */
  77.     private $comentario;
  78.     
  79.     /**
  80.      * @var boolean
  81.      *
  82.      * @ORM\Column(name="revisado", type="boolean", options={"default":0})
  83.      */
  84.     private $revisado=false;
  85.     /**
  86.      * @var float
  87.      *
  88.      * @ORM\Column(name="devuelto", type="float")
  89.      */
  90.     private $devuelto=0;
  91.     /**
  92.      * @var ArrayCollection
  93.      *
  94.      * @ORM\OneToMany(targetEntity="HistorialDevolucion", mappedBy="pagoTpv")
  95.      */
  96.     protected $historialDevoluciones;
  97.     
  98.     public function __construct() {
  99.         $this->estado self::PENDIENTE_DE_PAGO;
  100.         $this->fechaCreado = new \DateTime();
  101.         $this->historialDevoluciones = new ArrayCollection();
  102.     }
  103.     
  104.     public function __toString() {
  105.         return $this->getId()."-".$this->getTicket();
  106.         
  107.     }
  108.     
  109.     /**
  110.      * Get id
  111.      *
  112.      * @return integer 
  113.      */
  114.     public function getId()
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getTotal(): ?float
  119.     {
  120.         return $this->total;
  121.     }
  122.     public function setTotal(float $total): self
  123.     {
  124.         $this->total $total;
  125.         return $this;
  126.     }
  127.     public function getTicket(): ?string
  128.     {
  129.         return $this->ticket;
  130.     }
  131.     public function setTicket(string $ticket): self
  132.     {
  133.         $this->ticket $ticket;
  134.         return $this;
  135.     }
  136.     public function getEstado(): ?string
  137.     {
  138.         return $this->estado;
  139.     }
  140.     public function setEstado(string $estado): self
  141.     {
  142.         $this->estado $estado;
  143.         return $this;
  144.     }
  145.     public function getUsuario(): ?User
  146.     {
  147.         return $this->usuario;
  148.     }
  149.     public function setUsuario(?User $usuario): self
  150.     {
  151.         $this->usuario $usuario;
  152.         return $this;
  153.     }
  154.     public function getHash(): ?string
  155.     {
  156.         return $this->hash;
  157.     }
  158.     public function setHash(string $hash): self
  159.     {
  160.         $this->hash $hash;
  161.         return $this;
  162.     }
  163.     
  164.     
  165.     public static function generateHash($pagoTPV) {
  166.         return md5("GR".$pagoTPV->getTicket().$pagoTPV->getTotal()."HT");
  167.     }
  168.     
  169.     
  170.     /**
  171.      * @ORM\PrePersist
  172.      */
  173.     public function actualizarHash() {
  174.     
  175.         $this->setHash(self::generateHash($this));
  176.     
  177.     }
  178.     
  179.     public function isPendiente() {
  180.         return ($this->getEstado() == self::PENDIENTE_DE_PAGO or $this->getEstado() == self::EN_PASARELA_DE_PAGO);
  181.     }
  182.     public function isPagado() {
  183.         return ($this->getEstado() == self::PAGADO);
  184.     }
  185.     public function puedeDevolver() {
  186.         return ($this->getEstado() == self::DEVUELTO and $this->getTotal() > $this->getDevuelto());
  187.     }
  188.     
  189.     public function setFechaCreado($fechaCreado)
  190.     {
  191.         $this->fechaCreado $fechaCreado;
  192.         return $this;
  193.     }
  194.     
  195.     public function getFechaCreado()
  196.     {
  197.         return $this->fechaCreado;
  198.     }
  199.     
  200.     public function getComentario()
  201.     {
  202.         return $this->comentario;
  203.     }
  204.     
  205.     public function setComentario($comentario)
  206.     {
  207.         $this->comentario $comentario;
  208.         return $this;
  209.     }
  210.     
  211.     
  212.     public function getRevisado()
  213.     {
  214.         return $this->revisado;
  215.     }
  216.     
  217.     public function setRevisado($revisado)
  218.     {
  219.         $this->revisado $revisado;
  220.         return $this;
  221.     }
  222.     public function getDevuelto()
  223.     {
  224.         return $this->devuelto;
  225.     }
  226.     public function setDevuelto(float $devuelto)
  227.     {
  228.         $this->devuelto $devuelto;
  229.         return $this;
  230.     }
  231.     public function getHistorialDevoluciones()
  232.     {
  233.         return $this->historialDevoluciones;
  234.     }
  235.     public function addHistorialDevolucion($historialDevolucion)
  236.     {
  237.         if (!$this->historialDevoluciones->contains($historialDevolucion)) {
  238.             $this->historialDevoluciones->add($historialDevolucion);
  239.             $historialDevolucion->setPagoTpv($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeHistorialDevolucion($historialDevolucion)
  244.     {
  245.         if ($this->historialDevoluciones->removeElement($historialDevolucion)) {
  246.             // set the owning side to null (unless already changed)
  247.             if ($historialDevolucion->getPagoTpv() === $this) {
  248.                 $historialDevolucion->setPagoTpv(null);
  249.             }
  250.         }
  251.         return $this;
  252.     }
  253.   
  254. }