src/Entity/Purchasing/LineItem.php line 38
<?php
namespace App\Entity\Purchasing;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use App\Doctrine\Type\Purchasing\LineItemStatus;
use App\Entity\Common as Common;
use App\Entity\Common\Company;
use App\Entity\Expediting\Item;
use App\Entity\Inventory\InventoryItem;
use App\Entity\Sales\Asset;
use App\Validator\IsValidEnum\IsValidEnum;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'purchasing_line_item')]
#[ORM\Index(columns: ['order_id'], name: 'purchasing_line_item_order_id_idx')]
#[ORM\Index(columns: ['customer_id'], name: 'purchasing_line_item_customer_id_idx')]
#[ORM\Index(columns: ['supplier_id'], name: 'purchasing_line_item_supplier_id_idx')]
#[ORM\Index(columns: ['asset_id'], name: 'purchasing_line_item_asset_id_idx')]
#[ORM\Index(columns: ['flow_id'], name: 'purchasing_line_item_flow_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'purchasing_line_item_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'purchasing_line_item_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'purchasing_line_item_identifier_key', columns: ['identifier'])]
#[ORM\UniqueConstraint(name: 'purchasing_line_item_order_id_number_key', columns: ['order_id', 'number'])]
#[ORM\UniqueConstraint(name: 'purchasing_line_item_slug_key', columns: ['slug'])]
#[ORM\Entity]
#[UniqueEntity(fields: ['order', 'number'])]
#[ApiResource(routePrefix: '/purchasing')]
class LineItem
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'purchasing_line_item_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
private ?Ulid $identifier = null;
#[Gedmo\Slug(fields: ['number'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private ?string $slug = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'lineItems')]
#[ORM\JoinColumn(name: 'order_id', nullable: false)]
private ?Order $order = null;
/** @var Collection<int, Item> */
#[ORM\OneToMany(mappedBy: 'lineItem', targetEntity: Item::class, cascade: ['persist', 'remove'])]
private Collection $items;
/** @var Collection<int, InventoryItem> */
#[ORM\OneToMany(mappedBy: 'lineItem', targetEntity: InventoryItem::class)]
private Collection $inventoriedItems;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'customer_id')]
private ?Company $customer = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'supplier_id')]
private ?Company $supplier = null;
#[ORM\ManyToOne(targetEntity: Asset::class)]
#[ORM\JoinColumn(name: 'asset_id')]
private ?Asset $asset = null;
#[ORM\ManyToOne(targetEntity: Flow::class)]
#[ORM\JoinColumn(name: 'flow_id')]
private ?Flow $flow = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $number = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $materialNumber;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $materialGroup;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $supplierPartNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $supplierDescription = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $customerDescription = null;
#[Assert\Type(type: Types::INTEGER)]
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $quantity = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $hsCode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $countryOfOrigin = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 5, nullable: true)]
private ?float $unitPrice = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 5, nullable: true)]
private ?float $value = null;
#[Assert\Length(exactly: 3)]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, length: 3, nullable: true)]
private ?string $currency = null;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $availableOn = null;
#[Assert\NotNull]
#[IsValidEnum(enum: LineItemStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: LineItemStatus::class, options: ['default' => 'ORDERED'])]
private ?LineItemStatus $status = LineItemStatus::ORDERED;
public function __construct()
{
$this->identifier = new Ulid();
$this->items = new ArrayCollection();
$this->inventoriedItems = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getOrder(): ?Order
{
return $this->order;
}
public function setOrder(?Order $order): self
{
$this->order = $order;
return $this;
}
/**
* @return Collection<int, Item>
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Item $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setLineItem($this);
}
return $this;
}
public function removeItem(Item $item): self
{
if ($this->items->removeElement($item)) {
// set the owning side to null (unless already changed)
if ($item->getLineItem() === $this) {
$item->setLineItem(null);
}
}
return $this;
}
public function getCustomer(): ?Company
{
return $this->customer;
}
public function setCustomer(?Company $customer): self
{
$this->customer = $customer;
return $this;
}
public function getSupplier(): ?Company
{
return $this->supplier;
}
public function setSupplier(?Company $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getAsset(): ?Asset
{
return $this->asset;
}
public function setAsset(?Asset $asset): self
{
$this->asset = $asset;
return $this;
}
public function getFlow(): ?Flow
{
return $this->flow;
}
public function setFlow(?Flow $flow): self
{
$this->flow = $flow;
return $this;
}
public function getNumber(): ?string
{
return $this->number;
}
public function setNumber(string $number): self
{
$this->number = $number;
return $this;
}
public function getMaterialNumber(): ?string
{
return $this->materialNumber;
}
public function setMaterialNumber(?string $materialNumber): self
{
$this->materialNumber = $materialNumber;
return $this;
}
public function getMaterialGroup(): ?string
{
return $this->materialGroup;
}
public function setMaterialGroup(?string $materialGroup): self
{
$this->materialGroup = $materialGroup;
return $this;
}
public function getSupplierPartNumber(): ?string
{
return $this->supplierPartNumber;
}
public function setSupplierPartNumber(?string $supplierPartNumber): self
{
$this->supplierPartNumber = $supplierPartNumber;
return $this;
}
public function getSupplierDescription(): ?string
{
return $this->supplierDescription;
}
public function setSupplierDescription(?string $supplierDescription): self
{
$this->supplierDescription = $supplierDescription;
return $this;
}
public function getCustomerDescription(): ?string
{
return $this->customerDescription;
}
public function setCustomerDescription(?string $customerDescription): self
{
$this->customerDescription = $customerDescription;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(?int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getHsCode(): ?string
{
return $this->hsCode;
}
public function setHsCode(?string $hsCode): self
{
$this->hsCode = $hsCode;
return $this;
}
public function getCountryOfOrigin(): ?string
{
return $this->countryOfOrigin;
}
public function setCountryOfOrigin(?string $countryOfOrigin): self
{
$this->countryOfOrigin = $countryOfOrigin;
return $this;
}
public function getUnitPrice(): ?float
{
return $this->unitPrice;
}
public function setUnitPrice(?float $unitPrice): self
{
$this->unitPrice = $unitPrice;
return $this;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): self
{
$this->value = $value;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getAvailableOn(): ?DateTimeInterface
{
return $this->availableOn;
}
public function setAvailableOn(?DateTimeInterface $availableOn): self
{
$this->availableOn = $availableOn;
return $this;
}
public function getStatus(): ?LineItemStatus
{
return $this->status;
}
public function setStatus(?LineItemStatus $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection<int, InventoryItem>
*/
public function getInventoriedItems(): Collection
{
return $this->inventoriedItems;
}
public function addInventoriedItem(InventoryItem $inventoriedItem): static
{
if (!$this->inventoriedItems->contains($inventoriedItem)) {
$this->inventoriedItems->add($inventoriedItem);
$inventoriedItem->setLineItem($this);
}
return $this;
}
public function removeInventoriedItem(InventoryItem $inventoriedItem): static
{
if ($this->inventoriedItems->removeElement($inventoriedItem)) {
// set the owning side to null (unless already changed)
if ($inventoriedItem->getLineItem() === $this) {
$inventoriedItem->setLineItem(null);
}
}
return $this;
}
}