src/Entity/Suppliers.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SuppliersRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Warehouse;
  8. use phpDocumentor\Reflection\Types\This;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. /**
  12.  * ORM\Entity(repositoryClass=SuppliersRepository::class)
  13.  * ORM\Table(
  14.  *       name="suppliers",
  15.  *       uniqueConstraints={
  16.  *           ORM\UniqueConstraint(columns={"company", "location_id"}),
  17.  *       },
  18.  *  )
  19.  * UniqueEntity(
  20.  *       fields={"alias", "company", "location_id"},
  21.  *       message="Supplier already registered|Supplier with combination (%s %s) is already registered"
  22.  *  )
  23.  */
  24. /**
  25.  * @ORM\Entity(repositoryClass=SuppliersRepository::class)
  26.  * @ORM\Table(
  27.  *       name="suppliers",
  28.  *       uniqueConstraints={
  29.  *           @ORM\UniqueConstraint(columns={"company", "location_id"}),
  30.  *       },
  31.  *  )
  32.  * @UniqueEntity(
  33.  *       fields={"alias", "company", "location"},
  34.  *       message="Supplier already registered|Supplier with combination (%s %s) is already registered"
  35.  *  )
  36.  */
  37. class Suppliers
  38. {
  39.     /**
  40.      * @ORM\Id
  41.      * @ORM\GeneratedValue
  42.      * @ORM\Column(type="integer")
  43.      * @Groups({
  44.      *          "project.details.orders",
  45.      *          "order.detail",
  46.      *          "supplier.base",
  47.      *          "material.base",
  48.      *
  49.      *          "project.orders.expense.minify.list.version",
  50.      *
  51.      *     "supplier.core",
  52.      *     "supplier:core",
  53.      *
  54.      *     "supplier@core",
  55.      *     "supplier@base"
  56.      *
  57.      * })
  58.      */
  59.     private $id;
  60.     /**
  61.      * @deprecated use company
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      * @Groups({
  64.      *          "project.details.orders",
  65.      *          "order.detail",
  66.      *          "supplier.base",
  67.      *          "material.base",
  68.      *
  69.      *     "supplier.core", "supplier:core", "supplier@core", "supplier@base"
  70.      *     })
  71.      */
  72.     private $name;
  73.     /**
  74.      * @ORM\Column(type="string", length=64, nullable=true)
  75.      * @Groups({
  76.      *           "supplier.base",
  77.      *
  78.      *     "supplier.core", "supplier:core", "supplier@core"
  79.      *      })
  80.      */
  81.     private $city;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=ProjectOrderExtraCosts::class, mappedBy="supplier")
  84.      */
  85.     private $projectOrderExtraCosts;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity=Material::class, mappedBy="supplier")
  88.      * @Groups({"supplier@materials"})
  89.      */
  90.     private $materials;
  91.     /**
  92.      * @ORM\OneToMany(targetEntity=SupplierOrders::class, mappedBy="supplier")
  93.      */
  94.     private $supplierOrders;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity=ProjectOrderExpenses::class, mappedBy="supplier", orphanRemoval=true)
  97.      */
  98.     private $projectOrderExpenses;
  99.     /**
  100.      * @ORM\Column(type="string", length=64, nullable=true)
  101.      * @Groups({
  102.      *     "supplier.base",
  103.      *     "supplier.expenses",
  104.      *
  105.      *     "supplier@core"
  106.      * })
  107.      */
  108.     private $alias;
  109.     /**
  110.      * @ORM\Column(type="string", length=64, nullable=true)
  111.      * @Groups({
  112.      *     "supplier.base",
  113.      *     "project.orders.expense.minify.version",
  114.      *     "supplier.core", "supplier:core",
  115.      *
  116.      *     "supplier@core",
  117.      *     "supplier@base"
  118.      * })
  119.      */
  120.     private $company;
  121.     /**
  122.      * @ORM\Column(type="string", length=255, nullable=true)
  123.      * @Groups({
  124.      *     "supplier.base",
  125.      *     "project.orders.expense.minify.list.version",
  126.      *     "supplier.core", "supplier:core",
  127.      *
  128.      *     "supplier@core"
  129.      *  })
  130.      */
  131.     private $terms_to_payment;
  132.     /**
  133.      * @deprecated use Location
  134.      * @ORM\OneToMany(targetEntity=Addresses::class, mappedBy="supplier")
  135.      * @Groups({
  136.      *     "supplier.base",
  137.      *     "supplier.address",
  138.      *
  139.      *     "supplier@address"
  140.      * })
  141.      */
  142.     private $addresses;
  143.     /**
  144.      * TODO Bu Location yada Address ???
  145.      * @ORM\ManyToOne(targetEntity=Addresses::class, inversedBy="suppliers")
  146.      * @Groups({
  147.      *     "supplier.base",
  148.      *     "supplier.core", "supplier:core", "supplier@core"
  149.      * })
  150.      * @ORM\JoinColumn(onDelete="SET NULL")
  151.      */
  152.     private $address;
  153.     /**
  154.      * @ORM\Column(type="string", length=64, nullable=true)
  155.      * @Groups({
  156.      *     "supplier.base",
  157.      *     "supplier.core", "supplier:core", "supplier@core"
  158.      * })
  159.      */
  160.     private $tax;
  161.     /**
  162.      * @ORM\Column(type="string", length=255, nullable=true)
  163.      * @Groups({
  164.      *     "supplier.base",
  165.      *     "supplier.core", "supplier:core", "supplier@core"
  166.      * })
  167.      */
  168.     private $email;
  169.     /**
  170.      * @ORM\OneToMany(targetEntity=Stocks::class, mappedBy="supplier")
  171.      */
  172.     private $stocks;
  173.     /**
  174.      * @ORM\OneToMany(targetEntity=SupplierProducts::class, mappedBy="supplier")
  175.      * @Groups({
  176.      *     "supplier.products",
  177.      *     "supplier@products"
  178.      *  })
  179.      */
  180.     private $supplier_products;
  181.     /**
  182.      * @ORM\ManyToOne(targetEntity=Locations::class, inversedBy="suppliers")
  183.      * @Groups({
  184.      *     "supplier@location"
  185.      * })
  186.      */
  187.     private $location;
  188.     /**
  189.      * @ORM\OneToMany(targetEntity=SupplierEducation::class, mappedBy="supplier", orphanRemoval=true)
  190.      * @Groups({
  191.      *      "supplier@educations"
  192.      *  })
  193.      */
  194.     private $supplier_educations;
  195.     /**
  196.      * @ORM\Column(type="text", nullable=true)
  197.      * @Groups({
  198.      *     "supplier.core", "supplier:core", "supplier@core"
  199.      * })
  200.      */
  201.     private $order_confirmation_content;
  202.     /**
  203.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=true)
  204.      * @Groups({"supplier@core"})
  205.      */
  206.     private $monthly_limit;
  207.     /**
  208.      * Learned AI extraction hints — see App\Service\SupplierAIHintsService for lifecycle rules
  209.      * (learning → probation → stable → deprecated). Each entry is an array with:
  210.      *   id, prompt, added_at, from_document, status, usage_count, success_count,
  211.      *   consecutive_success, consecutive_fail, last_used_at, last_verified_at
  212.      *
  213.      * @ORM\Column(type="json", nullable=true)
  214.      * @Groups({"supplier@core"})
  215.      */
  216.     private $documents_prompts;
  217.     /**
  218.      * @ORM\OneToMany(targetEntity=SupplierContactPersons::class, mappedBy="supplier", orphanRemoval=true, cascade={"persist", "remove"})
  219.      * @Groups({
  220.      *     "supplier@contact_persons"
  221.      * })
  222.      */
  223.     private $supplier_contact_persons;
  224.     public function __construct()
  225.     {
  226.         $this->projectOrderExtraCosts = new ArrayCollection();
  227.         $this->materials = new ArrayCollection();
  228.         $this->supplierOrders = new ArrayCollection();
  229.         $this->projectOrderExpenses = new ArrayCollection();
  230.         $this->addresses = new ArrayCollection();
  231.         $this->stocks = new ArrayCollection();
  232.         $this->supplier_products = new ArrayCollection();
  233.         $this->supplier_educations = new ArrayCollection();
  234.         $this->supplier_contact_persons = new ArrayCollection();
  235.     }
  236.     public function getId(): ?int
  237.     {
  238.         return $this->id;
  239.     }
  240.     public function getName(): ?string
  241.     {
  242.         return $this->name;
  243.     }
  244.     public function setName(?string $name): self
  245.     {
  246.         $this->name $name;
  247.         return $this;
  248.     }
  249.     public function getCity(): ?string
  250.     {
  251.         return $this->city;
  252.     }
  253.     public function setCity(?string $city): self
  254.     {
  255.         $this->city $city;
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection<int, ProjectOrderExtraCosts>
  260.      */
  261.     public function getProjectOrderExtraCosts(): Collection
  262.     {
  263.         return $this->projectOrderExtraCosts;
  264.     }
  265.     public function addProjectOrderExtraCost(ProjectOrderExtraCosts $projectOrderExtraCost): self
  266.     {
  267.         if (!$this->projectOrderExtraCosts->contains($projectOrderExtraCost)) {
  268.             $this->projectOrderExtraCosts[] = $projectOrderExtraCost;
  269.             $projectOrderExtraCost->setSupplier($this);
  270.         }
  271.         return $this;
  272.     }
  273.     public function removeProjectOrderExtraCost(ProjectOrderExtraCosts $projectOrderExtraCost): self
  274.     {
  275.         if ($this->projectOrderExtraCosts->removeElement($projectOrderExtraCost)) {
  276.             // set the owning side to null (unless already changed)
  277.             if ($projectOrderExtraCost->getSupplier() === $this) {
  278.                 $projectOrderExtraCost->setSupplier(null);
  279.             }
  280.         }
  281.         return $this;
  282.     }
  283.     /**
  284.      * @return Collection<int, Material>
  285.      */
  286.     public function getMaterials(): Collection
  287.     {
  288.         return $this->materials;
  289.     }
  290.     public function addMaterial(Material $material): self
  291.     {
  292.         if (!$this->materials->contains($material)) {
  293.             $this->materials[] = $material;
  294.             $material->setSupplier($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function removeMaterial(Material $material): self
  299.     {
  300.         if ($this->materials->removeElement($material)) {
  301.             // set the owning side to null (unless already changed)
  302.             if ($material->getSupplier() === $this) {
  303.                 $material->setSupplier(null);
  304.             }
  305.         }
  306.         return $this;
  307.     }
  308.     /**
  309.      * @return Collection<int, SupplierOrders>
  310.      */
  311.     public function getSupplierOrders(): Collection
  312.     {
  313.         return $this->supplierOrders;
  314.     }
  315.     public function addSupplierOrder(SupplierOrders $supplierOrder): self
  316.     {
  317.         if (!$this->supplierOrders->contains($supplierOrder)) {
  318.             $this->supplierOrders[] = $supplierOrder;
  319.             $supplierOrder->setSupplier($this);
  320.         }
  321.         return $this;
  322.     }
  323.     public function removeSupplierOrder(SupplierOrders $supplierOrder): self
  324.     {
  325.         if ($this->supplierOrders->removeElement($supplierOrder)) {
  326.             // set the owning side to null (unless already changed)
  327.             if ($supplierOrder->getSupplier() === $this) {
  328.                 $supplierOrder->setSupplier(null);
  329.             }
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return Collection<int, ProjectOrderExpenses>
  335.      */
  336.     public function getProjectOrderExpenses(): Collection
  337.     {
  338.         return $this->projectOrderExpenses;
  339.     }
  340.     public function addProjectOrderExpense(ProjectOrderExpenses $projectOrderExpense): self
  341.     {
  342.         if (!$this->projectOrderExpenses->contains($projectOrderExpense)) {
  343.             $this->projectOrderExpenses[] = $projectOrderExpense;
  344.             $projectOrderExpense->setSupplier($this);
  345.         }
  346.         return $this;
  347.     }
  348.     public function removeProjectOrderExpense(ProjectOrderExpenses $projectOrderExpense): self
  349.     {
  350.         if ($this->projectOrderExpenses->removeElement($projectOrderExpense)) {
  351.             // set the owning side to null (unless already changed)
  352.             if ($projectOrderExpense->getSupplier() === $this) {
  353.                 $projectOrderExpense->setSupplier(null);
  354.             }
  355.         }
  356.         return $this;
  357.     }
  358.     public function getAlias(): ?string
  359.     {
  360.         return $this->alias;
  361.     }
  362.     public function setAlias(?string $alias): self
  363.     {
  364.         $this->alias $alias;
  365.         return $this;
  366.     }
  367.     public function getCompany(): ?string
  368.     {
  369.         return $this->company;
  370.     }
  371.     public function setCompany(?string $company): self
  372.     {
  373.         $this->company $company;
  374.         return $this;
  375.     }
  376.     public function getTermsToPayment(): ?string
  377.     {
  378.         return $this->terms_to_payment;
  379.     }
  380.     public function setTermsToPayment(?string $terms_to_payment): self
  381.     {
  382.         $this->terms_to_payment $terms_to_payment;
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return Collection<int, Addresses>
  387.      */
  388.     public function getAddresses(): Collection
  389.     {
  390.         return $this->addresses;
  391.     }
  392.     /**
  393.      * @deprecated use Location
  394.     */
  395.     public function addAdress(Addresses $adress): self
  396.     {
  397.         if (!$this->addresses->contains($adress)) {
  398.             $this->addresses[] = $adress;
  399.             $adress->setSupplier($this);
  400.         }
  401.         return $this;
  402.     }
  403.     /**
  404.      * @deprecated use Location
  405.      */
  406.     public function removeAdress(Addresses $adress): self
  407.     {
  408.         if ($this->addresses->removeElement($adress)) {
  409.             // set the owning side to null (unless already changed)
  410.             if ($adress->getSupplier() === $this) {
  411.                 $adress->setSupplier(null);
  412.             }
  413.         }
  414.         return $this;
  415.     }
  416.     public function getAddress(): ?Addresses
  417.     {
  418.         return $this->address;
  419.     }
  420.     public function setAddress(?Addresses $address): self
  421.     {
  422.         $this->address $address;
  423.         return $this;
  424.     }
  425.     public function getTax(): ?string
  426.     {
  427.         return $this->tax;
  428.     }
  429.     public function setTax(?string $tax): self
  430.     {
  431.         $this->tax $tax;
  432.         return $this;
  433.     }
  434.     public function getEmail(): ?string
  435.     {
  436.         return $this->email;
  437.     }
  438.     public function setEmail(?string $email): self
  439.     {
  440.         $this->email $email;
  441.         return $this;
  442.     }
  443.     public function getMonthlyLimit(): ?float
  444.     {
  445.         return $this->monthly_limit !== null ? (float)$this->monthly_limit null;
  446.     }
  447.     public function setMonthlyLimit(?float $monthly_limit): self
  448.     {
  449.         $this->monthly_limit $monthly_limit;
  450.         return $this;
  451.     }
  452.     /**
  453.      * Learned AI extraction hints. Never null on read — returns empty array
  454.      * when the column is unset so callers can iterate safely.
  455.      *
  456.      * @return array<int, array<string, mixed>>
  457.      */
  458.     public function getDocumentsPrompts(): array
  459.     {
  460.         return is_array($this->documents_prompts) ? $this->documents_prompts : [];
  461.     }
  462.     /**
  463.      * @param array<int, array<string, mixed>>|null $documents_prompts
  464.      */
  465.     public function setDocumentsPrompts(?array $documents_prompts): self
  466.     {
  467.         $this->documents_prompts $documents_prompts;
  468.         return $this;
  469.     }
  470.     /**
  471.      * @return Collection<int, Stocks>
  472.      */
  473.     public function getStocks(): Collection
  474.     {
  475.         return $this->stocks;
  476.     }
  477.     public function addStock(Stocks $stock): self
  478.     {
  479.         if (!$this->stocks->contains($stock)) {
  480.             $this->stocks[] = $stock;
  481.             $stock->setSupplier($this);
  482.         }
  483.         return $this;
  484.     }
  485.     public function removeStock(Stocks $stock): self
  486.     {
  487.         if ($this->stocks->removeElement($stock)) {
  488.             // set the owning side to null (unless already changed)
  489.             if ($stock->getSupplier() === $this) {
  490.                 $stock->setSupplier(null);
  491.             }
  492.         }
  493.         return $this;
  494.     }
  495.     /**
  496.      * @return Collection<int, SupplierProducts>
  497.      */
  498.     public function getSupplierProducts(): Collection
  499.     {
  500.         return $this->supplier_products;
  501.     }
  502.     public function addSupplierProduct(SupplierProducts $supplierProduct): self
  503.     {
  504.         if (!$this->supplier_products->contains($supplierProduct)) {
  505.             $this->supplier_products[] = $supplierProduct;
  506.             $supplierProduct->setSupplier($this);
  507.         }
  508.         return $this;
  509.     }
  510.     public function removeSupplierProduct(SupplierProducts $supplierProduct): self
  511.     {
  512.         if ($this->supplier_products->removeElement($supplierProduct)) {
  513.             // set the owning side to null (unless already changed)
  514.             if ($supplierProduct->getSupplier() === $this) {
  515.                 $supplierProduct->setSupplier(null);
  516.             }
  517.         }
  518.         return $this;
  519.     }
  520.     public function getLocation(): ?Locations
  521.     {
  522.         return $this->location;
  523.     }
  524.     public function setLocation(?Locations $location): self
  525.     {
  526.         $this->location $location;
  527.         return $this;
  528.     }
  529.     /**
  530.      * @return Collection<int, SupplierEducation>
  531.      */
  532.     public function getSupplierEducations(): Collection
  533.     {
  534.         return $this->supplier_educations;
  535.     }
  536.     public function addSupplierAiEducation(SupplierEducation $supplierAiEducation): self
  537.     {
  538.         if (!$this->supplier_educations->contains($supplierAiEducation)) {
  539.             $this->supplier_educations[] = $supplierAiEducation;
  540.             $supplierAiEducation->setSupplier($this);
  541.         }
  542.         return $this;
  543.     }
  544.     public function removeSupplierAiEducation(SupplierEducation $supplierAiEducation): self
  545.     {
  546.         if ($this->supplier_educations->removeElement($supplierAiEducation)) {
  547.             // set the owning side to null (unless already changed)
  548.             if ($supplierAiEducation->getSupplier() === $this) {
  549.                 $supplierAiEducation->setSupplier(null);
  550.             }
  551.         }
  552.         return $this;
  553.     }
  554.     /**
  555.      * @return Collection<int, SupplierContactPersons>
  556.      */
  557.     public function getSupplierContactPersons(): Collection
  558.     {
  559.         return $this->supplier_contact_persons;
  560.     }
  561.     public function addSupplierContactPerson(SupplierContactPersons $supplierContactPerson): self
  562.     {
  563.         if (!$this->supplier_contact_persons->contains($supplierContactPerson)) {
  564.             $this->supplier_contact_persons[] = $supplierContactPerson;
  565.             $supplierContactPerson->setSupplier($this);
  566.         }
  567.         return $this;
  568.     }
  569.     public function removeSupplierContactPerson(SupplierContactPersons $supplierContactPerson): self
  570.     {
  571.         if ($this->supplier_contact_persons->removeElement($supplierContactPerson)) {
  572.             if ($supplierContactPerson->getSupplier() === $this) {
  573.                 $supplierContactPerson->setSupplier(null);
  574.             }
  575.         }
  576.         return $this;
  577.     }
  578.     public function getOrderConfirmationContent(): ?string
  579.     {
  580.         return $this->order_confirmation_content;
  581.     }
  582.     public function setOrderConfirmationContent(?string $order_confirmation_content): self
  583.     {
  584.         $this->order_confirmation_content $order_confirmation_content;
  585.         return $this;
  586.     }
  587. }