src/Entity/Delete/Withdrawal.php line 93
<?php
namespace App\Entity\Delete;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
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 ApiPlatform\OpenApi\Model;
use App\Controller\Delete\WithdrawalDocumentUploadAction;
use App\Dto\Common\ObservationInput;
use App\Dto\Delete\WithdrawalInput;
use App\Entity\Common as Common;
use App\Entity\Common\Observation;
use App\Entity\File\File;
use App\Entity\Identity\User;
use App\Processor\Delete\WithdrawalInputProcessor;
use App\Processor\Delete\WithdrawalObservationProcessor;
use App\Provider\Delete\WithdrawalProvider;
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\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'inventory_x_withdrawal')]
#[ORM\Index(columns: ['created_by'], name: 'inventory_x_withdrawal_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'inventory_x_withdrawal_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'inventory_x_withdrawal_slug_key', columns: ['slug'])]
#[ORM\UniqueConstraint(name: 'inventory_x_withdrawal_reference_key', columns: ['reference'])]
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(provider: WithdrawalProvider::class),
new GetCollection(),
new Post(input: WithdrawalInput::class, processor: WithdrawalInputProcessor::class),
new Patch(),
new Put(),
new Delete(),
],
routePrefix: '/nventory',
)]
#[ApiResource(
// FIXME : This does not work well with docker
uriTemplate: '/nventory/withdrawals/{slug}/attachments',
operations: [
new Post(
controller: WithdrawalDocumentUploadAction::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,
),
],
)]
#[ApiResource(
operations: [
new Post(
uriTemplate: '/nventory/withdrawals/{slug}/observations',
input: ObservationInput::class,
processor: WithdrawalObservationProcessor::class
),
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'reference' => 'ipartial',
])]
class Withdrawal
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'inventory_x_withdrawal_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private int $id;
#[Gedmo\Slug(fields: ['reference'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private string $slug;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $reference = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $type = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $consumer = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $reason = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, options: ['default' => 'CURRENT_TIMESTAMP'])]
private ?DateTimeInterface $requestedFor = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, nullable: true)]
private ?DateTimeInterface $acceptedAt = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, nullable: true)]
private ?DateTimeInterface $processedAt = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, nullable: true)]
private ?DateTimeInterface $pickedAt = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, nullable: true)]
private ?DateTimeInterface $rejectedAt = null;
#[Gedmo\Blameable(on: 'create')]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: true)]
protected ?User $createdBy = null;
/** @var Collection<int, Movement> */
#[ORM\OneToMany(mappedBy: 'withdrawal', targetEntity: Movement::class, cascade: ['persist', 'remove'])]
private Collection $movements;
/** @var Collection<int, File> */
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name: 'inventory_x_withdrawal_file_map')]
#[ORM\JoinColumn(name: 'withdrawal_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
#[ORM\OrderBy(['id' => 'ASC'])]
private Collection $attachments;
/** @var Collection<int, Observation> */
#[ORM\OneToMany(mappedBy: 'withdrawal', targetEntity: Observation::class, cascade: ['persist', 'remove'])]
private Collection $observations;
public array $items = [];
public function __construct()
{
$this->movements = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->observations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): static
{
$this->reference = $reference;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getConsumer(): ?string
{
return $this->consumer;
}
public function setConsumer(string $consumer): static
{
$this->consumer = $consumer;
return $this;
}
public function getReason(): ?string
{
return $this->reason;
}
public function setReason(string $reason): static
{
$this->reason = $reason;
return $this;
}
public function getRequestedFor(): ?DateTimeInterface
{
return $this->requestedFor;
}
public function setRequestedFor(DateTimeInterface $requestedFor): static
{
$this->requestedFor = $requestedFor;
return $this;
}
public function getAcceptedAt(): ?DateTimeInterface
{
return $this->acceptedAt;
}
public function setAcceptedAt(?DateTimeInterface $acceptedAt): static
{
$this->acceptedAt = $acceptedAt;
return $this;
}
public function getProcessedAt(): ?DateTimeInterface
{
return $this->processedAt;
}
public function setProcessedAt(?DateTimeInterface $processedAt): static
{
$this->processedAt = $processedAt;
return $this;
}
public function getPickedAt(): ?DateTimeInterface
{
return $this->pickedAt;
}
public function setPickedAt(?DateTimeInterface $pickedAt): static
{
$this->pickedAt = $pickedAt;
return $this;
}
public function getRejectedAt(): ?DateTimeInterface
{
return $this->rejectedAt;
}
public function setRejectedAt(?DateTimeInterface $rejectedAt): static
{
$this->rejectedAt = $rejectedAt;
return $this;
}
/** @return Collection<int, Movement> */
public function getMovements(): Collection
{
return $this->movements;
}
public function addMovement(Movement $movement): static
{
if (!$this->movements->contains($movement)) {
$this->movements->add($movement);
$movement->setWithdrawal($this);
}
return $this;
}
public function removeMovement(Movement $movement): static
{
if ($this->movements->removeElement($movement)) {
// set the owning side to null (unless already changed)
if ($movement->getWithdrawal() === $this) {
$movement->setWithdrawal(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;
}
/**
* @return Collection<int, Observation>
*/
public function getObservations(): Collection
{
return $this->observations;
}
public function addObservation(Observation $observation): self
{
if (!$this->observations->contains($observation)) {
$this->observations->add($observation);
$observation->setWithdrawal($this);
}
return $this;
}
public function removeObservation(Observation $observation): self
{
if ($this->observations->removeElement($observation)) {
// set the owning side to null (unless already changed)
if ($observation->getWithdrawal() === $this) {
$observation->setWithdrawal(null);
}
}
return $this;
}
}