src/Entity/ClientOrder.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ClientOrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassClientOrderRepository::class)]
  9. class ClientOrder
  10. {
  11.     /**
  12.      * Commande non complète
  13.      */
  14.     const STATUS_DRAFT 'draft';
  15.     /**
  16.      * Commande créée, en attente d'être envoyé à Nielsen (nielsenOrder = 0)
  17.      */
  18.     const STATUS_TOSEND 'tosend';
  19.     /**
  20.      * Commande envoyée à Nielsen (nielsenOrder > 0)
  21.      */
  22.     const STATUS_SENT 'sent';
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     private ?int $id null;
  27.     #[ORM\ManyToOne(inversedBy'clientOrders')]
  28.     private ?Project $project null;
  29.     #[ORM\OneToMany(mappedBy'clientOrder'targetEntityOrderProduct::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  30.     private Collection $orderProducts;
  31.     // Legacy relationships - keep for backward compatibility but marked as deprecated
  32.     /** @deprecated Use orderProducts collection instead */
  33.     #[ORM\OneToOne(mappedBy'clientOrder'cascade: ['persist''remove'])]
  34.     private ?Cadre $cadre null;
  35.     /** @deprecated Use orderProducts collection instead */
  36.     #[ORM\OneToOne(mappedBy'clientOrder'cascade: ['persist''remove'])]
  37.     private ?PassePartout $passePartout null;
  38.     /** @deprecated Use orderProducts collection instead */
  39.     #[ORM\OneToOne(mappedBy'clientOrder'cascade: ['persist''remove'])]
  40.     private ?CaisseAmericaine $caisseAmericaine null;
  41.     /** @deprecated Use orderProducts collection instead */
  42.     #[ORM\OneToOne(mappedBy'clientOrder'cascade: ['persist''remove'])]
  43.     private ?Partial $partial null;
  44.     /** @deprecated Use orderProducts collection instead */
  45.     #[ORM\OneToOne(mappedBy'clientOrder'cascade: ['persist''remove'])]
  46.     private ?Sujet $sujet null;
  47.     #[ORM\Column(nullabletrue)]
  48.     private ?float $price null;
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  50.     private ?\DateTimeInterface $created null;
  51.     #[ORM\ManyToMany(targetEntityNielsenOrder::class, mappedBy'clientOrders')]
  52.     private Collection $nielsenOrders;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $save_link null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     private ?string $reference null;
  57.     #[ORM\Column(length255nullabletrue)]
  58.     private ?string $client_reference null;
  59.     #[ORM\Column(length255nullabletrue)]
  60.     private ?string $sellerName null;
  61.     #[ORM\Column(length255nullabletrue)]
  62.     private ?string $refToSend null;
  63.     #[ORM\ManyToOne(inversedBy'clientOrders'cascade: ["persist"])]
  64.     private ?Internaute $internaute null;
  65.     #[ORM\OneToMany(mappedBy'clientOrder'targetEntityMail::class)]
  66.     private Collection $mails;
  67.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  68.     private ?string $comment null;
  69.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  70.     private ?\DateTimeInterface $receivedByShopAt null;
  71.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  72.     private ?\DateTimeInterface $clientContactedAt null;
  73.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  74.     private ?\DateTimeInterface $productDeliveredToClientAt null;
  75.     #[ORM\OneToMany(mappedBy'clientOrder'targetEntityTinyUrl::class, cascade: ['persist''remove'])]
  76.     private Collection $tinyUrls;
  77.     #[ORM\Column(length255nullabletrue)]
  78.     private ?string $status null;
  79.     #[ORM\Column(nullabletrue)]
  80.     private ?float $priceNetRefToSend null;
  81.     #[ORM\Column(length255nullabletrue)]
  82.     private ?string $orderToken null;
  83.     #[ORM\Column(nullabletrue)]
  84.     private ?bool $isArchived null;
  85.     #[ORM\Column(nullabletrue)]
  86.     private ?\DateTimeImmutable $archivedAt null;
  87.     /**
  88.      * Temporary property to store variants, not persisted to database
  89.      */
  90.     public ?array $variants null;
  91.     public function __construct()
  92.     {
  93.         $this->nielsenOrders = new ArrayCollection();
  94.         $this->created = new \DateTimeImmutable();
  95.         $this->mails = new ArrayCollection();
  96.         $this->tinyUrls = new ArrayCollection();
  97.         $this->orderProducts = new ArrayCollection();
  98.         $this->isArchived false;
  99.     }
  100.     public function getAppConfig(): array
  101.     {
  102.         return ($this->getTinyUrls()->last() ?: null)
  103.             ?->getAppConfig()
  104.             ?? [];
  105.     }
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getProject(): ?Project
  111.     {
  112.         return $this->project;
  113.     }
  114.     public function getHauteur(): ?int
  115.     {
  116.         if ($this->orderProducts->count() > 0) {
  117.             $firstProduct $this->orderProducts->first();
  118.             if ($firstProduct instanceof Cadre || $firstProduct instanceof CaisseAmericaine) {
  119.                 return $firstProduct->getHauteur();
  120.             } elseif ($firstProduct instanceof PassePartout) {
  121.                 return $firstProduct->getHauteurExterieur();
  122.             }
  123.         }
  124.         
  125.         return $this->cadre?->getHauteur() ?? $this->caisseAmericaine?->getHauteur() ?? $this->passePartout?->getHauteurExterieur();
  126.     }
  127.     public function getLargeur(): ?int
  128.     {
  129.         if ($this->orderProducts->count() > 0) {
  130.             $firstProduct $this->orderProducts->first();
  131.             if ($firstProduct instanceof Cadre || $firstProduct instanceof CaisseAmericaine) {
  132.                 return $firstProduct->getLargeur();
  133.             } elseif ($firstProduct instanceof PassePartout) {
  134.                 return $firstProduct->getLargeurExterieur();
  135.             }
  136.         }
  137.         
  138.         return $this->cadre?->getLargeur() ?? $this->caisseAmericaine?->getLargeur() ?? $this->passePartout?->getLargeurExterieur();
  139.     }
  140.     public function setProject(?Project $project): static
  141.     {
  142.         $this->project $project;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, OrderProduct>
  147.      */
  148.     public function getOrderProducts(): Collection
  149.     {
  150.         return $this->orderProducts;
  151.     }
  152.     public function addOrderProduct(OrderProduct $orderProduct): static
  153.     {
  154.         if (!$this->orderProducts->contains($orderProduct)) {
  155.             $this->orderProducts->add($orderProduct);
  156.             $orderProduct->setClientOrder($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeOrderProduct(OrderProduct $orderProduct): static
  161.     {
  162.         if ($this->orderProducts->removeElement($orderProduct)) {
  163.             // set the owning side to null (unless already changed)
  164.             if ($orderProduct->getClientOrder() === $this) {
  165.                 $orderProduct->setClientOrder(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170.     public function isMultiItemOrder(): bool
  171.     {
  172.         return $this->orderProducts->count() > 1;
  173.     }
  174.     public function getCalculatedPrice(): float
  175.     {
  176.         $total 0;
  177.         foreach ($this->orderProducts as $product) {
  178.             $total += ($product->getPrice() ?? 0) * ($product->getQuantity() ?? 1);
  179.         }
  180.         return $total;
  181.     }
  182.     public function getCadres(): array
  183.     {
  184.         return array_values($this->orderProducts->filter(fn($product) => $product instanceof Cadre)->toArray());
  185.     }
  186.     public function getPassePartouts(): array
  187.     {
  188.         return array_values($this->orderProducts->filter(fn($product) => $product instanceof PassePartout)->toArray());
  189.     }
  190.     public function getCaisseAmericaines(): array
  191.     {
  192.         return array_values($this->orderProducts->filter(fn($product) => $product instanceof CaisseAmericaine)->toArray());
  193.     }
  194.     public function getSujets(): array
  195.     {
  196.         return array_values($this->orderProducts->filter(fn($product) => $product instanceof Sujet)->toArray());
  197.     }
  198.     public function getPartials(): array
  199.     {
  200.         return array_values($this->orderProducts->filter(fn($product) => $product instanceof Partial)->toArray());
  201.     }
  202.     public function getCadre(): ?Cadre
  203.     {
  204.         $cadres $this->getCadres();
  205.         if (!empty($cadres)) {
  206.             return $cadres[0];
  207.         }
  208.         
  209.         return $this->cadre;
  210.     }
  211.     public function setCadre(?Cadre $cadre): static
  212.     {
  213.         // unset the owning side of the relation if necessary
  214.         if ($cadre === null && $this->cadre !== null) {
  215.             $this->cadre->setClientOrder(null);
  216.         }
  217.         // set the owning side of the relation if necessary
  218.         if ($cadre !== null && $cadre->getClientOrder() !== $this) {
  219.             $cadre->setClientOrder($this);
  220.         }
  221.         $this->cadre $cadre;
  222.         return $this;
  223.     }
  224.     public function getPassePartout(): ?PassePartout
  225.     {
  226.         $pp $this->getPassePartouts();
  227.         if (!empty($pp)) {
  228.             return $pp[0];
  229.         }
  230.         
  231.         return $this->passePartout;
  232.     }
  233.     public function setPassePartout(?PassePartout $passePartout): static
  234.     {
  235.         // unset the owning side of the relation if necessary
  236.         if ($passePartout === null && $this->passePartout !== null) {
  237.             $this->passePartout->setClientOrder(null);
  238.         }
  239.         // set the owning side of the relation if necessary
  240.         if ($passePartout !== null && $passePartout->getClientOrder() !== $this) {
  241.             $passePartout->setClientOrder($this);
  242.         }
  243.         $this->passePartout $passePartout;
  244.         return $this;
  245.     }
  246.     public function getPrice(): ?float
  247.     {
  248.         return $this->price;
  249.     }
  250.     public function setPrice(?float $price): static
  251.     {
  252.         $this->price $price;
  253.         return $this;
  254.     }
  255.     public function getCreated(): ?\DateTimeInterface
  256.     {
  257.         return $this->created;
  258.     }
  259.     public function setCreated(\DateTimeInterface $created): static
  260.     {
  261.         $this->created $created;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, NielsenOrder>
  266.      */
  267.     public function getNielsenOrders(): Collection
  268.     {
  269.         return $this->nielsenOrders;
  270.     }
  271.     public function addNielsenOrder(NielsenOrder $nielsenOrder): static
  272.     {
  273.         if (!$this->nielsenOrders->contains($nielsenOrder)) {
  274.             $this->nielsenOrders->add($nielsenOrder);
  275.             $nielsenOrder->addClientOrder($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeNielsenOrder(NielsenOrder $nielsenOrder): static
  280.     {
  281.         if ($this->nielsenOrders->removeElement($nielsenOrder)) {
  282.             $nielsenOrder->removeClientOrder($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function getSujet(): ?Sujet
  287.     {
  288.         $sujets $this->getSujets();
  289.         if (!empty($sujets)) {
  290.             return $sujets[0];
  291.         }
  292.         
  293.         return $this->sujet;
  294.     }
  295.     public function setSujet(?Sujet $sujet): static
  296.     {
  297.         // unset the owning side of the relation if necessary
  298.         if ($sujet === null && $this->sujet !== null) {
  299.             $this->sujet->setClientOrder(null);
  300.         }
  301.         // set the owning side of the relation if necessary
  302.         if ($sujet !== null && $sujet->getClientOrder() !== $this) {
  303.             $sujet->setClientOrder($this);
  304.         }
  305.         $this->sujet $sujet;
  306.         return $this;
  307.     }
  308.     public function getSaveCode(): string
  309.     {
  310.         $explodedSaveLink explode("="$this->save_link ?? "");
  311.         return end($explodedSaveLink) ?? "";
  312.     }
  313.     public function getSaveLink(): ?string
  314.     {
  315.         return $this->save_link;
  316.     }
  317.     public function setSaveLink(?string $save_link): static
  318.     {
  319.         $this->save_link $save_link;
  320.         return $this;
  321.     }
  322.     public function getReference(): ?string
  323.     {
  324.         return $this->reference;
  325.     }
  326.     public function setReference(?string $reference): static
  327.     {
  328.         $this->reference $reference;
  329.         return $this;
  330.     }
  331.     public function getClientReference(): ?string
  332.     {
  333.         return $this->client_reference;
  334.     }
  335.     public function setClientReference(?string $client_reference): static
  336.     {
  337.         $this->client_reference $client_reference;
  338.         return $this;
  339.     }
  340.     public function getInternaute(): ?Internaute
  341.     {
  342.         return $this->internaute;
  343.     }
  344.     public function setInternaute(?Internaute $internaute): static
  345.     {
  346.         $this->internaute $internaute;
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection<int, Mail>
  351.      */
  352.     public function getMails(): Collection
  353.     {
  354.         return $this->mails;
  355.     }
  356.     public function addMail(Mail $mail): static
  357.     {
  358.         if (!$this->mails->contains($mail)) {
  359.             $this->mails->add($mail);
  360.             $mail->setClientOrder($this);
  361.         }
  362.         return $this;
  363.     }
  364.     public function removeMail(Mail $mail): static
  365.     {
  366.         if ($this->mails->removeElement($mail)) {
  367.             // set the owning side to null (unless already changed)
  368.             if ($mail->getClientOrder() === $this) {
  369.                 $mail->setClientOrder(null);
  370.             }
  371.         }
  372.         return $this;
  373.     }
  374.     public function getComment(): ?string
  375.     {
  376.         return $this->comment;
  377.     }
  378.     public function setComment(?string $comment): static
  379.     {
  380.         $this->comment $comment;
  381.         return $this;
  382.     }
  383.     public function getCaisseAmericaine(): ?CaisseAmericaine
  384.     {
  385.         $ca $this->getCaisseAmericaines();
  386.         if (!empty($ca)) {
  387.             return $ca[0];
  388.         }
  389.         
  390.         return $this->caisseAmericaine;
  391.     }
  392.     public function setCaisseAmericaine(?CaisseAmericaine $caisseAmericaine): static
  393.     {
  394.         // unset the owning side of the relation if necessary
  395.         if ($caisseAmericaine === null && $this->caisseAmericaine !== null) {
  396.             $this->caisseAmericaine->setClientOrder(null);
  397.         }
  398.         // set the owning side of the relation if necessary
  399.         if ($caisseAmericaine !== null && $caisseAmericaine->getClientOrder() !== $this) {
  400.             $caisseAmericaine->setClientOrder($this);
  401.         }
  402.         $this->caisseAmericaine $caisseAmericaine;
  403.         return $this;
  404.     }
  405.     public function getPartial(): ?Partial
  406.     {
  407.         $partials $this->getPartials();
  408.         if (!empty($partials)) {
  409.             return $partials[0];
  410.         }
  411.         
  412.         return $this->partial;
  413.     }
  414.     public function setPartial(?Partial $partial): static
  415.     {
  416.         // unset the owning side of the relation if necessary
  417.         if ($partial === null && $this->partial !== null) {
  418.             $this->partial->setClientOrder(null);
  419.         }
  420.         // set the owning side of the relation if necessary
  421.         if ($partial !== null && $partial->getClientOrder() !== $this) {
  422.             $partial->setClientOrder($this);
  423.         }
  424.         $this->partial $partial;
  425.         return $this;
  426.     }
  427.     public function getReceivedByShopAt(): ?\DateTimeInterface
  428.     {
  429.         return $this->receivedByShopAt;
  430.     }
  431.     public function setReceivedByShopAt(?\DateTimeInterface $receivedByShopAt): static
  432.     {
  433.         $this->receivedByShopAt $receivedByShopAt;
  434.         return $this;
  435.     }
  436.     public function getClientContactedAt(): ?\DateTimeInterface
  437.     {
  438.         return $this->clientContactedAt;
  439.     }
  440.     public function setClientContactedAt(?\DateTimeInterface $clientContactedAt): static
  441.     {
  442.         $this->clientContactedAt $clientContactedAt;
  443.         return $this;
  444.     }
  445.     public function getProductDeliveredToClientAt(): ?\DateTimeInterface
  446.     {
  447.         return $this->productDeliveredToClientAt;
  448.     }
  449.     public function setProductDeliveredToClientAt(?\DateTimeInterface $productDeliveredToClientAt): static
  450.     {
  451.         $this->productDeliveredToClientAt $productDeliveredToClientAt;
  452.         return $this;
  453.     }
  454.     public function getSellerName(): ?string
  455.     {
  456.         return $this->sellerName;
  457.     }
  458.     public function setSellerName(?string $sellerName): self
  459.     {
  460.         $this->sellerName $sellerName;
  461.         return $this;
  462.     }
  463.     /**
  464.      * @return Collection<int, TinyUrl>
  465.      */
  466.     public function getTinyUrls(): Collection
  467.     {
  468.         return $this->tinyUrls;
  469.     }
  470.     public function addTinyUrl(TinyUrl $tinyUrl): static
  471.     {
  472.         if (!$this->tinyUrls->contains($tinyUrl)) {
  473.             $this->tinyUrls->add($tinyUrl);
  474.             $tinyUrl->setClientOrder($this);
  475.         }
  476.         return $this;
  477.     }
  478.     public function removeTinyUrl(TinyUrl $tinyUrl): static
  479.     {
  480.         if ($this->tinyUrls->removeElement($tinyUrl)) {
  481.             // set the owning side to null (unless already changed)
  482.             if ($tinyUrl->getClientOrder() === $this) {
  483.                 $tinyUrl->setClientOrder(null);
  484.             }
  485.         }
  486.         return $this;
  487.     }
  488.     public function getRefToSend(): ?string
  489.     {
  490.         return $this->refToSend;
  491.     }
  492.     public function setRefToSend(?string $refToSend): self
  493.     {
  494.         $this->refToSend $refToSend;
  495.         return $this;
  496.     }
  497.     public function getStatus(): ?string
  498.     {
  499.         return $this->status;
  500.     }
  501.     public function setStatus(?string $status): static
  502.     {
  503.         $this->status $status;
  504.         return $this;
  505.     }
  506.     public function getPriceNetRefToSend(): ?float
  507.     {
  508.         return $this->priceNetRefToSend;
  509.     }
  510.     public function setPriceNetRefToSend(?float $priceNetRefToSend): static
  511.     {
  512.         $this->priceNetRefToSend $priceNetRefToSend;
  513.         return $this;
  514.     }
  515.     public function getOrderToken(): ?string
  516.     {
  517.         return $this->orderToken;
  518.     }
  519.     public function setOrderToken(?string $orderToken): static
  520.     {
  521.         $this->orderToken $orderToken;
  522.         return $this;
  523.     }
  524.     public function isIsArchived(): ?bool
  525.     {
  526.         return $this->isArchived;
  527.     }
  528.     public function setIsArchived(bool $isArchived): static
  529.     {
  530.         $this->isArchived $isArchived;
  531.         return $this;
  532.     }
  533.     public function getArchivedAt(): ?\DateTimeImmutable
  534.     {
  535.         return $this->archivedAt;
  536.     }
  537.     public function setArchivedAt(?\DateTimeImmutable $archivedAt): static
  538.     {
  539.         $this->archivedAt $archivedAt;
  540.         return $this;
  541.     }
  542.     public function getVariants(): ?array
  543.     {
  544.         return $this->variants;
  545.     }
  546.     public function setVariants(?array $variants): static
  547.     {
  548.         $this->variants $variants;
  549.         return $this;
  550.     }
  551. }