src/Entity/Operacion.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\EstadoOperacionEnum;
  4. use App\Enum\EstadoRelojEnum;
  5. use App\Enum\TipoOperacionEnum;
  6. use DateTime;
  7. use DateTimeInterface;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Validator as PerseoAssert;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. /**
  17.  * @ORM\Entity(repositoryClass="App\Repository\OperacionRepository")
  18.  * @ORM\Table(name="operacion",
  19.  *     indexes={
  20.  *         @ORM\Index(name="idx_operacion_valoracion", columns={"valoracion_id", "deleted_at"})
  21.  *     }
  22.  * )
  23.  * @ORM\EntityListeners({
  24.  *     "App\EntityListener\Operacion\CalcularIDPerseoListener",
  25.  *     "App\EntityListener\Operacion\CalcularTipoOperacionListener",
  26.  *     "App\EntityListener\Operacion\UpdateDatesListener",
  27.  *     "App\EntityListener\Operacion\ControlTipoOperacionListener"
  28.  * })
  29.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  30.  * @Vich\Uploadable
  31.  * @PerseoAssert\ContraintsValidarEntidadDetalleCompra()
  32.  * @PerseoAssert\ContraintsValidarEntidadDetalleVenta()
  33.  */
  34. class Operacion
  35. {
  36.     /**
  37.      * @ORM\Id
  38.      * @ORM\Column(type="bigint", options={"unsigned":true})
  39.      * @ORM\GeneratedValue(strategy="AUTO")
  40.      */
  41.     protected $id;
  42.     /**
  43.      * @ORM\Column(
  44.      *     type="string",
  45.      *     nullable=true,
  46.      *     options={"comment":"valores a tomar (Compra, Gestión, Permuta, Venta)"}
  47.      * )
  48.      */
  49.     protected $tipo;
  50.     /**
  51.      * @ORM\Column(type="string", nullable=true, name="id_perseo")
  52.      */
  53.     protected $IDperseo;
  54.     /**
  55.      * @ORM\Column(type="datetime", nullable=true)
  56.      */
  57.     protected $fecha;
  58.     /**
  59.      * @ORM\Column(type="boolean", nullable=true, options={"comment":"0 => particular, 1 => empresa"})
  60.      */
  61.     protected $tipoCliente;
  62.     /**
  63.      * @ORM\Column(type="boolean", nullable=true, options={"default":0})
  64.      */
  65.     protected $exportacion;
  66.     /**
  67.      * @ORM\Column(type="string", length=2, nullable=true, options={"default":"es"})
  68.      */
  69.     protected $idioma;
  70.     /**
  71.      * @ORM\Column(type="datetime", nullable=true, name="fecha_tramitacion")
  72.      */
  73.     protected $fechaTramitacion;
  74.     /**
  75.      * @ORM\Column(type="datetime", nullable=true, name="fecha_tramitada")
  76.      */
  77.     protected $fechaTramitada;
  78.     /**
  79.      * @ORM\Column(type="datetime", nullable=true, name="fecha_confirmada")
  80.      */
  81.     protected $fechaConfirmada;
  82.     /**
  83.      * @ORM\Column(type="datetime", nullable=true, name="fecha_asentada")
  84.      */
  85.     protected $fechaAsentada;
  86.     /**
  87.      * @ORM\Column(type="datetime", nullable=true, name="fecha_finalizada")
  88.      */
  89.     private $fechaFinalizada;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true, name="fecha_cancelada")
  92.      */
  93.     protected $fechaCancelada;
  94.     /**
  95.      * @ORM\Column(type="string", nullable=true, name="forma_pago")
  96.      */
  97.     protected $formaPago;
  98.     /**
  99.      * @ORM\Column(type="float", nullable=true, precision=2, name="precio_pagar", options={"comment":"Costes compra + Costes venta"})
  100.      */
  101.     protected $precioPagar;
  102.     /**
  103.      * @ORM\Column(type="text", nullable=true, name="comentario_contrato")
  104.      */
  105.     protected $comentarioContrato;
  106.     /**
  107.      * @ORM\Column(type="text", nullable=true)
  108.      */
  109.     protected $comentario;
  110.     /**
  111.      * @ORM\Column(type="string", nullable=true, name="contract_signed")
  112.      */
  113.     protected $contractSigned;
  114.     /**
  115.      * @Assert\File(
  116.      *     mimeTypes={
  117.      *     "application/pdf",
  118.      *     }
  119.      * )
  120.      * @Vich\UploadableField(mapping="operacion", fileNameProperty="contractSigned")
  121.      * @var File
  122.      */
  123.     protected $contractSignedFile;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true, name="can_deleted", options={"default":true})
  126.      */
  127.     protected $canDeleted;
  128.     /**
  129.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  130.      */
  131.     protected $deletedAt;
  132.     /**
  133.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  134.      * @Gedmo\Timestampable(on="update")
  135.      */
  136.     protected $updatedAt;
  137.     /**
  138.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  139.      * @Gedmo\Timestampable(on="create")
  140.      */
  141.     protected $createdAt;
  142.     /**
  143.      * @ORM\OneToOne(targetEntity="App\Entity\Compra", inversedBy="operacion", cascade={"persist"})
  144.      * @ORM\JoinColumn(name="compra_id", referencedColumnName="id", unique=true)
  145.      */
  146.     protected $compra;
  147.     /**
  148.      * @ORM\OneToOne(targetEntity="App\Entity\Venta", inversedBy="operacion", cascade={"persist"})
  149.      * @ORM\JoinColumn(name="venta_id", referencedColumnName="id", unique=true)
  150.      */
  151.     protected $venta;
  152.     /**
  153.      * @ORM\OneToOne(targetEntity="App\Entity\Valoracion", inversedBy="operacion")
  154.      * @ORM\JoinColumn(name="valoracion_id", referencedColumnName="id", unique=true)
  155.      */
  156.     protected $valoracion;
  157.     /**
  158.      * @ORM\OneToMany(targetEntity=\App\Entity\Reloj::class, mappedBy="operacionGestion")
  159.      */
  160.     private $relojesGestion;
  161.     /**
  162.      * @ORM\OneToMany(targetEntity=\App\Entity\Reloj::class, mappedBy="operacionVenta")
  163.      */
  164.     private $relojesVenta;
  165.     /**
  166.      * @ORM\OneToMany(targetEntity=\App\Entity\Reloj::class, mappedBy="operacionCompra")
  167.      */
  168.     private $relojesCompra;
  169.     /**
  170.      * @ORM\ManyToOne(targetEntity="App\Entity\Canal", inversedBy="operaciones")
  171.      * @ORM\JoinColumn(name="canal_id", referencedColumnName="id")
  172.      */
  173.     protected $canal;
  174.     /**
  175.      * @ORM\ManyToOne(targetEntity="App\Entity\Cliente", inversedBy="operaciones")
  176.      * @ORM\JoinColumn(name="cliente_id", referencedColumnName="id")
  177.      */
  178.     protected $cliente;
  179.     /**
  180.      * @ORM\ManyToOne(targetEntity="App\Entity\EstadoOperacion", inversedBy="operaciones")
  181.      * @ORM\JoinColumn(name="estado_id", referencedColumnName="id")
  182.      */
  183.     protected $estado;
  184.     /**
  185.      * @ORM\ManyToOne(targetEntity="App\Entity\Banco", inversedBy="operaciones")
  186.      * @ORM\JoinColumn(name="banco_id", referencedColumnName="id")
  187.      */
  188.     protected $banco;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity="App\Entity\Firmante", inversedBy="operaciones")
  191.      * @ORM\JoinColumn(name="firmante_id", referencedColumnName="id")
  192.      */
  193.     protected $firmante;
  194.     /**
  195.      * @ORM\ManyToOne(targetEntity="App\Entity\Intercambio", inversedBy="operaciones")
  196.      * @ORM\JoinColumn(name="intercambio_id", referencedColumnName="id")
  197.      */
  198.     protected $intercambio;
  199.     /**
  200.      * @ORM\ManyToOne(targetEntity="App\Entity\UnidadNegocio", inversedBy="operaciones")
  201.      * @ORM\JoinColumn(name="unidad_negocio_id", referencedColumnName="id")
  202.      */
  203.     protected $unidadNegocio;
  204.     /**
  205.      * @ORM\ManyToOne(targetEntity="App\Entity\Usuario", inversedBy="operaciones")
  206.      * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id")
  207.      */
  208.     protected $usuario;
  209.     public function __construct()
  210.     {
  211.         $this->venta = new Venta();
  212.         $this->compra = new Compra();
  213.         $this->cliente = new Cliente();
  214.         $this->relojesGestion = new ArrayCollection();
  215.         $this->relojesVenta = new ArrayCollection();
  216.         $this->relojesCompra = new ArrayCollection();
  217.     }
  218.     public function __toString(): string
  219.     {
  220.         return $this->IDperseo??'---';
  221.     }
  222.     public function getId(): ?string
  223.     {
  224.         return $this->id;
  225.     }
  226.     public function getIDperseo(): ?string
  227.     {
  228.         return $this->IDperseo;
  229.     }
  230.     public function setIDperseo(?string $IDperseo): self
  231.     {
  232.         $this->IDperseo $IDperseo;
  233.         return $this;
  234.     }
  235.     public function getFechaTramitacion(): ?DateTimeInterface
  236.     {
  237.         return $this->fechaTramitacion;
  238.     }
  239.     public function setFechaTramitacion(?DateTimeInterface $fechaTramitacion): self
  240.     {
  241.         $this->fechaTramitacion $fechaTramitacion;
  242.         return $this;
  243.     }
  244.     public function getFechaTramitada(): ?DateTimeInterface
  245.     {
  246.         return $this->fechaTramitada;
  247.     }
  248.     public function setFechaTramitada(?DateTimeInterface $fechaTramitada): self
  249.     {
  250.         $this->fechaTramitada $fechaTramitada;
  251.         return $this;
  252.     }
  253.     public function getFechaConfirmada(): ?DateTimeInterface
  254.     {
  255.         return $this->fechaConfirmada;
  256.     }
  257.     public function setFechaConfirmada(?DateTimeInterface $fechaConfirmada): self
  258.     {
  259.         $this->fechaConfirmada $fechaConfirmada;
  260.         return $this;
  261.     }
  262.     public function getFechaAsentada(): ?DateTimeInterface
  263.     {
  264.         return $this->fechaAsentada;
  265.     }
  266.     public function setFechaAsentada(?DateTimeInterface $fechaAsentada): self
  267.     {
  268.         $this->fechaAsentada $fechaAsentada;
  269.         return $this;
  270.     }
  271.     public function getFechaCancelada(): ?DateTimeInterface
  272.     {
  273.         return $this->fechaCancelada;
  274.     }
  275.     public function setFechaCancelada(?DateTimeInterface $fechaCancelada): self
  276.     {
  277.         $this->fechaCancelada $fechaCancelada;
  278.         return $this;
  279.     }
  280.     public function getFormaPago(): ?string
  281.     {
  282.         return $this->formaPago;
  283.     }
  284.     public function setFormaPago(?string $formaPago): self
  285.     {
  286.         $this->formaPago $formaPago;
  287.         return $this;
  288.     }
  289.     public function getPrecioPagar(): ?float
  290.     {
  291.         return $this->precioPagar;
  292.     }
  293.     public function setPrecioPagar(?float $precioPagar): self
  294.     {
  295.         $this->precioPagar $precioPagar;
  296.         return $this;
  297.     }
  298.     public function getDeletedAt(): ?DateTimeInterface
  299.     {
  300.         return $this->deletedAt;
  301.     }
  302.     public function setDeletedAt(?DateTimeInterface $deletedAt): self
  303.     {
  304.         $this->deletedAt $deletedAt;
  305.         return $this;
  306.     }
  307.     public function getUpdatedAt(): ?DateTimeInterface
  308.     {
  309.         return $this->updatedAt;
  310.     }
  311.     public function setUpdatedAt(DateTimeInterface $updatedAt): self
  312.     {
  313.         $this->updatedAt $updatedAt;
  314.         return $this;
  315.     }
  316.     public function getCreatedAt(): ?DateTimeInterface
  317.     {
  318.         return $this->createdAt;
  319.     }
  320.     public function setCreatedAt(DateTimeInterface $createdAt): self
  321.     {
  322.         $this->createdAt $createdAt;
  323.         return $this;
  324.     }
  325.     public function getCanal(): ?Canal
  326.     {
  327.         return $this->canal;
  328.     }
  329.     public function setCanal(?Canal $canal): self
  330.     {
  331.         $this->canal $canal;
  332.         return $this;
  333.     }
  334.     public function getCliente(): ?Cliente
  335.     {
  336.         return $this->cliente;
  337.     }
  338.     public function setCliente(?Cliente $cliente): self
  339.     {
  340.         $this->cliente $cliente;
  341.         return $this;
  342.     }
  343.     public function getVenta(): ?Venta
  344.     {
  345.         return $this->venta;
  346.     }
  347.     public function setVenta(?Venta $venta): self
  348.     {
  349.         $this->venta $venta;
  350.         return $this;
  351.     }
  352.     public function getCompra(): ?Compra
  353.     {
  354.         return $this->compra;
  355.     }
  356.     public function setCompra(?Compra $compra): self
  357.     {
  358.         $this->compra $compra;
  359.         return $this;
  360.     }
  361.     public function getTipoCliente(): ?bool
  362.     {
  363.         return $this->tipoCliente;
  364.     }
  365.     public function setTipoCliente(?bool $tipoCliente): self
  366.     {
  367.         $this->tipoCliente $tipoCliente;
  368.         return $this;
  369.     }
  370.     public function getExportacionStr():string
  371.     {
  372.         return $this->isExportacion() ? 'Exportacion' 'Europa';
  373.     }
  374.     public function getExportacion(): ?bool
  375.     {
  376.         return $this->exportacion;
  377.     }
  378.     public function setExportacion(?bool $exportacion): self
  379.     {
  380.         $this->exportacion $exportacion;
  381.         return $this;
  382.     }
  383.     public function getComentarioContrato(): ?string
  384.     {
  385.         return $this->comentarioContrato;
  386.     }
  387.     public function setComentarioContrato(?string $comentarioContrato): self
  388.     {
  389.         $this->comentarioContrato $comentarioContrato;
  390.         return $this;
  391.     }
  392.     public function getComentario(): ?string
  393.     {
  394.         return $this->comentario;
  395.     }
  396.     public function setComentario(?string $comentario): self
  397.     {
  398.         $this->comentario $comentario;
  399.         return $this;
  400.     }
  401.     public function getValoracion(): ?Valoracion
  402.     {
  403.         return $this->valoracion;
  404.     }
  405.     public function setValoracion(?Valoracion $valoracion): self
  406.     {
  407.         $this->valoracion $valoracion;
  408.         return $this;
  409.     }
  410.     public function getEstado(): ?EstadoOperacion
  411.     {
  412.         return $this->estado;
  413.     }
  414.     public function setEstado(?EstadoOperacion $estado): self
  415.     {
  416.         $this->estado $estado;
  417.         return $this;
  418.     }
  419.     public function getBanco(): ?Banco
  420.     {
  421.         return $this->banco;
  422.     }
  423.     public function setBanco(?Banco $banco): self
  424.     {
  425.         $this->banco $banco;
  426.         return $this;
  427.     }
  428.     public function getFirmante(): ?Firmante
  429.     {
  430.         return $this->firmante;
  431.     }
  432.     public function setFirmante(?Firmante $firmante): self
  433.     {
  434.         $this->firmante $firmante;
  435.         return $this;
  436.     }
  437.     public function getIntercambio(): ?Intercambio
  438.     {
  439.         return $this->intercambio;
  440.     }
  441.     public function setIntercambio(?Intercambio $intercambio): self
  442.     {
  443.         $this->intercambio $intercambio;
  444.         return $this;
  445.     }
  446.     public function getFecha(): ?DateTimeInterface
  447.     {
  448.         return $this->fecha;
  449.     }
  450.     public function setFecha(?DateTimeInterface $fecha): self
  451.     {
  452.         $this->fecha $fecha;
  453.         return $this;
  454.     }
  455.     public function getUnidadNegocio(): ?UnidadNegocio
  456.     {
  457.         return $this->unidadNegocio;
  458.     }
  459.     public function setUnidadNegocio(?UnidadNegocio $unidadNegocio): self
  460.     {
  461.         $this->unidadNegocio $unidadNegocio;
  462.         return $this;
  463.     }
  464.     public function getUsuario(): ?Usuario
  465.     {
  466.         return $this->usuario;
  467.     }
  468.     public function setUsuario(?Usuario $usuario): self
  469.     {
  470.         $this->usuario $usuario;
  471.         return $this;
  472.     }
  473.     public function getIdioma(): ?string
  474.     {
  475.         return $this->idioma;
  476.     }
  477.     public function setIdioma(?string $idioma): self
  478.     {
  479.         $this->idioma $idioma;
  480.         return $this;
  481.     }
  482.     public function isTipoCliente(): ?bool
  483.     {
  484.         return $this->tipoCliente;
  485.     }
  486.     public function isExportacion(): ?bool
  487.     {
  488.         return $this->exportacion;
  489.     }
  490.     public function getContractSigned(): ?string
  491.     {
  492.         return $this->contractSigned;
  493.     }
  494.     public function setContractSigned(?string $contractSigned): static
  495.     {
  496.         $this->contractSigned $contractSigned;
  497.         return $this;
  498.     }
  499.     public function getContractSignedFile(): ?File
  500.     {
  501.         return $this->contractSignedFile;
  502.     }
  503.     public function setContractSignedFile(?File $contractSignedFile): self
  504.     {
  505.         $this->contractSignedFile $contractSignedFile;
  506.         if ($contractSignedFile) {
  507.             // if 'updatedAt' is not defined in your entity, use another property
  508.             $this->setUpdatedAt(new DateTime('now'));
  509.         }
  510.         return $this;
  511.     }
  512.     public function getType(): ?string
  513.     {
  514.         return $this->type;
  515.     }
  516.     public function getTipo(): ?string
  517.     {
  518.         return $this->tipo;
  519.     }
  520.     public function setTipo(string $tipo): static
  521.     {
  522.         $this->tipo $tipo;
  523.         return $this;
  524.     }
  525.     /**
  526.      * @return DateTime
  527.      */
  528.     public function getEstadoFecha(): DateTime
  529.     {
  530.         switch($this->getEstado()?->getKey())
  531.         {
  532.             case EstadoOperacionEnum::ESTADO_EN_TRAMITACION:
  533.                 $fecha $this->getFechaTramitacion();
  534.                 break;
  535.             case EstadoOperacionEnum::ESTADO_TRAMITADA:
  536.                 $fecha $this->getFechaTramitada();
  537.                 break;
  538.             case EstadoOperacionEnum::ESTADO_CONFIRMADA:
  539.                 $fecha $this->getFechaConfirmada();
  540.                 break;
  541.             case EstadoOperacionEnum::ESTADO_CANCELADA:
  542.                 $fecha $this->getFechaCancelada();
  543.                 break;
  544.             case EstadoOperacionEnum::ESTADO_ASENTADA:
  545.                 $fecha $this->getFechaAsentada();
  546.                 break;
  547.             default:
  548.                 $fecha null;
  549.                 break;
  550.         }
  551.         return $fecha;
  552.     }
  553.     public function isCanDeleted(): ?bool
  554.     {
  555.         return $this->canDeleted;
  556.     }
  557.     public function setCanDeleted(?bool $canDeleted): static
  558.     {
  559.         $this->canDeleted $canDeleted;
  560.         return $this;
  561.     }
  562.     /**
  563.      * @return Collection<int, Reloj>
  564.      */
  565.     public function getRelojesGestion(): Collection
  566.     {
  567.         return $this->relojesGestion;
  568.     }
  569.     public function addRelojesGestion(Reloj $relojesGestion): static
  570.     {
  571.         if (!$this->relojesGestion->contains($relojesGestion)) {
  572.             $this->relojesGestion->add($relojesGestion);
  573.             $relojesGestion->setOperacionGestion($this);
  574.         }
  575.         return $this;
  576.     }
  577.     public function removeRelojesGestion(Reloj $relojesGestion): static
  578.     {
  579.         if ($this->relojesGestion->removeElement($relojesGestion)) {
  580.             // set the owning side to null (unless already changed)
  581.             if ($relojesGestion->getOperacionGestion() === $this) {
  582.                 $relojesGestion->setOperacionGestion(null);
  583.             }
  584.         }
  585.         return $this;
  586.     }
  587.     /**
  588.      * @return Collection<int, Reloj>
  589.      */
  590.     public function getRelojesVenta(): Collection
  591.     {
  592.         return $this->relojesVenta;
  593.     }
  594.     public function addRelojesVentum(Reloj $relojesVentum): static
  595.     {
  596.         if (!$this->relojesVenta->contains($relojesVentum)) {
  597.             $this->relojesVenta->add($relojesVentum);
  598.             $relojesVentum->setOperacionVenta($this);
  599.         }
  600.         return $this;
  601.     }
  602.     public function removeRelojesVentum(Reloj $relojesVentum): static
  603.     {
  604.         if ($this->relojesVenta->removeElement($relojesVentum)) {
  605.             // set the owning side to null (unless already changed)
  606.             if ($relojesVentum->getOperacionVenta() === $this) {
  607.                 $relojesVentum->setOperacionVenta(null);
  608.             }
  609.         }
  610.         return $this;
  611.     }
  612.     /**
  613.      * @return Collection<int, Reloj>
  614.      */
  615.     public function getRelojesCompra(): Collection
  616.     {
  617.         return $this->relojesCompra;
  618.     }
  619.     public function addRelojesCompra(Reloj $relojesCompra): static
  620.     {
  621.         if (!$this->relojesCompra->contains($relojesCompra)) {
  622.             $this->relojesCompra->add($relojesCompra);
  623.             $relojesCompra->setOperacionCompra($this);
  624.         }
  625.         return $this;
  626.     }
  627.     public function removeRelojesCompra(Reloj $relojesCompra): static
  628.     {
  629.         if ($this->relojesCompra->removeElement($relojesCompra)) {
  630.             // set the owning side to null (unless already changed)
  631.             if ($relojesCompra->getOperacionCompra() === $this) {
  632.                 $relojesCompra->setOperacionCompra(null);
  633.             }
  634.         }
  635.         return $this;
  636.     }
  637.     public function getFechaFinalizada(): ?\DateTimeInterface
  638.     {
  639.         return $this->fechaFinalizada;
  640.     }
  641.     public function setFechaFinalizada(?\DateTimeInterface $fechaFinalizada): static
  642.     {
  643.         $this->fechaFinalizada $fechaFinalizada;
  644.         return $this;
  645.     }
  646.     public function canBeProcessed(): ?bool
  647.     {
  648.         // Solo EN_TRAMITACION o CONFIRMADA
  649.         if (!in_array($this->getEstado()?->getKey(), [
  650.             EstadoOperacionEnum::ESTADO_EN_TRAMITACION,
  651.             EstadoOperacionEnum::ESTADO_CONFIRMADA
  652.         ])) {
  653.             return false;
  654.         }
  655.         // Si está CONFIRMADA y es tipo GESTION, no puede tramitarse
  656.         if ($this->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_CONFIRMADA
  657.             && $this->getTipo() === TipoOperacionEnum::OPERACION_GESTION
  658.         ) {
  659.             return false;
  660.         }
  661.         foreach ($this->getVenta()->getDetalle() as $detalle)
  662.         {
  663.             if(in_array($detalle->getReloj()->getEstado()?->getKey(), [ EstadoRelojEnum::ESTADO_GESTION_CANCELADA])) return false;
  664.         }
  665.         return $this->getFechaTramitada() ? true false;
  666.     }
  667.     public function canBeConfirmed(): ?bool
  668.     {
  669.         if ($this->isCompraGestion()) return true;
  670.         if (!$this->isProcessed())  return false;
  671.         foreach ($this->getVenta()->getDetalle() as $detalle)
  672.         {
  673.             if(!($detalle->getReloj()->isSend() && $detalle->getFechaEnvio())) return false;
  674.             if(in_array($detalle->getReloj()->getEstado()?->getKey(), [ EstadoRelojEnum::ESTADO_GESTION_CANCELADAEstadoRelojEnum::ESTADO_VENDIDO])) return false;
  675.         }
  676.         return $this->getFechaConfirmada() ? true false;
  677.     }
  678.     public function isCompraGestion(): ?bool
  679.     {
  680.         $detalles $this->getCompra()?->getDetalle();
  681.         if($this->getTipo() === TipoOperacionEnum::OPERACION_COMPRA &&
  682.             $detalles->count() === &&
  683.             $detalles->first()?->getReloj()?->getOperacionGestion())
  684.         {
  685.             return true;
  686.         }
  687.         return false;
  688.     }
  689.     public function isCancelled(): ?bool
  690.     {
  691.         return $this->getEstado()->getKey() === EstadoOperacionEnum::ESTADO_CANCELADA;
  692.     }
  693.     public function isProcessed(): ?bool
  694.     {
  695.         return $this->getEstado()->getKey() === EstadoOperacionEnum::ESTADO_TRAMITADA;
  696.     }
  697.     public function isConfirmed(): ?bool
  698.     {
  699.         return $this->getEstado()->getKey() === EstadoOperacionEnum::ESTADO_CONFIRMADA;
  700.     }
  701.     public function isSettled(): ?bool
  702.     {
  703.         return $this->getEstado()->getKey() === EstadoOperacionEnum::ESTADO_ASENTADA;
  704.     }
  705.     public function isFinalized(): ?bool
  706.     {
  707.         return $this->getEstado()->getKey() === EstadoOperacionEnum::ESTADO_FINALIZADA;
  708.     }
  709.     public function canSynchronizeStates(): ?bool
  710.     {
  711.         return $this->isConfirmed() || $this->isSettled() || $this->isFinalized();
  712.     }
  713.     public function hasRelojSold(): bool
  714.     {
  715.         $detalleCompra $this->getCompra()->getDetalle();
  716.         foreach ($detalleCompra as $detalle)
  717.         {
  718.             if($detalle->getReloj()?->isSold()) return true;
  719.         }
  720.         $detalleVenta $this->getVenta()->getDetalle();
  721.         foreach ($detalleVenta as $detalle)
  722.         {
  723.             if($detalle->getReloj()?->isSold()) return true;
  724.         }
  725.         return false;
  726.     }
  727. }