src/Entity/Purchasing/Order.php line 57
<?php
namespace App\Entity\Purchasing;
use ApiPlatform\Metadata\ApiProperty;
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\Purchasing\PurchaseOrderStatus;
use App\Doctrine\Type\Sales\Incoterm;
use App\Dto\Purchasing\CurrencyInput;
use App\Entity\Common as Common;
use App\Entity\Common\Company;
use App\Entity\Expediting\Freight;
use App\Entity\File\Parsable;
use App\Entity\Identity\User;
use App\Processor\Purchasing\CurrencyInputProcessor;
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_order')]
#[ORM\Index(columns: ['customer_id'], name: 'purchasing_order_customer_id_idx')]
#[ORM\Index(columns: ['supplier_id'], name: 'purchasing_order_supplier_id_idx')]
#[ORM\Index(columns: ['source_id'], name: 'purchasing_order_source_id_idx')]
#[ORM\Index(columns: ['issued_by'], name: 'purchasing_order_issued_by_idx')]
#[ORM\Index(columns: ['created_by'], name: 'purchasing_order_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'purchasing_order_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'purchasing_order_identifier_key', columns: ['identifier'])]
#[ORM\UniqueConstraint(name: 'purchasing_order_customer_id_number_key', columns: ['customer_id', 'number'])]
#[ORM\UniqueConstraint(name: 'purchasing_order_slug_key', columns: ['slug'])]
#[ORM\Entity]
#[UniqueEntity(fields: ['customer', 'number'])]
#[ApiResource(routePrefix: '/purchasing')]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Post(uriTemplate: '/orders/currencies', input: CurrencyInput::class, provider: CurrencyInputProcessor::class),
new Patch(),
new Put(),
new Delete(),
],
routePrefix: '/purchasing',
)]
class Order
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'purchasing_order_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;
#[ORM\Column(type: Types::STRING)]
#[Gedmo\Slug(fields: ['number'])]
#[ApiProperty(identifier: true)]
private ?string $slug = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'customer_id')]
#[ApiProperty(readableLink: true)]
private ?Company $customer = null;
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'supplier_id')]
#[ApiProperty(readableLink: true)]
private ?Company $supplier = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'issued_by')]
private ?User $issuedBy = null;
#[Assert\Type(type: Parsable::class)]
#[ORM\ManyToOne(targetEntity: Parsable::class, inversedBy: 'orders')]
#[ORM\JoinColumn(name: 'source_id')]
private ?Parsable $source = 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 $groupNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $trackingNumber = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $highValue = false;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $highVolume = false;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $highRisk = false;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $delayed = false;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, options: ['default' => 'CURRENT_DATE'])]
private ?DateTimeInterface $placedOn = null;
#[IsValidEnum(enum: Incoterm::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: Incoterm::class)]
private ?Incoterm $incoterm = null;
#[Assert\Length(exactly: 3)]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, length: 3, nullable: true)]
private ?string $currency = null;
/** @var Collection<int, LineItem> */
#[ORM\OneToMany(mappedBy: 'order', targetEntity: LineItem::class, cascade: ['persist', 'remove'])]
private Collection $lineItems;
/** @var Collection<int, Freight> */
#[ORM\OneToMany(mappedBy: 'order', targetEntity: Freight::class)]
private Collection $freights;
#[Assert\NotNull]
#[IsValidEnum(enum: PurchaseOrderStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: PurchaseOrderStatus::class, options: ['default' => 'PLACED'])]
private ?PurchaseOrderStatus $status = PurchaseOrderStatus::PLACED;
public function __construct()
{
$this->identifier = new Ulid();
$this->lineItems = new ArrayCollection();
$this->freights = 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 getNumber(): ?string
{
return $this->number;
}
public function setNumber(string $number): self
{
$this->number = $number;
return $this;
}
public function getGroupNumber(): ?string
{
return $this->groupNumber;
}
public function setGroupNumber(?string $groupNumber): self
{
$this->groupNumber = $groupNumber;
return $this;
}
public function getTrackingNumber(): ?string
{
return $this->trackingNumber;
}
public function setTrackingNumber(?string $trackingNumber): self
{
$this->trackingNumber = $trackingNumber;
return $this;
}
public function isHighValue(): ?bool
{
return $this->highValue;
}
public function setHighValue(bool $highValue): self
{
$this->highValue = $highValue;
return $this;
}
public function isHighVolume(): ?bool
{
return $this->highVolume;
}
public function setHighVolume(bool $highVolume): self
{
$this->highVolume = $highVolume;
return $this;
}
public function isHighRisk(): ?bool
{
return $this->highRisk;
}
public function setHighRisk(bool $highRisk): self
{
$this->highRisk = $highRisk;
return $this;
}
public function isDelayed(): ?bool
{
return $this->delayed;
}
public function setDelayed(bool $delayed): self
{
$this->delayed = $delayed;
return $this;
}
public function getPlacedOn(): ?DateTimeInterface
{
return $this->placedOn;
}
public function setPlacedOn(?DateTimeInterface $placedOn): self
{
$this->placedOn = $placedOn;
return $this;
}
public function getIncoterm(): ?Incoterm
{
return $this->incoterm;
}
public function setIncoterm(?Incoterm $incoterm): self
{
$this->incoterm = $incoterm;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getStatus(): ?PurchaseOrderStatus
{
return $this->status;
}
public function setStatus(?PurchaseOrderStatus $status): self
{
$this->status = $status;
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 getIssuedBy(): ?User
{
return $this->issuedBy;
}
public function setIssuedBy(?User $issuedBy): self
{
$this->issuedBy = $issuedBy;
return $this;
}
public function getSource(): ?Parsable
{
return $this->source;
}
public function setSource(?Parsable $source): self
{
$this->source = $source;
return $this;
}
/**
* @return Collection<int, LineItem>
*/
public function getLineItems(): Collection
{
return $this->lineItems;
}
public function addLineItem(LineItem $lineItem): self
{
if (!$this->lineItems->contains($lineItem)) {
$this->lineItems->add($lineItem);
$lineItem->setOrder($this);
}
return $this;
}
public function removeLineItem(LineItem $lineItem): self
{
if ($this->lineItems->removeElement($lineItem)) {
// set the owning side to null (unless already changed)
if ($lineItem->getOrder() === $this) {
$lineItem->setOrder(null);
}
}
return $this;
}
/**
* @return Collection<int, Freight>
*/
public function getFreights(): Collection
{
return $this->freights;
}
public function addFreight(Freight $freight): self
{
if (!$this->freights->contains($freight)) {
$this->freights->add($freight);
$freight->setOrder($this);
}
return $this;
}
public function removeFreight(Freight $freight): self
{
if ($this->freights->removeElement($freight)) {
// set the owning side to null (unless already changed)
if ($freight->getOrder() === $this) {
$freight->setOrder(null);
}
}
return $this;
}
}