src/Entity/Expediting/Item.php line 47
<?php
namespace App\Entity\Expediting;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Doctrine\Type\Expediting\UnitOfMeasurement;
use App\Dto\Expediting\ItemSurveyInput;
use App\Entity\File\File;
use App\Entity\Inventory\ItemMovement;
use App\Entity\Purchasing\Flow;
use App\Entity\Purchasing\LineItem;
use App\Entity\Purchasing\Order;
use App\Processor\Expediting\ItemSurveyInputProcessor;
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 Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Post(),
new Put(),
new Patch(),
new Delete(),
new Post(
uriTemplate: '/items/survey',
inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']],
input: ItemSurveyInput::class,
processor: ItemSurveyInputProcessor::class
),
],
routePrefix: '/expediting'
)]
class Item extends Expeditable
{
use Shippable;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Freight::class, inversedBy: 'items')]
#[ORM\JoinColumn(name: 'freight_id', nullable: false)]
private ?Freight $freight = null;
#[ORM\ManyToOne(targetEntity: Order::class)]
#[ORM\JoinColumn(name: 'order_id')]
private ?Order $order = null;
#[ORM\ManyToOne(targetEntity: Flow::class)]
#[ORM\JoinColumn(name: 'flow_id')]
private ?Flow $flow = null;
#[ORM\ManyToOne(targetEntity: LineItem::class, inversedBy: 'items')]
#[ORM\JoinColumn(name: 'line_item_id')]
private ?LineItem $lineItem = null;
/** @var Collection<int, Part> */
#[ORM\OneToMany(mappedBy: 'item', targetEntity: Part::class, cascade: ['remove'])]
private Collection $parts;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
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 $packageNumber = null;
#[IsValidEnum(enum: UnitOfMeasurement::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: UnitOfMeasurement::class)]
private ?UnitOfMeasurement $unitOfMeasurement = null;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $requestedDeliveryOn = null;
#[Assert\Type(type: Types::INTEGER)]
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $quantity = 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\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $packed = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $certified = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $fatRequired = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $listed = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $retired = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $uniquePart = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $manufactured = false;
/** @var Collection<int, ItemMovement> */
#[ORM\OneToMany(mappedBy: 'item', targetEntity: ItemMovement::class)]
#[Ignore]
private Collection $movements;
public function __construct()
{
parent::__construct();
$this->parts = new ArrayCollection();
$this->movements = new ArrayCollection();
}
public function getFreight(): ?Freight
{
return $this->freight;
}
public function setFreight(?Freight $freight): self
{
$this->freight = $freight;
return $this;
}
public function getOrder(): ?Order
{
return $this->order;
}
public function setOrder(?Order $order): self
{
$this->order = $order;
return $this;
}
public function getLineItem(): ?LineItem
{
return $this->lineItem;
}
public function setLineItem(?LineItem $lineItem): self
{
$this->lineItem = $lineItem;
// This is important as this is used for indexing items
$this->lineItem->addItem($this);
return $this;
}
/**
* @return Collection<int, Part>
*/
public function getParts(): Collection
{
return $this->parts;
}
public function addPart(Part $part): self
{
if (!$this->parts->contains($part)) {
$this->parts[] = $part;
$part->setItem($this);
}
return $this;
}
public function removePart(Part $part): self
{
if ($this->parts->removeElement($part)) {
// set the owning side to null (unless already changed)
if ($part->getItem() === $this) {
$part->setItem(null);
}
}
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 getPackageNumber(): ?string
{
return $this->packageNumber;
}
public function setPackageNumber(?string $packageNumber): self
{
$this->packageNumber = $packageNumber;
return $this;
}
public function getUnitOfMeasurement(): ?UnitOfMeasurement
{
return $this->unitOfMeasurement;
}
public function setUnitOfMeasurement(?UnitOfMeasurement $unitOfMeasurement): self
{
$this->unitOfMeasurement = $unitOfMeasurement;
return $this;
}
public function getRequestedDeliveryOn(): ?DateTimeInterface
{
return $this->requestedDeliveryOn;
}
public function setRequestedDeliveryOn(?DateTimeInterface $requestedDeliveryOn): self
{
$this->requestedDeliveryOn = $requestedDeliveryOn;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(?int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getUnitPrice(): ?float
{
return $this->unitPrice;
}
public function setUnitPrice(?float $unitPrice): self
{
$this->unitPrice = $unitPrice;
return $this;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue(?float $value): self
{
$this->value = $value;
return $this;
}
public function isPacked(): ?bool
{
return $this->packed;
}
public function setPacked(?bool $packed): self
{
$this->packed = $packed;
return $this;
}
public function isCertified(): ?bool
{
return $this->certified;
}
public function setCertified(?bool $certified): self
{
$this->certified = $certified;
return $this;
}
public function isFatRequired(): ?bool
{
return $this->fatRequired;
}
public function setFatRequired(?bool $fatRequired): self
{
$this->fatRequired = $fatRequired;
return $this;
}
public function getFlow(): ?Flow
{
return $this->flow;
}
public function setFlow(?Flow $flow): self
{
$this->flow = $flow;
return $this;
}
public function isUniquePart(): ?bool
{
return $this->uniquePart;
}
public function setUniquePart(?bool $uniquePart): self
{
$this->uniquePart = $uniquePart;
return $this;
}
public function isManufactured(): ?bool
{
return $this->manufactured;
}
public function setManufactured(?bool $manufactured): self
{
$this->manufactured = $manufactured;
return $this;
}
public function isListed(): ?bool
{
return $this->listed;
}
public function setListed(?bool $listed): self
{
$this->listed = $listed;
return $this;
}
public function isRetired(): ?bool
{
return $this->retired;
}
public function setRetired(?bool $retired): self
{
$this->retired = $retired;
return $this;
}
/**
* @return Collection<int, ItemMovement>
*/
public function getMovements(): Collection
{
return $this->movements;
}
public function addMovement(ItemMovement $movement): static
{
if (!$this->movements->contains($movement)) {
$this->movements->add($movement);
$movement->setItem($this);
}
return $this;
}
public function removeMovement(ItemMovement $movement): static
{
if ($this->movements->removeElement($movement)) {
// set the owning side to null (unless already changed)
if ($movement->getItem() === $this) {
$movement->setItem(null);
}
}
return $this;
}
}