src/Entity/Promocion.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\EstadoRelojEnum;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Uid\Uuid;
  15. /**
  16. * @ORM\Entity(repositoryClass="App\Repository\PromocionRepository")
  17. * @ORM\Table(name="promocion", schema="perseo")
  18. * @ORM\EntityListeners({"App\EntityListener\Promocion\CalcularIDPerseoListener"})
  19. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  20. * @Vich\Uploadable
  21. */
  22. class Promocion
  23. {
  24. /**
  25. * @ORM\Id
  26. * @ORM\Column(type="uuid", unique=true)
  27. * @ORM\GeneratedValue(strategy="CUSTOM")
  28. * @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
  29. */
  30. protected $id;
  31. /**
  32. * @ORM\Column(type="string", unique=true, nullable=false, name="id_perseo")
  33. */
  34. protected $IDperseo;
  35. /**
  36. * @ORM\Column(
  37. * type="string",
  38. * nullable=false,
  39. * options={"default":"COMPRA","comment":"valores a tomar (Compra, Gestión)"}
  40. * )
  41. */
  42. protected $tipo;
  43. /**
  44. * @ORM\Column(type="datetime", nullable=true, name="fecha_promocion", options={"comment":"La más antigua"})
  45. */
  46. protected $fechaPromocion;
  47. /**
  48. * @ORM\Column(type="datetime", nullable=true, name="fecha_listo", options={"comment":"La más antigua"})
  49. */
  50. protected $fechaListo;
  51. /**
  52. * @ORM\Column(type="datetime", nullable=true, name="fecha_venta")
  53. */
  54. protected $fechaVenta;
  55. /**
  56. * @ORM\Column(type="float", nullable=true, precision=2)
  57. */
  58. protected $precio;
  59. /**
  60. * @ORM\Column(type="float", nullable=true, precision=2)
  61. */
  62. protected $precioChrono24;
  63. /**
  64. * @ORM\Column(type="float", nullable=true, precision=2)
  65. */
  66. protected $margenBrutoEsperado;
  67. /**
  68. * @ORM\Column(type="float", nullable=true, precision=2)
  69. */
  70. protected $margenNetoEsperado;
  71. /**
  72. * @ORM\Column(type="float", nullable=true, precision=2, options={"comment":"% tiempo desde la compra"})
  73. */
  74. protected $tiempo;
  75. /**
  76. * @ORM\Column(type="text", length=16834, nullable=true, options={"comment":"formato html"})
  77. */
  78. protected $comentarioPublico;
  79. /**
  80. * @ORM\Column(type="text", length=256, nullable=true)
  81. */
  82. protected $comentarioPrivado;
  83. /**
  84. * @ORM\Column(type="text", nullable=true)
  85. */
  86. protected $descripcion;
  87. /**
  88. * @ORM\Column(type="string", nullable=true, name="ubicacion_actual", options={"comment":"Ubicación actual"})
  89. */
  90. protected $ubicacionActual;
  91. /**
  92. * @ORM\Column(type="datetime", nullable=true, name="fecha_ubicacion_actual")
  93. */
  94. protected $fechaUbicacionActual;
  95. /**
  96. * @ORM\Column(
  97. * type="datetime",
  98. * nullable=true,
  99. * name="fecha_anuncio",
  100. * options={"comment":"La fecha del primer anuncio"}
  101. * )
  102. */
  103. private $fechaAnuncio;
  104. /**
  105. * @ORM\Column(type="string", nullable=true, name="estado_actual")
  106. */
  107. protected $estadoActual;
  108. /**
  109. * @ORM\Column(type="datetime", nullable=true, name="fecha_estado_actual")
  110. */
  111. private $fechaEstadoActual;
  112. /**
  113. * @ORM\Column(type="json", nullable=true, options={"comment":"Servicio y Mejoras"})
  114. */
  115. protected $costes;
  116. /**
  117. * @ORM\Column(type="string", nullable=true, name="reloj_foto")
  118. */
  119. protected $relojFoto;
  120. /**
  121. * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto")
  122. * @var \Symfony\Component\HttpFoundation\File\File
  123. */
  124. protected $relojFotoFile;
  125. /**
  126. * @ORM\Column(type="string", nullable=true, name="reloj_foto_valoracion")
  127. */
  128. private $relojFotoValoracion;
  129. /**
  130. * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_valoracion")
  131. * @var File
  132. */
  133. protected $relojFotoValoracionFile;
  134. /**
  135. * @ORM\Column(type="string", nullable=true, name="reloj_foto_set")
  136. */
  137. private $relojFotoSet;
  138. /**
  139. * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_set")
  140. * @var File
  141. */
  142. protected $relojFotoSetFile;
  143. /**
  144. * @ORM\Column(type="string", nullable=true, name="reloj_foto_crono", options={"comment":"foto del cronocomparador"})
  145. */
  146. private $relojFotoCrono;
  147. /**
  148. * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_crono")
  149. * @var File
  150. */
  151. protected $relojFotoCronoFile;
  152. /**
  153. * @ORM\Column(type="string", nullable=true, name="reloj_video")
  154. */
  155. private $relojVideo;
  156. /**
  157. * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_video")
  158. * @var File
  159. */
  160. protected $relojVideoFile;
  161. /**
  162. * @ORM\Column(type="float", nullable=true, precision=2)
  163. */
  164. private $recompra;
  165. /**
  166. * @ORM\Column(type="string", nullable=true)
  167. */
  168. private $garantia;
  169. /**
  170. * @ORM\Column(
  171. * type="boolean",
  172. * nullable=true,
  173. * options={
  174. * "default":1,
  175. * "comment":"Utilizado cuando ya existe promoción y has deshecho parte de operación y hay que desactivar
  176. * promoción hasta que operación este en estado aceptada."
  177. * }
  178. * )
  179. */
  180. protected $active;
  181. /**
  182. * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  183. */
  184. protected $deletedAt;
  185. /**
  186. * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  187. * @Gedmo\Timestampable(on="update")
  188. */
  189. protected $updatedAt;
  190. /**
  191. * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  192. * @Gedmo\Timestampable(on="create")
  193. */
  194. protected $createdAt;
  195. /**
  196. * @ORM\JoinColumn(name="reloj_id", referencedColumnName="id", unique=true)
  197. * @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="promociones")
  198. */
  199. protected $reloj;
  200. /**
  201. * @ORM\OneToMany(targetEntity="App\Entity\AccionAbstract", mappedBy="promocion")
  202. */
  203. protected $acciones;
  204. public function __construct()
  205. {
  206. $this->acciones = new ArrayCollection();
  207. }
  208. public function __toString(): string
  209. {
  210. return $this->getIDperseo().'';
  211. }
  212. public function getId(): ?Uuid
  213. {
  214. return $this->id;
  215. }
  216. public function getFechaInicio(): ?DateTimeInterface
  217. {
  218. return $this->fechaInicio;
  219. }
  220. public function setFechaInicio(?DateTimeInterface $fechaInicio): self
  221. {
  222. $this->fechaInicio = $fechaInicio;
  223. return $this;
  224. }
  225. public function getFechaFin(): ?DateTimeInterface
  226. {
  227. return $this->fechaFin;
  228. }
  229. public function setFechaFin(?DateTimeInterface $fechaFin): self
  230. {
  231. $this->fechaFin = $fechaFin;
  232. return $this;
  233. }
  234. public function getPrecio(): ?float
  235. {
  236. return $this->precio;
  237. }
  238. public function setPrecio(?float $precio): self
  239. {
  240. $this->precio = $precio;
  241. return $this;
  242. }
  243. public function getDeletedAt(): ?DateTimeInterface
  244. {
  245. return $this->deletedAt;
  246. }
  247. public function setDeletedAt(?DateTimeInterface $deletedAt): self
  248. {
  249. $this->deletedAt = $deletedAt;
  250. return $this;
  251. }
  252. public function getUpdatedAt(): ?DateTimeInterface
  253. {
  254. return $this->updatedAt;
  255. }
  256. public function setUpdatedAt(DateTimeInterface $updatedAt): self
  257. {
  258. $this->updatedAt = $updatedAt;
  259. return $this;
  260. }
  261. public function getCreatedAt(): ?DateTimeInterface
  262. {
  263. return $this->createdAt;
  264. }
  265. public function setCreatedAt(DateTimeInterface $createdAt): self
  266. {
  267. $this->createdAt = $createdAt;
  268. return $this;
  269. }
  270. public function getCanal(): ?Canal
  271. {
  272. return $this->canal;
  273. }
  274. public function setCanal(?Canal $canal): self
  275. {
  276. $this->canal = $canal;
  277. return $this;
  278. }
  279. public function getFechaPromocion(): ?DateTimeInterface
  280. {
  281. return $this->fechaPromocion;
  282. }
  283. public function setFechaPromocion(?DateTimeInterface $fechaPromocion): self
  284. {
  285. $this->fechaPromocion = $fechaPromocion;
  286. return $this;
  287. }
  288. public function getMargenBrutoEsperado(): ?float
  289. {
  290. return $this->margenBrutoEsperado;
  291. }
  292. public function setMargenBrutoEsperado(?float $margenBrutoEsperado): self
  293. {
  294. $this->margenBrutoEsperado = $margenBrutoEsperado;
  295. return $this;
  296. }
  297. public function getMargenNetoEsperado(): ?float
  298. {
  299. return $this->margenNetoEsperado;
  300. }
  301. public function setMargenNetoEsperado(?float $margenNetoEsperado): self
  302. {
  303. $this->margenNetoEsperado = $margenNetoEsperado;
  304. return $this;
  305. }
  306. public function getTiempo(): ?float
  307. {
  308. return $this->tiempo;
  309. }
  310. public function setTiempo(?float $tiempo): self
  311. {
  312. $this->tiempo = $tiempo;
  313. return $this;
  314. }
  315. public function getComentarioPublico(): ?string
  316. {
  317. return $this->comentarioPublico;
  318. }
  319. public function setComentarioPublico(?string $comentarioPublico): self
  320. {
  321. $this->comentarioPublico = $comentarioPublico;
  322. return $this;
  323. }
  324. public function getComentarioPrivado(): ?string
  325. {
  326. return $this->comentarioPrivado;
  327. }
  328. public function setComentarioPrivado(?string $comentarioPrivado): self
  329. {
  330. $this->comentarioPrivado = $comentarioPrivado;
  331. return $this;
  332. }
  333. /**
  334. * @return Collection<int, AccionAbstract>
  335. */
  336. public function getAcciones(): Collection
  337. {
  338. return $this->acciones;
  339. }
  340. public function addAccione(AccionAbstract $accione): self
  341. {
  342. if (!$this->acciones->contains($accione)) {
  343. $this->acciones->add($accione);
  344. $accione->setPromocion($this);
  345. }
  346. return $this;
  347. }
  348. public function removeAccione(AccionAbstract $accione): self
  349. {
  350. if ($this->acciones->removeElement($accione)) {
  351. // set the owning side to null (unless already changed)
  352. if ($accione->getPromocion() === $this) {
  353. $accione->setPromocion(null);
  354. }
  355. }
  356. return $this;
  357. }
  358. public function getReloj(): ?Reloj
  359. {
  360. return $this->reloj;
  361. }
  362. public function setReloj(?Reloj $reloj): static
  363. {
  364. $this->reloj = $reloj;
  365. return $this;
  366. }
  367. public function getIDperseo(): ?string
  368. {
  369. return $this->IDperseo;
  370. }
  371. public function setIDperseo(?string $IDperseo): static
  372. {
  373. $this->IDperseo = $IDperseo;
  374. return $this;
  375. }
  376. public function getPrecioChrono24(): ?float
  377. {
  378. return $this->precioChrono24;
  379. }
  380. public function setPrecioChrono24(?float $precioChrono24): static
  381. {
  382. $this->precioChrono24 = $precioChrono24;
  383. return $this;
  384. }
  385. public function getDescripcion(): ?string
  386. {
  387. return $this->descripcion;
  388. }
  389. public function setDescripcion(?string $descripcion): static
  390. {
  391. $this->descripcion = $descripcion;
  392. return $this;
  393. }
  394. public function getUbicacionActual(): ?string
  395. {
  396. return $this->ubicacionActual;
  397. }
  398. public function setUbicacionActual(?string $ubicacionActual): static
  399. {
  400. $this->ubicacionActual = $ubicacionActual;
  401. return $this;
  402. }
  403. public function getEstadoActual(): ?string
  404. {
  405. $sort = new Criteria(null, ['fecha' => Criteria::DESC, 'createdAt' => Criteria::DESC]);
  406. $acciones = $this->getAcciones()->matching($sort);
  407. foreach ($acciones as $accion)
  408. {
  409. if(!$accion instanceof AccionServicio && !$accion instanceof AccionMejora && !$accion instanceof AccionCompetencia) break;
  410. }
  411. $checked = @$accion instanceof AccionCheck && $accion->getEstado() !== null;
  412. return $checked ? '---' : $this->estadoActual;
  413. }
  414. public function setEstadoActual(?string $estadoActual): static
  415. {
  416. $this->estadoActual = $estadoActual;
  417. return $this;
  418. }
  419. public function getCostes(): ?array
  420. {
  421. return $this->costes;
  422. }
  423. public function setCostes(?array $costes): static
  424. {
  425. $this->costes = $costes;
  426. return $this;
  427. }
  428. public function getUbicacion(): string
  429. {
  430. return '---';
  431. }
  432. public function getTipo(): ?string
  433. {
  434. return $this->tipo;
  435. }
  436. public function setTipo(string $tipo): static
  437. {
  438. $this->tipo = $tipo;
  439. return $this;
  440. }
  441. public function getFechaListo(): ?DateTimeInterface
  442. {
  443. return $this->fechaListo;
  444. }
  445. public function setFechaListo(?DateTimeInterface $fechaListo): static
  446. {
  447. $this->fechaListo = $fechaListo;
  448. return $this;
  449. }
  450. public function getFechaVenta(): ?DateTimeInterface
  451. {
  452. return $this->fechaVenta;
  453. }
  454. public function setFechaVenta(?DateTimeInterface $fechaVenta): static
  455. {
  456. $this->fechaVenta = $fechaVenta;
  457. return $this;
  458. }
  459. public function getRelojFoto(): ?string
  460. {
  461. return $this->relojFoto;
  462. }
  463. public function setRelojFoto(?string $relojFoto): static
  464. {
  465. $this->relojFoto = $relojFoto;
  466. return $this;
  467. }
  468. public function getRelojFotoFile(): ?File
  469. {
  470. return $this->relojFotoFile;
  471. }
  472. public function setRelojFotoFile(?File $relojFotoFile): static
  473. {
  474. $this->relojFotoFile = $relojFotoFile;
  475. if($relojFotoFile)
  476. {
  477. $this->setUpdatedAt(new DateTime('now'));
  478. }
  479. return $this;
  480. }
  481. public function getRelojFotoValoracion(): ?string
  482. {
  483. return $this->relojFotoValoracion;
  484. }
  485. public function setRelojFotoValoracion(?string $relojFotoValoracion): static
  486. {
  487. $this->relojFotoValoracion = $relojFotoValoracion;
  488. return $this;
  489. }
  490. public function getRelojFotoValoracionFile(): ?File
  491. {
  492. return $this->relojFotoValoracionFile;
  493. }
  494. public function setRelojFotoValoracionFile(?File $relojFotoValoracionFile): static
  495. {
  496. $this->relojFotoValoracionFile = $relojFotoValoracionFile;
  497. if($relojFotoValoracionFile)
  498. {
  499. $this->setUpdatedAt(new DateTime('now'));
  500. }
  501. return $this;
  502. }
  503. public function getRelojFotoSet(): ?string
  504. {
  505. return $this->relojFotoSet;
  506. }
  507. public function setRelojFotoSet(?string $relojFotoSet): static
  508. {
  509. $this->relojFotoSet = $relojFotoSet;
  510. return $this;
  511. }
  512. public function getRelojFotoSetFile(): ?File
  513. {
  514. return $this->relojFotoSetFile;
  515. }
  516. public function setRelojFotoSetFile(?File $relojFotoSetFile): static
  517. {
  518. $this->relojFotoSetFile = $relojFotoSetFile;
  519. if($relojFotoSetFile)
  520. {
  521. $this->setUpdatedAt(new DateTime('now'));
  522. }
  523. return $this;
  524. }
  525. public function getRelojFotoCrono(): ?string
  526. {
  527. return $this->relojFotoCrono;
  528. }
  529. public function setRelojFotoCrono(?string $relojFotoCrono): static
  530. {
  531. $this->relojFotoCrono = $relojFotoCrono;
  532. return $this;
  533. }
  534. public function getRelojFotoCronoFile(): ?File
  535. {
  536. return $this->relojFotoCronoFile;
  537. }
  538. public function setRelojFotoCronoFile(?File $relojFotoCronoFile): static
  539. {
  540. $this->relojFotoCronoFile = $relojFotoCronoFile;
  541. if($relojFotoCronoFile)
  542. {
  543. $this->setUpdatedAt(new DateTime('now'));
  544. }
  545. return $this;
  546. }
  547. public function getRelojVideo(): ?string
  548. {
  549. return $this->relojVideo;
  550. }
  551. public function setRelojVideo(?string $relojVideo): static
  552. {
  553. $this->relojVideo = $relojVideo;
  554. return $this;
  555. }
  556. public function getRelojVideoFile(): ?File
  557. {
  558. return $this->relojVideoFile;
  559. }
  560. public function setRelojVideoFile(?File $relojVideoFile): static
  561. {
  562. $this->relojVideoFile = $relojVideoFile;
  563. if($relojVideoFile)
  564. {
  565. $this->setUpdatedAt(new DateTime('now'));
  566. }
  567. return $this;
  568. }
  569. public function isActive(): ?bool
  570. {
  571. return $this->active;
  572. }
  573. public function setActive(?bool $active): static
  574. {
  575. $this->active = $active;
  576. return $this;
  577. }
  578. public function getRecompra(): ?float
  579. {
  580. return $this->recompra;
  581. }
  582. public function setRecompra(?float $recompra): static
  583. {
  584. $this->recompra = $recompra;
  585. return $this;
  586. }
  587. public function getGarantia(): ?string
  588. {
  589. return $this->garantia;
  590. }
  591. public function setGarantia(?string $garantia): static
  592. {
  593. $this->garantia = $garantia;
  594. return $this;
  595. }
  596. public function getExportFechaPromocion(): ?string
  597. {
  598. return $this->getFechaPromocion()?->format('d/m/Y');
  599. }
  600. public function diasEnVenta(): ?string
  601. {
  602. $now = new DateTime();
  603. return $this->getFechaPromocion() ? ($this->getFechaVenta() ? $this->getFechaPromocion()->diff($this->getFechaVenta())->format('%a') : $this->getFechaPromocion()->diff($now)->format('%a')) : null;
  604. }
  605. public function fechaEstadoCompraStr(): ?string
  606. {
  607. return $this->fechaEstadoCompra()?->format('d/m/Y');
  608. }
  609. public function fechaEstadoCompra(): ?DateTimeInterface
  610. {
  611. $estado = $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_COMPRA )->first();
  612. return $estado ? $estado->getFecha() : null;
  613. }
  614. public function fechaEstadoRecepcionStr(): ?string
  615. {
  616. return $this->fechaEstadoRecepcion()?->format('d/m/Y');
  617. }
  618. public function fechaEstadoRecepcion(): ?DateTimeInterface
  619. {
  620. $estado = $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_RECEPCION )->first();
  621. return $estado ? $estado->getFecha() : null;
  622. }
  623. public function getFechaUbicacionActual(): ?DateTimeInterface
  624. {
  625. return $this->fechaUbicacionActual;
  626. }
  627. public function setFechaUbicacionActual(?DateTimeInterface $fechaUbicacionActual): static
  628. {
  629. $this->fechaUbicacionActual = $fechaUbicacionActual;
  630. return $this;
  631. }
  632. public function getFechaAnuncio(): ?\DateTimeInterface
  633. {
  634. return $this->fechaAnuncio;
  635. }
  636. public function setFechaAnuncio(?\DateTimeInterface $fechaAnuncio): static
  637. {
  638. $this->fechaAnuncio = $fechaAnuncio;
  639. return $this;
  640. }
  641. public function getFechaEstadoActual(): ?\DateTimeInterface
  642. {
  643. return $this->fechaEstadoActual;
  644. }
  645. public function setFechaEstadoActual(?\DateTimeInterface $fechaEstadoActual): static
  646. {
  647. $this->fechaEstadoActual = $fechaEstadoActual;
  648. return $this;
  649. }
  650. }