src/Entity/Product.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\EntityTime;
  4. use App\Repository\ProductRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassProductRepository::class)]
  11. class Product extends EntityTime
  12. {
  13.     #[Groups(['product:read'])]
  14.     #[ORM\Column(length255)]
  15.     private ?string $name null;
  16.     #[ORM\ManyToOne(inversedBy'products')]
  17.     #[ORM\JoinColumn(nullablefalse)]
  18.     private ?Category $category null;
  19.     #[ORM\ManyToOne(inversedBy'products')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?Range $range null;
  22.     #[ORM\ManyToOne(inversedBy'products')]
  23.     #[ORM\JoinColumn(nullablefalse)]
  24.     #[Groups(['product:read'])]
  25.     private ?Serie $serie null;
  26.     #[ORM\ManyToOne(inversedBy'products')]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private ?Provider $provider null;
  29.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  30.     private ?string $options null;
  31.     #[Groups(['product:read'])]
  32.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  33.     private ?string $description null;
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     private ?string $required null;
  36.     #[ORM\Column(length100nullabletrue)]
  37.     #[Groups(['product:read'])]
  38.     private ?string $referenceAFIMES null;
  39.     #[ORM\Column(nullabletrue)]
  40.     #[Groups(['product:read'])]
  41.     private ?int $providerSellingPrice null;
  42.     #[ORM\Column(nullabletrue)]
  43.     private ?int $providerDiscount null;
  44.     #[ORM\Column(nullabletrue)]
  45.     private ?int $recommendedMarginRate null;
  46.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  47.     private ?string $comment null;
  48.     #[ORM\Column(length20nullabletrue)]
  49.     private ?string $unit null;
  50.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  51.     private ?string $additionalOptions null;
  52.     #[Groups(['product:read'])]
  53.     private ?string $file;
  54.     #[ORM\OneToMany(mappedBy'product'targetEntityProductOption::class, orphanRemovaltrue)]
  55.     #[Groups(['product:read'])]
  56.     private Collection $productOptions;
  57.     #[ORM\Column(length255nullabletrue)]
  58.     private ?string $pricingLastUpdate null;
  59.     #[ORM\Column(nullabletrue)]
  60.     private ?int $documentId null;
  61.     public function __construct(
  62.         string $name null,
  63.         Category $category null,
  64.         Serie $serie null,
  65.         Range $range null,
  66.         Provider $provider null
  67.     ) {
  68.         parent::__construct();
  69.         $this->name $name;
  70.         $this->category $category;
  71.         $this->serie $serie;
  72.         $this->range $range;
  73.         $this->provider $provider;
  74.         $this->productOptions = new ArrayCollection();
  75.     }
  76.     public function getName(): ?string
  77.     {
  78.         return $this->name;
  79.     }
  80.     public function setName(string $name): self
  81.     {
  82.         $this->name $name;
  83.         return $this;
  84.     }
  85.     public function getCategory(): ?Category
  86.     {
  87.         return $this->category;
  88.     }
  89.     public function setCategory(?Category $category): self
  90.     {
  91.         $this->category $category;
  92.         return $this;
  93.     }
  94.     public function getRange(): ?Range
  95.     {
  96.         return $this->range;
  97.     }
  98.     public function setRange(?Range $range): self
  99.     {
  100.         $this->range $range;
  101.         return $this;
  102.     }
  103.     public function getSerie(): ?Serie
  104.     {
  105.         return $this->serie;
  106.     }
  107.     public function setSerie(?Serie $serie): self
  108.     {
  109.         $this->serie $serie;
  110.         return $this;
  111.     }
  112.     public function getProvider(): ?Provider
  113.     {
  114.         return $this->provider;
  115.     }
  116.     public function setProvider(?Provider $provider): self
  117.     {
  118.         $this->provider $provider;
  119.         return $this;
  120.     }
  121.     public function getOptions(): ?string
  122.     {
  123.         return $this->options;
  124.     }
  125.     public function setOptions(?string $options): self
  126.     {
  127.         $this->options $options;
  128.         return $this;
  129.     }
  130.     public function getDescription(): ?string
  131.     {
  132.         return $this->description;
  133.     }
  134.     public function setDescription(?string $description): self
  135.     {
  136.         $this->description $description;
  137.         return $this;
  138.     }
  139.     public function getRequired(): ?string
  140.     {
  141.         return $this->required;
  142.     }
  143.     public function setRequired(?string $required): self
  144.     {
  145.         $this->required $required;
  146.         return $this;
  147.     }
  148.     public function getReferenceAFIMES(): ?string
  149.     {
  150.         return $this->referenceAFIMES;
  151.     }
  152.     public function setReferenceAFIMES(?string $referenceAFIMES): self
  153.     {
  154.         $this->referenceAFIMES $referenceAFIMES;
  155.         return $this;
  156.     }
  157.     public function getProviderSellingPrice(): int
  158.     {
  159.         return intval($this->providerSellingPrice);
  160.     }
  161.     public function setProviderSellingPrice(int|string|null $providerSellingPrice): self
  162.     {
  163.         if (is_string($providerSellingPrice)) {
  164.             $providerSellingPrice trim($providerSellingPrice);
  165.             if (strtolower($providerSellingPrice) == 'offert') {
  166.                 $providerSellingPrice = -1;
  167.             } elseif (strtolower($providerSellingPrice) == 'sur devis') {
  168.                 $providerSellingPrice = -2;
  169.             } elseif (strtolower($providerSellingPrice) == 'x' || strtolower($providerSellingPrice) == '-') {
  170.                 $providerSellingPrice null;
  171.             } else {
  172.                 $providerSellingPrice str_replace('€'''$providerSellingPrice);
  173.                 $providerSellingPrice str_replace(' '''$providerSellingPrice);
  174.                 $providerSellingPrice str_replace(' '''$providerSellingPrice);
  175.                 $providerSellingPrice str_replace(',''.'$providerSellingPrice);
  176.                 $providerSellingPrice intval(floatval($providerSellingPrice) * 100);
  177.             }
  178.         }
  179.         $this->providerSellingPrice $providerSellingPrice;
  180.         return $this;
  181.     }
  182.     public function getProviderDiscount(): ?int
  183.     {
  184.         return $this->providerDiscount;
  185.     }
  186.     public function setProviderDiscount(int|string|null $providerDiscount): self
  187.     {
  188.         if (is_string($providerDiscount)) {
  189.             $providerDiscount str_replace('%'''$providerDiscount);
  190.             $providerDiscount str_replace(',''.'$providerDiscount);
  191.             $providerDiscount trim($providerDiscount);
  192.             $providerDiscount intval($providerDiscount);
  193.         }
  194.         $this->providerDiscount $providerDiscount;
  195.         return $this;
  196.     }
  197.     public function getRecommendedMarginRate(): ?int
  198.     {
  199.         return $this->recommendedMarginRate;
  200.     }
  201.     public function setRecommendedMarginRate(int|string|null $recommendedMarginRate): self
  202.     {
  203.         if (is_string($recommendedMarginRate)) {
  204.             $recommendedMarginRate str_replace('%'''$recommendedMarginRate);
  205.             $recommendedMarginRate str_replace(',''.'$recommendedMarginRate);
  206.             $recommendedMarginRate trim($recommendedMarginRate);
  207.             $recommendedMarginRate intval($recommendedMarginRate);
  208.         }
  209.         $this->recommendedMarginRate $recommendedMarginRate;
  210.         return $this;
  211.     }
  212.     public function getComment(): ?string
  213.     {
  214.         return $this->comment;
  215.     }
  216.     public function setComment(?string $comment): self
  217.     {
  218.         $this->comment $comment;
  219.         return $this;
  220.     }
  221.     public function getUnit(): ?string
  222.     {
  223.         return $this->unit;
  224.     }
  225.     public function setUnit(?string $unit): self
  226.     {
  227.         $this->unit $unit;
  228.         return $this;
  229.     }
  230.     public function getAdditionalOptions(): ?string
  231.     {
  232.         return $this->additionalOptions;
  233.     }
  234.     public function setAdditionalOptions(?string $additionalOptions): self
  235.     {
  236.         $this->additionalOptions $additionalOptions;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection<int, ProductOption>
  241.      */
  242.     public function getProductOptions(): Collection
  243.     {
  244.         return $this->productOptions;
  245.     }
  246.     public function addProductOption(ProductOption $productOption): self
  247.     {
  248.         if (!$this->productOptions->contains($productOption)) {
  249.             $this->productOptions->add($productOption);
  250.             $productOption->setProduct($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeProductOption(ProductOption $productOption): self
  255.     {
  256.         if ($this->productOptions->removeElement($productOption)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($productOption->getProduct() === $this) {
  259.                 $productOption->setProduct(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     public function getProductOptionByName(string $name): ProductOption|bool
  265.     {
  266.         return $this->productOptions
  267.             ->filter(fn (ProductOption $option) => $option->getName() == $name)
  268.             ->first();
  269.     }
  270.     public function setFile(?string $file): self
  271.     {
  272.         $this->file $file;
  273.         return $this;
  274.     }
  275.     public function getFile(): ?string
  276.     {
  277.         return $this->file;
  278.     }
  279.     public function getPricingLastUpdate(): ?string
  280.     {
  281.         return $this->pricingLastUpdate;
  282.     }
  283.     public function setPricingLastUpdate(?string $pricingLastUpdate): self
  284.     {
  285.         $this->pricingLastUpdate $pricingLastUpdate;
  286.         return $this;
  287.     }
  288.     public function getPrice(bool $discount true): int
  289.     {
  290.         if(!$discount) {
  291.             return $this->getProviderSellingPrice();
  292.         }
  293.         $buyPrice = ($this->getProviderSellingPrice() / 100) * (- ($this->getProviderDiscount()/100));
  294.         return  ceil(($buyPrice / (- ($this->getRecommendedMarginRate()/ 100))) / 10) * 10;
  295.     }
  296.     public function getFinalPrice(): float
  297.     {
  298.         $salePriceInitial ceil((($this->getProviderSellingPrice() / 100) / (- ($this->getRecommendedMarginRate()/ 100))) / 10) * 10;
  299.         return ($salePriceInitial * (+ ($this->getRecommendedMarginRate() / 100)));
  300.     }
  301.     public function getDocumentId(): ?int
  302.     {
  303.         return $this->documentId;
  304.     }
  305.     public function setDocumentId(?int $documentId): self
  306.     {
  307.         $this->documentId $documentId;
  308.         return $this;
  309.     }
  310.     public function getOptionValueByName(string $name): mixed
  311.     {
  312.         $option $this->getProductOptionByName($name);
  313.         return  $option $option->getValue() : null;
  314.     }
  315. }