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