src/Entity/Operacion.php line 38

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