src/Entity/Purchasing/LineItem.php line 38

  1. <?php
  2. namespace App\Entity\Purchasing;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Doctrine\Type\Purchasing\LineItemStatus;
  6. use App\Entity\Common as Common;
  7. use App\Entity\Common\Company;
  8. use App\Entity\Expediting\Item;
  9. use App\Entity\Inventory\InventoryItem;
  10. use App\Entity\Sales\Asset;
  11. use App\Validator\IsValidEnum\IsValidEnum;
  12. use DateTimeInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\DBAL\Types\Types;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. use Symfony\Component\Uid\Ulid;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. #[ORM\Table(name'purchasing_line_item')]
  22. #[ORM\Index(columns: ['order_id'], name'purchasing_line_item_order_id_idx')]
  23. #[ORM\Index(columns: ['customer_id'], name'purchasing_line_item_customer_id_idx')]
  24. #[ORM\Index(columns: ['supplier_id'], name'purchasing_line_item_supplier_id_idx')]
  25. #[ORM\Index(columns: ['asset_id'], name'purchasing_line_item_asset_id_idx')]
  26. #[ORM\Index(columns: ['flow_id'], name'purchasing_line_item_flow_id_idx')]
  27. #[ORM\Index(columns: ['created_by'], name'purchasing_line_item_created_by_idx')]
  28. #[ORM\Index(columns: ['updated_by'], name'purchasing_line_item_updated_by_idx')]
  29. #[ORM\UniqueConstraint(name'purchasing_line_item_identifier_key'columns: ['identifier'])]
  30. #[ORM\UniqueConstraint(name'purchasing_line_item_order_id_number_key'columns: ['order_id''number'])]
  31. #[ORM\UniqueConstraint(name'purchasing_line_item_slug_key'columns: ['slug'])]
  32. #[ORM\Entity]
  33. #[UniqueEntity(fields: ['order''number'])]
  34. #[ApiResource(routePrefix'/purchasing')]
  35. class LineItem
  36. {
  37.     use Common\Blameable;
  38.     use Common\Trackable;
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  41.     #[ORM\SequenceGenerator(sequenceName'purchasing_line_item_id_seq')]
  42.     #[ORM\Column(typeTypes::INTEGER)]
  43.     #[ApiProperty(identifierfalse)]
  44.     private ?int $id null;
  45.     #[Assert\Ulid]
  46.     #[Assert\NotNull]
  47.     #[ORM\Column(type'ulid'uniquetrue)]
  48.     private ?Ulid $identifier null;
  49.     #[Gedmo\Slug(fields: ['number'])]
  50.     #[ORM\Column(typeTypes::STRING)]
  51.     #[ApiProperty(identifiertrue)]
  52.     private ?string $slug null;
  53.     #[Assert\NotNull]
  54.     #[ORM\ManyToOne(targetEntityOrder::class, inversedBy'lineItems')]
  55.     #[ORM\JoinColumn(name'order_id'nullablefalse)]
  56.     private ?Order $order null;
  57.     /** @var Collection<int, Item> */
  58.     #[ORM\OneToMany(mappedBy'lineItem'targetEntityItem::class, cascade: ['persist''remove'])]
  59.     private Collection $items;
  60.     /** @var Collection<int, InventoryItem> */
  61.     #[ORM\OneToMany(mappedBy'lineItem'targetEntityInventoryItem::class)]
  62.     private Collection $inventoriedItems;
  63.     #[Assert\NotNull]
  64.     #[ORM\ManyToOne(targetEntityCompany::class)]
  65.     #[ORM\JoinColumn(name'customer_id')]
  66.     private ?Company $customer null;
  67.     #[Assert\NotNull]
  68.     #[ORM\ManyToOne(targetEntityCompany::class)]
  69.     #[ORM\JoinColumn(name'supplier_id')]
  70.     private ?Company $supplier null;
  71.     #[ORM\ManyToOne(targetEntityAsset::class)]
  72.     #[ORM\JoinColumn(name'asset_id')]
  73.     private ?Asset $asset null;
  74.     #[ORM\ManyToOne(targetEntityFlow::class)]
  75.     #[ORM\JoinColumn(name'flow_id')]
  76.     private ?Flow $flow null;
  77.     #[Assert\NotBlank]
  78.     #[Assert\Type(typeTypes::STRING)]
  79.     #[ORM\Column(typeTypes::STRING)]
  80.     private ?string $number null;
  81.     #[Assert\Type(typeTypes::STRING)]
  82.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  83.     private ?string $materialNumber;
  84.     #[Assert\Type(typeTypes::STRING)]
  85.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  86.     private ?string $materialGroup;
  87.     #[Assert\Type(typeTypes::STRING)]
  88.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  89.     private ?string $supplierPartNumber null;
  90.     #[Assert\Type(typeTypes::STRING)]
  91.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  92.     private ?string $supplierDescription null;
  93.     #[Assert\Type(typeTypes::STRING)]
  94.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  95.     private ?string $customerDescription null;
  96.     #[Assert\Type(typeTypes::INTEGER)]
  97.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  98.     private ?int $quantity null;
  99.     #[Assert\Type(typeTypes::STRING)]
  100.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  101.     private ?string $hsCode null;
  102.     #[Assert\Type(typeTypes::STRING)]
  103.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  104.     private ?string $countryOfOrigin null;
  105.     #[Assert\Type(typeTypes::FLOAT)]
  106.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  107.     private ?float $unitPrice null;
  108.     #[Assert\Type(typeTypes::FLOAT)]
  109.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  110.     private ?float $value null;
  111.     #[Assert\Length(exactly3)]
  112.     #[Assert\Type(typeTypes::STRING)]
  113.     #[ORM\Column(typeTypes::STRINGlength3nullabletrue)]
  114.     private ?string $currency null;
  115.     #[Assert\Type(typeTypes::DATE_MUTABLE)]
  116.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  117.     private ?DateTimeInterface $availableOn null;
  118.     #[Assert\NotNull]
  119.     #[IsValidEnum(enumLineItemStatus::class)]
  120.     #[ORM\Column(typeTypes::STRINGenumTypeLineItemStatus::class, options: ['default' => 'ORDERED'])]
  121.     private ?LineItemStatus $status LineItemStatus::ORDERED;
  122.     public function __construct()
  123.     {
  124.         $this->identifier = new Ulid();
  125.         $this->items = new ArrayCollection();
  126.         $this->inventoriedItems = new ArrayCollection();
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getIdentifier(): ?Ulid
  133.     {
  134.         return $this->identifier;
  135.     }
  136.     public function setIdentifier(Ulid $identifier): self
  137.     {
  138.         $this->identifier $identifier;
  139.         return $this;
  140.     }
  141.     public function getSlug(): ?string
  142.     {
  143.         return $this->slug;
  144.     }
  145.     public function setSlug(string $slug): self
  146.     {
  147.         $this->slug $slug;
  148.         return $this;
  149.     }
  150.     public function getOrder(): ?Order
  151.     {
  152.         return $this->order;
  153.     }
  154.     public function setOrder(?Order $order): self
  155.     {
  156.         $this->order $order;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, Item>
  161.      */
  162.     public function getItems(): Collection
  163.     {
  164.         return $this->items;
  165.     }
  166.     public function addItem(Item $item): self
  167.     {
  168.         if (!$this->items->contains($item)) {
  169.             $this->items[] = $item;
  170.             $item->setLineItem($this);
  171.         }
  172.         return $this;
  173.     }
  174.     public function removeItem(Item $item): self
  175.     {
  176.         if ($this->items->removeElement($item)) {
  177.             // set the owning side to null (unless already changed)
  178.             if ($item->getLineItem() === $this) {
  179.                 $item->setLineItem(null);
  180.             }
  181.         }
  182.         return $this;
  183.     }
  184.     public function getCustomer(): ?Company
  185.     {
  186.         return $this->customer;
  187.     }
  188.     public function setCustomer(?Company $customer): self
  189.     {
  190.         $this->customer $customer;
  191.         return $this;
  192.     }
  193.     public function getSupplier(): ?Company
  194.     {
  195.         return $this->supplier;
  196.     }
  197.     public function setSupplier(?Company $supplier): self
  198.     {
  199.         $this->supplier $supplier;
  200.         return $this;
  201.     }
  202.     public function getAsset(): ?Asset
  203.     {
  204.         return $this->asset;
  205.     }
  206.     public function setAsset(?Asset $asset): self
  207.     {
  208.         $this->asset $asset;
  209.         return $this;
  210.     }
  211.     public function getFlow(): ?Flow
  212.     {
  213.         return $this->flow;
  214.     }
  215.     public function setFlow(?Flow $flow): self
  216.     {
  217.         $this->flow $flow;
  218.         return $this;
  219.     }
  220.     public function getNumber(): ?string
  221.     {
  222.         return $this->number;
  223.     }
  224.     public function setNumber(string $number): self
  225.     {
  226.         $this->number $number;
  227.         return $this;
  228.     }
  229.     public function getMaterialNumber(): ?string
  230.     {
  231.         return $this->materialNumber;
  232.     }
  233.     public function setMaterialNumber(?string $materialNumber): self
  234.     {
  235.         $this->materialNumber $materialNumber;
  236.         return $this;
  237.     }
  238.     public function getMaterialGroup(): ?string
  239.     {
  240.         return $this->materialGroup;
  241.     }
  242.     public function setMaterialGroup(?string $materialGroup): self
  243.     {
  244.         $this->materialGroup $materialGroup;
  245.         return $this;
  246.     }
  247.     public function getSupplierPartNumber(): ?string
  248.     {
  249.         return $this->supplierPartNumber;
  250.     }
  251.     public function setSupplierPartNumber(?string $supplierPartNumber): self
  252.     {
  253.         $this->supplierPartNumber $supplierPartNumber;
  254.         return $this;
  255.     }
  256.     public function getSupplierDescription(): ?string
  257.     {
  258.         return $this->supplierDescription;
  259.     }
  260.     public function setSupplierDescription(?string $supplierDescription): self
  261.     {
  262.         $this->supplierDescription $supplierDescription;
  263.         return $this;
  264.     }
  265.     public function getCustomerDescription(): ?string
  266.     {
  267.         return $this->customerDescription;
  268.     }
  269.     public function setCustomerDescription(?string $customerDescription): self
  270.     {
  271.         $this->customerDescription $customerDescription;
  272.         return $this;
  273.     }
  274.     public function getQuantity(): ?int
  275.     {
  276.         return $this->quantity;
  277.     }
  278.     public function setQuantity(?int $quantity): self
  279.     {
  280.         $this->quantity $quantity;
  281.         return $this;
  282.     }
  283.     public function getHsCode(): ?string
  284.     {
  285.         return $this->hsCode;
  286.     }
  287.     public function setHsCode(?string $hsCode): self
  288.     {
  289.         $this->hsCode $hsCode;
  290.         return $this;
  291.     }
  292.     public function getCountryOfOrigin(): ?string
  293.     {
  294.         return $this->countryOfOrigin;
  295.     }
  296.     public function setCountryOfOrigin(?string $countryOfOrigin): self
  297.     {
  298.         $this->countryOfOrigin $countryOfOrigin;
  299.         return $this;
  300.     }
  301.     public function getUnitPrice(): ?float
  302.     {
  303.         return $this->unitPrice;
  304.     }
  305.     public function setUnitPrice(?float $unitPrice): self
  306.     {
  307.         $this->unitPrice $unitPrice;
  308.         return $this;
  309.     }
  310.     public function getValue(): ?string
  311.     {
  312.         return $this->value;
  313.     }
  314.     public function setValue(?string $value): self
  315.     {
  316.         $this->value $value;
  317.         return $this;
  318.     }
  319.     public function getCurrency(): ?string
  320.     {
  321.         return $this->currency;
  322.     }
  323.     public function setCurrency(?string $currency): self
  324.     {
  325.         $this->currency $currency;
  326.         return $this;
  327.     }
  328.     public function getAvailableOn(): ?DateTimeInterface
  329.     {
  330.         return $this->availableOn;
  331.     }
  332.     public function setAvailableOn(?DateTimeInterface $availableOn): self
  333.     {
  334.         $this->availableOn $availableOn;
  335.         return $this;
  336.     }
  337.     public function getStatus(): ?LineItemStatus
  338.     {
  339.         return $this->status;
  340.     }
  341.     public function setStatus(?LineItemStatus $status): self
  342.     {
  343.         $this->status $status;
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return Collection<int, InventoryItem>
  348.      */
  349.     public function getInventoriedItems(): Collection
  350.     {
  351.         return $this->inventoriedItems;
  352.     }
  353.     public function addInventoriedItem(InventoryItem $inventoriedItem): static
  354.     {
  355.         if (!$this->inventoriedItems->contains($inventoriedItem)) {
  356.             $this->inventoriedItems->add($inventoriedItem);
  357.             $inventoriedItem->setLineItem($this);
  358.         }
  359.         return $this;
  360.     }
  361.     public function removeInventoriedItem(InventoryItem $inventoriedItem): static
  362.     {
  363.         if ($this->inventoriedItems->removeElement($inventoriedItem)) {
  364.             // set the owning side to null (unless already changed)
  365.             if ($inventoriedItem->getLineItem() === $this) {
  366.                 $inventoriedItem->setLineItem(null);
  367.             }
  368.         }
  369.         return $this;
  370.     }
  371. }