src/Entity/Expediting/Freight.php line 73
<?php
namespace App\Entity\Expediting;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model;
use App\Controller\Expediting\FreightDocumentUploadAction;
use App\Entity\Common as Common;
use App\Entity\File\File;
use App\Entity\Purchasing\Order;
use App\Entity\Sales\WorkOrder;
use ArrayObject;
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: 'expediting_freight')]
#[ORM\Index(columns: ['order_id'], name: 'expediting_freight_order_id_idx')]
#[ORM\Index(columns: ['work_order_id'], name: 'expediting_freight_work_order_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'expediting_freight_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'expediting_freight_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'expediting_freight_identifier_key', columns: ['identifier'])]
#[ORM\Entity]
#[UniqueEntity(fields: ['identifier'])]
#[ApiResource(routePrefix: '/expediting')]
#[ApiResource(
uriTemplate: '/work_orders/{slug}/freights',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'freights', fromClass: WorkOrder::class),
],
)]
#[ApiResource(
// FIXME : This does not work well with docker
uriTemplate: '/freights/{slug}/attachments',
operations: [
new Post(
controller: FreightDocumentUploadAction::class,
openapi: new Model\Operation(
requestBody: new Model\RequestBody(
content: new ArrayObject([
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary'
]
]
]
]
])
)
),
shortName: 'Upload',
validationContext: ['groups' => ['Default', 'upload:create']],
deserialize: false,
),
],
routePrefix: '/expediting',
)]
class Freight
{
use Shippable;
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_freight_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private ?int $id = null;
#[Gedmo\Slug(fields: ['reference'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private ?string $slug = null;
#[ORM\Column(type: Types::STRING)]
private ?string $reference = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
private ?Ulid $identifier = null;
#[ORM\ManyToOne(targetEntity: WorkOrder::class, inversedBy: 'freights')]
#[ORM\JoinColumn(name: 'work_order_id', nullable: false)]
private ?WorkOrder $workOrder = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Order::class, cascade: ['persist', 'remove'], inversedBy: 'freights')]
#[ORM\JoinColumn(name: 'order_id')]
private ?Order $order = null;
#[Assert\NotNull]
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?DateTimeInterface $availableOn = 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::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $location = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $invoicesNumbers = [];
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $delayed = false;
/** @var Collection<int, Item> */
#[ORM\OneToMany(mappedBy: 'freight', targetEntity: Item::class, cascade: ['persist', 'remove'])]
private Collection $items;
/** @var Collection<int, File> */
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name: 'expediting_freight_file_map')]
#[ORM\JoinColumn(name: 'freight_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
#[ORM\OrderBy(['id' => 'ASC'])]
private Collection $attachments;
public function __construct()
{
$this->identifier = new Ulid();
$this->items = new ArrayCollection();
$this->attachments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getAvailableOn(): ?DateTimeInterface
{
return $this->availableOn;
}
public function setAvailableOn(DateTimeInterface $availableOn): self
{
$this->availableOn = $availableOn;
return $this;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): self
{
$this->value = $value;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function isDelayed(): ?bool
{
return $this->delayed;
}
public function setDelayed(?bool $delayed): self
{
$this->delayed = $delayed;
return $this;
}
public function getInvoicesNumbers(): ?array
{
return $this->invoicesNumbers;
}
public function addInvoiceNumber(string $invoiceNumber): self
{
$this->invoicesNumbers []= strtoupper($invoiceNumber);
$this->invoicesNumbers = array_unique($this->invoicesNumbers);
return $this;
}
public function setInvoicesNumbers(?array $invoicesNumbers): self
{
$this->invoicesNumbers = $invoicesNumbers;
return $this;
}
public function getWorkOrder(): ?WorkOrder
{
return $this->workOrder;
}
public function setWorkOrder(?WorkOrder $workOrder): self
{
$this->workOrder = $workOrder;
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->add($item);
$item->setFreight($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->getFreight() === $this) {
$item->setFreight(null);
}
}
return $this;
}
/**
* @return Collection<int, File>
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(File $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments->add($attachment);
}
return $this;
}
public function removeAttachment(File $attachment): self
{
$this->attachments->removeElement($attachment);
return $this;
}
}