src/Entity/OnlineShop/Supplier.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Entity\OnlineShop;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\AbstractBase;
  5. use App\Entity\Interfaces\PublishedInterface;
  6. use App\Entity\Interfaces\SiteInterface;
  7. use App\Entity\MiniAbstractBase;
  8. use App\Entity\Traits\HasImageTrait;
  9. use App\Entity\Traits\PhoneTrait;
  10. use App\Entity\Traits\PublishedTrait;
  11. use App\Entity\Traits\SiteTrait;
  12. use App\Entity\User;
  13. use App\Enum\DocumentTypeEnum;
  14. use App\Enum\MinOrderTypeEnum;
  15. use App\Enum\NotInMinOrderTypeEnum;
  16. use App\Enum\ShipmentTypeEnum;
  17. use App\Repository\OnlineShop\SupplierRepository;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Gedmo\Mapping\Annotation as Gedmo;
  22. use Money\Money;
  23. use Symfony\Component\HttpFoundation\File\File;
  24. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  25. /**
  26.  * @ORM\Table(name="vulco_supplier", indexes={@ORM\Index(name="supplier_site_idx", columns={"site"})})
  27.  *
  28.  * @ORM\Entity(repositoryClass=SupplierRepository::class)
  29.  *
  30.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  31.  *
  32.  * @SiteAware(siteFieldName="site")
  33.  *
  34.  * @Vich\Uploadable
  35.  */
  36. class Supplier extends AbstractBase implements SiteInterfacePublishedInterface
  37. {
  38.     use HasImageTrait;
  39.     use PhoneTrait;
  40.     use PublishedTrait;
  41.     use SiteTrait;
  42.     /**
  43.      * @ORM\Column(type="string", length=255)
  44.      */
  45.     private string $legalName;
  46.     /**
  47.      * @ORM\Column(type="string", length=255)
  48.      */
  49.     private string $commercialName;
  50.     /**
  51.      * @ORM\Column(type="text", length=10000)
  52.      */
  53.     private string $address;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     private ?string $fax null;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      */
  61.     private ?string $website null;
  62.     /**
  63.      * @ORM\Column(type="string", length=255, nullable=true)
  64.      */
  65.     private ?string $contactPerson null;
  66.     /**
  67.      * @ORM\Column(type="string", length=255, nullable=true)
  68.      */
  69.     private ?string $contactEmail null;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      */
  73.     private ?string $orderEmail null;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      */
  77.     private ?string $orderCcEmail null;
  78.     /**
  79.      * @ORM\Column(type="text", length=10000, nullable=true)
  80.      */
  81.     private ?string $imageUrl null;
  82.     /**
  83.      * @ORM\Column(type="string", length=255, nullable=true)
  84.      */
  85.     private ?string $deliveryTime null;
  86.     /**
  87.      * @ORM\Column(type="integer")
  88.      */
  89.     private int $shipmentType;
  90.     /**
  91.      * @ORM\Column(type="money")
  92.      */
  93.     private Money $fixedShipmentCost;
  94.     /**
  95.      * @ORM\Column(type="integer")
  96.      */
  97.     private int $fixedShipmentMinOrder;
  98.     /**
  99.      * @ORM\Column(type="integer")
  100.      */
  101.     private int $fixedShipmentMinOrderType;
  102.     /**
  103.      * @ORM\Column(type="integer")
  104.      */
  105.     private int $fixedShipmentToDoNotInMinOrderType;
  106.     /**
  107.      * @ORM\Column(type="integer")
  108.      */
  109.     private int $scaleShipmentMinPointsToBlockOrder;
  110.     /**
  111.      * @ORM\Column(type="integer")
  112.      */
  113.     private int $scaleShipmentMinPointsToFreeShipment;
  114.     /**
  115.      * @ORM\Column(type="string", length=255, nullable=true)
  116.      */
  117.     private ?string $imageName null;
  118.     /**
  119.      * @ORM\OneToMany(targetEntity="App\Entity\OnlineShop\ScaleShippingCost", mappedBy="supplier", cascade={"persist", "remove"}, orphanRemoval=true)
  120.      *
  121.      * @ORM\OrderBy({"points": "ASC"})
  122.      */
  123.     private ?Collection $scaleShippingCosts;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\OnlineShop\SupplierDocument", mappedBy="supplier", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER")
  126.      *
  127.      * @ORM\OrderBy({"createdAt": "DESC"})
  128.      */
  129.     private ?Collection $documents;
  130.     /**
  131.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="suppliers")
  132.      *
  133.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id"))
  134.      */
  135.     private ?User $user null;
  136.     /**
  137.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  138.      */
  139.     private bool $rappelCentralVulco true;
  140.     /**
  141.      * @ORM\Column(type="decimal", precision=10, scale=2)
  142.      */
  143.     private $rappelPercentage;
  144.     /**
  145.      * @ORM\Column(type="text", length=10000, nullable=true)
  146.      */
  147.     private ?string $rappelText null;
  148.     /**
  149.      * @Vich\UploadableField(mapping="supplier_image", fileNameProperty="imageName")
  150.      */
  151.     private ?File $image null;
  152.     /**
  153.      * @ORM\ManyToMany(targetEntity="App\Entity\OnlineShop\SupplierCategory")
  154.      *
  155.      * @ORM\JoinTable(name="vulco_supplier_supplier_category",
  156.      *     joinColumns={@ORM\JoinColumn(name="supplier_id", referencedColumnName="id")},
  157.      *     inverseJoinColumns={@ORM\JoinColumn(name="supplier_category_id", referencedColumnName="id")}
  158.      * )
  159.      */
  160.     private ?Collection $categories;
  161.     public function __construct()
  162.     {
  163.         $this->scaleShippingCosts = new ArrayCollection();
  164.         $this->categories = new ArrayCollection();
  165.         $this->documents = new ArrayCollection();
  166.     }
  167.     public function getLegalName(): string
  168.     {
  169.         return $this->legalName;
  170.     }
  171.     public function setLegalName(string $legalName): self
  172.     {
  173.         $this->legalName $legalName;
  174.         return $this;
  175.     }
  176.     public function getCommercialName(): string
  177.     {
  178.         return $this->commercialName;
  179.     }
  180.     public function setCommercialName(string $commercialName): self
  181.     {
  182.         $this->commercialName $commercialName;
  183.         return $this;
  184.     }
  185.     public function getAddress(): string
  186.     {
  187.         return $this->address;
  188.     }
  189.     public function setAddress(string $address): self
  190.     {
  191.         $this->address $address;
  192.         return $this;
  193.     }
  194.     public function getFax(): ?string
  195.     {
  196.         return $this->fax;
  197.     }
  198.     public function setFax(?string $fax): self
  199.     {
  200.         $this->fax $fax;
  201.         return $this;
  202.     }
  203.     public function getWebsite(): ?string
  204.     {
  205.         return $this->website;
  206.     }
  207.     public function setWebsite(?string $website): self
  208.     {
  209.         $this->website $website;
  210.         return $this;
  211.     }
  212.     public function getContactPerson(): ?string
  213.     {
  214.         return $this->contactPerson;
  215.     }
  216.     public function setContactPerson(?string $contactPerson): self
  217.     {
  218.         $this->contactPerson $contactPerson;
  219.         return $this;
  220.     }
  221.     public function getContactEmail(): ?string
  222.     {
  223.         return $this->contactEmail;
  224.     }
  225.     public function setContactEmail(?string $contactEmail): self
  226.     {
  227.         $this->contactEmail $contactEmail;
  228.         return $this;
  229.     }
  230.     public function getOrderEmail(): ?string
  231.     {
  232.         return $this->orderEmail;
  233.     }
  234.     public function setOrderEmail(?string $orderEmail): self
  235.     {
  236.         $this->orderEmail $orderEmail;
  237.         return $this;
  238.     }
  239.     public function getOrderCcEmail(): ?string
  240.     {
  241.         return $this->orderCcEmail;
  242.     }
  243.     public function setOrderCcEmail(?string $orderCcEmail): self
  244.     {
  245.         $this->orderCcEmail $orderCcEmail;
  246.         return $this;
  247.     }
  248.     public function getImageUrl(): ?string
  249.     {
  250.         return $this->imageUrl;
  251.     }
  252.     public function setImageUrl(?string $imageUrl): self
  253.     {
  254.         $this->imageUrl $imageUrl;
  255.         return $this;
  256.     }
  257.     public function getDeliveryTime(): ?string
  258.     {
  259.         return $this->deliveryTime;
  260.     }
  261.     public function setDeliveryTime(?string $deliveryTime): self
  262.     {
  263.         $this->deliveryTime $deliveryTime;
  264.         return $this;
  265.     }
  266.     public function getShipmentType(): int
  267.     {
  268.         return $this->shipmentType;
  269.     }
  270.     public function getShipmentTypeAsString(): string
  271.     {
  272.         return ShipmentTypeEnum::getReversedTranslations()[$this->getShipmentType()];
  273.     }
  274.     public function setShipmentType(int $shipmentType): self
  275.     {
  276.         $this->shipmentType $shipmentType;
  277.         return $this;
  278.     }
  279.     public function getFixedShipmentCost(): Money
  280.     {
  281.         return $this->fixedShipmentCost;
  282.     }
  283.     public function setFixedShipmentCost(Money $fixedShipmentCost): self
  284.     {
  285.         $this->fixedShipmentCost $fixedShipmentCost;
  286.         return $this;
  287.     }
  288.     public function getFixedShipmentMinOrder(): int
  289.     {
  290.         return $this->fixedShipmentMinOrder;
  291.     }
  292.     public function setFixedShipmentMinOrder(int $fixedShipmentMinOrder): self
  293.     {
  294.         $this->fixedShipmentMinOrder $fixedShipmentMinOrder;
  295.         return $this;
  296.     }
  297.     public function getFixedShipmentMinOrderType(): int
  298.     {
  299.         return $this->fixedShipmentMinOrderType;
  300.     }
  301.     public function getFixedShipmentMinOrderTypeAsString(): string
  302.     {
  303.         return MinOrderTypeEnum::getReversedTranslations()[$this->getFixedShipmentMinOrderType()];
  304.     }
  305.     public function setFixedShipmentMinOrderType(int $fixedShipmentMinOrderType): self
  306.     {
  307.         $this->fixedShipmentMinOrderType $fixedShipmentMinOrderType;
  308.         return $this;
  309.     }
  310.     public function getFixedShipmentToDoNotInMinOrderType(): int
  311.     {
  312.         return $this->fixedShipmentToDoNotInMinOrderType;
  313.     }
  314.     public function getFixedShipmentToDoNotInMinOrderTypeAsString(): string
  315.     {
  316.         return NotInMinOrderTypeEnum::getReversedTranslations()[$this->getFixedShipmentToDoNotInMinOrderType()];
  317.     }
  318.     public function setFixedShipmentToDoNotInMinOrderType(int $fixedShipmentToDoNotInMinOrderType): self
  319.     {
  320.         $this->fixedShipmentToDoNotInMinOrderType $fixedShipmentToDoNotInMinOrderType;
  321.         return $this;
  322.     }
  323.     public function getScaleShipmentMinPointsToBlockOrder(): int
  324.     {
  325.         return $this->scaleShipmentMinPointsToBlockOrder;
  326.     }
  327.     public function setScaleShipmentMinPointsToBlockOrder(int $scaleShipmentMinPointsToBlockOrder): self
  328.     {
  329.         $this->scaleShipmentMinPointsToBlockOrder $scaleShipmentMinPointsToBlockOrder;
  330.         return $this;
  331.     }
  332.     public function getScaleShipmentMinPointsToFreeShipment(): int
  333.     {
  334.         return $this->scaleShipmentMinPointsToFreeShipment;
  335.     }
  336.     public function setScaleShipmentMinPointsToFreeShipment(int $scaleShipmentMinPointsToFreeShipment): self
  337.     {
  338.         $this->scaleShipmentMinPointsToFreeShipment $scaleShipmentMinPointsToFreeShipment;
  339.         return $this;
  340.     }
  341.     public function getScaleShippingCosts(): ?Collection
  342.     {
  343.         return $this->scaleShippingCosts;
  344.     }
  345.     public function setScaleShippingCosts(?Collection $scaleShippingCosts): self
  346.     {
  347.         $this->scaleShippingCosts $scaleShippingCosts;
  348.         return $this;
  349.     }
  350.     public function addScaleShippingCost(ScaleShippingCost $scaleShippingCost): self
  351.     {
  352.         if (!$this->scaleShippingCosts->contains($scaleShippingCost)) {
  353.             $scaleShippingCost->setSupplier($this);
  354.             $this->scaleShippingCosts->add($scaleShippingCost);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeScaleShippingCost(ScaleShippingCost $scaleShippingCost): self
  359.     {
  360.         if ($this->scaleShippingCosts->contains($scaleShippingCost)) {
  361.             $this->scaleShippingCosts->removeElement($scaleShippingCost);
  362.         }
  363.         return $this;
  364.     }
  365.     public function getDocuments(): ?Collection
  366.     {
  367.         return $this->documents;
  368.     }
  369.     public function setDocuments(?Collection $documents): self
  370.     {
  371.         $this->documents $documents;
  372.         return $this;
  373.     }
  374.     public function addDocument(SupplierDocument $document): self
  375.     {
  376.         if (!$this->documents->contains($document)) {
  377.             $document->setSupplier($this);
  378.             $this->documents->add($document);
  379.         }
  380.         return $this;
  381.     }
  382.     public function addPromotionDocument(SupplierDocument $document): self
  383.     {
  384.         return $this->addDocument($document);
  385.     }
  386.     public function addConditionRateDocument(SupplierDocument $document): self
  387.     {
  388.         return $this->addDocument($document);
  389.     }
  390.     public function addWarrantyDocument(SupplierDocument $document): self
  391.     {
  392.         return $this->addDocument($document);
  393.     }
  394.     public function addRateDocument(SupplierDocument $document): self
  395.     {
  396.         return $this->addDocument($document);
  397.     }
  398.     public function addCatalogDocument(SupplierDocument $document): self
  399.     {
  400.         return $this->addDocument($document);
  401.     }
  402.     public function removeDocument(SupplierDocument $document): self
  403.     {
  404.         if ($this->documents->contains($document)) {
  405.             $this->documents->removeElement($document);
  406.         }
  407.         return $this;
  408.     }
  409.     public function removePromotionDocument(SupplierDocument $document): self
  410.     {
  411.         return $this->removeDocument($document);
  412.     }
  413.     public function removeConditionRateDocument(SupplierDocument $document): self
  414.     {
  415.         return $this->removeDocument($document);
  416.     }
  417.     public function removeWarrantyDocument(SupplierDocument $document): self
  418.     {
  419.         return $this->removeDocument($document);
  420.     }
  421.     public function removeRateDocument(SupplierDocument $document): self
  422.     {
  423.         return $this->removeDocument($document);
  424.     }
  425.     public function removeCatalogDocument(SupplierDocument $document): self
  426.     {
  427.         return $this->removeDocument($document);
  428.     }
  429.     public function getCategories(): ?Collection
  430.     {
  431.         return $this->categories;
  432.     }
  433.     public function setCategories(?Collection $categories): self
  434.     {
  435.         $this->categories $categories;
  436.         return $this;
  437.     }
  438.     public function addCategorie(SupplierCategory $category): self
  439.     {
  440.         if (!$this->categories->contains($category)) {
  441.             $this->categories->add($category);
  442.         }
  443.         return $this;
  444.     }
  445.     public function removeCategorie(SupplierCategory $category): self
  446.     {
  447.         if ($this->categories->contains($category)) {
  448.             $this->categories->removeElement($category);
  449.         }
  450.         return $this;
  451.     }
  452.     public function getUser(): ?User
  453.     {
  454.         return $this->user;
  455.     }
  456.     public function setRappelCentralVulco(bool $rappelCentralVulco): self
  457.     {
  458.         $this->rappelCentralVulco $rappelCentralVulco;
  459.         return $this;
  460.     }
  461.     public function isRappelCentralVulco(): bool
  462.     {
  463.         return $this->rappelCentralVulco;
  464.     }
  465.     public function isRappelDirectSupplier(): bool
  466.     {
  467.         return !$this->isRappelCentralVulco();
  468.     }
  469.     public function getRappelPercentage(): float
  470.     {
  471.         return $this->rappelPercentage;
  472.     }
  473.     public function setRappelPercentage(float $rappelPercentage): self
  474.     {
  475.         $this->rappelPercentage $rappelPercentage;
  476.         return $this;
  477.     }
  478.     public function getRappelText(): ?string
  479.     {
  480.         return $this->rappelText;
  481.     }
  482.     public function setRappelText(?string $rappelText): self
  483.     {
  484.         $this->rappelText $rappelText;
  485.         return $this;
  486.     }
  487.     public function setFeatured(bool $featured): self
  488.     {
  489.         $this->featured $featured;
  490.         return $this;
  491.     }
  492.     public function getPromotionDocuments(): Collection
  493.     {
  494.         return $this->filterDocumentsByType(DocumentTypeEnum::PROMOTION);
  495.     }
  496.     public function getPromotionDocumentsEnabled(): Collection
  497.     {
  498.         return $this->filterDocumentsByType(DocumentTypeEnum::PROMOTIONtrue);
  499.     }
  500.     public function getConditionRateDocuments(): Collection
  501.     {
  502.         return $this->filterDocumentsByType(DocumentTypeEnum::CONDITION_RATE);
  503.     }
  504.     public function getConditionRateDocumentsEnabled(): Collection
  505.     {
  506.         return $this->filterDocumentsByType(DocumentTypeEnum::CONDITION_RATEtrue);
  507.     }
  508.     public function getWarrantyDocuments(): Collection
  509.     {
  510.         return $this->filterDocumentsByType(DocumentTypeEnum::WARRANTY);
  511.     }
  512.     public function getWarrantyDocumentsEnabled(): Collection
  513.     {
  514.         return $this->filterDocumentsByType(DocumentTypeEnum::WARRANTYtrue);
  515.     }
  516.     public function getRateDocuments(): Collection
  517.     {
  518.         return $this->filterDocumentsByType(DocumentTypeEnum::RATE);
  519.     }
  520.     public function getRateDocumentsEnabled(): Collection
  521.     {
  522.         return $this->filterDocumentsByType(DocumentTypeEnum::RATEtrue);
  523.     }
  524.     public function getRateDocumentsEnabledAndCurrentDate(): Collection
  525.     {
  526.         $result = new ArrayCollection();
  527.         $enabledSupplierDocuments $this->filterDocumentsByType(DocumentTypeEnum::RATEtrue);
  528.         $today = (new \DateTimeImmutable())->format(MiniAbstractBase::DEFAULT_DATE_DATABASE_FORMAT);
  529.         /** @var SupplierDocument $document */
  530.         foreach ($enabledSupplierDocuments as $document) {
  531.             if ($document->getStartDate() && $document->getEndDate() && $today >= $document->getStartDate()->format(MiniAbstractBase::DEFAULT_DATE_DATABASE_FORMAT) && $today <= $document->getEndDate()->format(MiniAbstractBase::DEFAULT_DATE_DATABASE_FORMAT)) {
  532.                 $result->add($document);
  533.             } elseif ($document->getStartDate() && !$document->getEndDate() && $today >= $document->getStartDate()->format(MiniAbstractBase::DEFAULT_DATE_DATABASE_FORMAT)) {
  534.                 $result->add($document);
  535.             } elseif (!$document->getStartDate() && $document->getEndDate() && $today <= $document->getEndDate()->format(MiniAbstractBase::DEFAULT_DATE_DATABASE_FORMAT)) {
  536.                 $result->add($document);
  537.             }
  538.         }
  539.         return $result;
  540.     }
  541.     public function getCatalogDocuments(): Collection
  542.     {
  543.         return $this->filterDocumentsByType(DocumentTypeEnum::CATALOG);
  544.     }
  545.     public function getCatalogDocumentsEnabled(): Collection
  546.     {
  547.         return $this->filterDocumentsByType(DocumentTypeEnum::CATALOGtrue);
  548.     }
  549.     protected function filterDocumentsByType(int $typebool $enabled false): Collection
  550.     {
  551.         $result = new ArrayCollection();
  552.         /** @var SupplierDocument $document */
  553.         foreach ($this->documents as $document) {
  554.             if ($type === $document->getDocumentType()) {
  555.                 if ($enabled) {
  556.                     if ($document->isEnabled()) {
  557.                         $result->add($document);
  558.                     }
  559.                 } else {
  560.                     $result->add($document);
  561.                 }
  562.             }
  563.         }
  564.         return $result;
  565.     }
  566.     public function __toString(): string
  567.     {
  568.         return $this->commercialName $this->getCommercialName() : MiniAbstractBase::DEFAULT_EMPTY_STRING;
  569.     }
  570. }