src/Entity/Delete/Withdrawal.php line 93

  1. <?php
  2. namespace App\Entity\Delete;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiProperty;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Delete;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Patch;
  11. use ApiPlatform\Metadata\Post;
  12. use ApiPlatform\Metadata\Put;
  13. use ApiPlatform\OpenApi\Model;
  14. use App\Controller\Delete\WithdrawalDocumentUploadAction;
  15. use App\Dto\Common\ObservationInput;
  16. use App\Dto\Delete\WithdrawalInput;
  17. use App\Entity\Common as Common;
  18. use App\Entity\Common\Observation;
  19. use App\Entity\File\File;
  20. use App\Entity\Identity\User;
  21. use App\Processor\Delete\WithdrawalInputProcessor;
  22. use App\Processor\Delete\WithdrawalObservationProcessor;
  23. use App\Provider\Delete\WithdrawalProvider;
  24. use ArrayObject;
  25. use DateTimeInterface;
  26. use Doctrine\Common\Collections\ArrayCollection;
  27. use Doctrine\Common\Collections\Collection;
  28. use Doctrine\DBAL\Types\Types;
  29. use Doctrine\ORM\Mapping as ORM;
  30. use Gedmo\Mapping\Annotation as Gedmo;
  31. use Symfony\Component\Validator\Constraints as Assert;
  32. #[ORM\Table(name'inventory_x_withdrawal')]
  33. #[ORM\Index(columns: ['created_by'], name'inventory_x_withdrawal_created_by_idx')]
  34. #[ORM\Index(columns: ['updated_by'], name'inventory_x_withdrawal_updated_by_idx')]
  35. #[ORM\UniqueConstraint(name'inventory_x_withdrawal_slug_key'columns: ['slug'])]
  36. #[ORM\UniqueConstraint(name'inventory_x_withdrawal_reference_key'columns: ['reference'])]
  37. #[ORM\Entity]
  38. #[ApiResource(
  39.     operations: [
  40.         new Get(providerWithdrawalProvider::class),
  41.         new GetCollection(),
  42.         new Post(inputWithdrawalInput::class, processorWithdrawalInputProcessor::class),
  43.         new Patch(),
  44.         new Put(),
  45.         new Delete(),
  46.     ],
  47.     routePrefix'/nventory',
  48. )]
  49. #[ApiResource(
  50.     // FIXME : This does not work well with docker
  51.     uriTemplate'/nventory/withdrawals/{slug}/attachments',
  52.     operations: [
  53.         new Post(
  54.             controllerWithdrawalDocumentUploadAction::class,
  55.             openapi: new Model\Operation(
  56.                 requestBody: new Model\RequestBody(
  57.                     content: new ArrayObject([
  58.                         'multipart/form-data' => [
  59.                             'schema' => [
  60.                                 'type' => 'object',
  61.                                 'properties' => [
  62.                                     'file' => [
  63.                                         'type' => 'string',
  64.                                         'format' => 'binary'
  65.                                     ]
  66.                                 ]
  67.                             ]
  68.                         ]
  69.                     ])
  70.                 )
  71.             ),
  72.             shortName'Upload',
  73.             validationContext: ['groups' => ['Default''upload:create']],
  74.             deserializefalse,
  75.         ),
  76.     ],
  77. )]
  78. #[ApiResource(
  79.     operations: [
  80.         new Post(
  81.             uriTemplate'/nventory/withdrawals/{slug}/observations',
  82.             inputObservationInput::class,
  83.             processorWithdrawalObservationProcessor::class
  84.         ),
  85.     ]
  86. )]
  87. #[ApiFilter(SearchFilter::class, properties: [
  88.     'reference' => 'ipartial',
  89. ])]
  90. class Withdrawal
  91. {
  92.     use Common\Blameable;
  93.     use Common\Trackable;
  94.     #[ORM\Id]
  95.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  96.     #[ORM\SequenceGenerator(sequenceName'inventory_x_withdrawal_id_seq')]
  97.     #[ORM\Column(typeTypes::INTEGER)]
  98.     #[ApiProperty(identifierfalse)]
  99.     private int $id;
  100.     #[Gedmo\Slug(fields: ['reference'])]
  101.     #[ORM\Column(typeTypes::STRING)]
  102.     #[ApiProperty(identifiertrue)]
  103.     private string $slug;
  104.     #[Assert\NotBlank]
  105.     #[Assert\Type(typeTypes::STRING)]
  106.     #[ORM\Column(typeTypes::STRING)]
  107.     private ?string $reference null;
  108.     #[Assert\Type(typeTypes::STRING)]
  109.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  110.     private ?string $type null;
  111.     #[Assert\Type(typeTypes::STRING)]
  112.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  113.     private ?string $consumer null;
  114.     #[Assert\Type(typeTypes::STRING)]
  115.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  116.     private ?string $reason null;
  117.     #[Assert\Type(typeDateTimeInterface::class)]
  118.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEoptions: ['default' => 'CURRENT_TIMESTAMP'])]
  119.     private ?DateTimeInterface $requestedFor null;
  120.     #[Assert\Type(typeDateTimeInterface::class)]
  121.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEnullabletrue)]
  122.     private ?DateTimeInterface $acceptedAt null;
  123.     #[Assert\Type(typeDateTimeInterface::class)]
  124.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEnullabletrue)]
  125.     private ?DateTimeInterface $processedAt null;
  126.     #[Assert\Type(typeDateTimeInterface::class)]
  127.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEnullabletrue)]
  128.     private ?DateTimeInterface $pickedAt null;
  129.     #[Assert\Type(typeDateTimeInterface::class)]
  130.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEnullabletrue)]
  131.     private ?DateTimeInterface $rejectedAt null;
  132.     #[Gedmo\Blameable(on'create')]
  133.     #[ORM\ManyToOne(targetEntityUser::class)]
  134.     #[ORM\JoinColumn(name'created_by'nullabletrue)]
  135.     protected ?User $createdBy null;
  136.     /** @var Collection<int, Movement> */
  137.     #[ORM\OneToMany(mappedBy'withdrawal'targetEntityMovement::class, cascade: ['persist''remove'])]
  138.     private Collection $movements;
  139.     /** @var Collection<int, File> */
  140.     #[ORM\ManyToMany(targetEntityFile::class, cascade: ['persist''remove'])]
  141.     #[ORM\JoinTable(name'inventory_x_withdrawal_file_map')]
  142.     #[ORM\JoinColumn(name'withdrawal_id')]
  143.     #[ORM\InverseJoinColumn(name'file_id')]
  144.     #[ORM\OrderBy(['id' => 'ASC'])]
  145.     private Collection $attachments;
  146.     /** @var Collection<int, Observation> */
  147.     #[ORM\OneToMany(mappedBy'withdrawal'targetEntityObservation::class, cascade: ['persist''remove'])]
  148.     private Collection $observations;
  149.     public array $items = [];
  150.     public function __construct()
  151.     {
  152.         $this->movements = new ArrayCollection();
  153.         $this->attachments = new ArrayCollection();
  154.         $this->observations = new ArrayCollection();
  155.     }
  156.     public function getId(): ?int
  157.     {
  158.         return $this->id;
  159.     }
  160.     public function getSlug(): ?string
  161.     {
  162.         return $this->slug;
  163.     }
  164.     public function setSlug(string $slug): static
  165.     {
  166.         $this->slug $slug;
  167.         return $this;
  168.     }
  169.     public function getReference(): ?string
  170.     {
  171.         return $this->reference;
  172.     }
  173.     public function setReference(string $reference): static
  174.     {
  175.         $this->reference $reference;
  176.         return $this;
  177.     }
  178.     public function getType(): ?string
  179.     {
  180.         return $this->type;
  181.     }
  182.     public function setType(string $type): static
  183.     {
  184.         $this->type $type;
  185.         return $this;
  186.     }
  187.     public function getConsumer(): ?string
  188.     {
  189.         return $this->consumer;
  190.     }
  191.     public function setConsumer(string $consumer): static
  192.     {
  193.         $this->consumer $consumer;
  194.         return $this;
  195.     }
  196.     public function getReason(): ?string
  197.     {
  198.         return $this->reason;
  199.     }
  200.     public function setReason(string $reason): static
  201.     {
  202.         $this->reason $reason;
  203.         return $this;
  204.     }
  205.     public function getRequestedFor(): ?DateTimeInterface
  206.     {
  207.         return $this->requestedFor;
  208.     }
  209.     public function setRequestedFor(DateTimeInterface $requestedFor): static
  210.     {
  211.         $this->requestedFor $requestedFor;
  212.         return $this;
  213.     }
  214.     public function getAcceptedAt(): ?DateTimeInterface
  215.     {
  216.         return $this->acceptedAt;
  217.     }
  218.     public function setAcceptedAt(?DateTimeInterface $acceptedAt): static
  219.     {
  220.         $this->acceptedAt $acceptedAt;
  221.         return $this;
  222.     }
  223.     public function getProcessedAt(): ?DateTimeInterface
  224.     {
  225.         return $this->processedAt;
  226.     }
  227.     public function setProcessedAt(?DateTimeInterface $processedAt): static
  228.     {
  229.         $this->processedAt $processedAt;
  230.         return $this;
  231.     }
  232.     public function getPickedAt(): ?DateTimeInterface
  233.     {
  234.         return $this->pickedAt;
  235.     }
  236.     public function setPickedAt(?DateTimeInterface $pickedAt): static
  237.     {
  238.         $this->pickedAt $pickedAt;
  239.         return $this;
  240.     }
  241.     public function getRejectedAt(): ?DateTimeInterface
  242.     {
  243.         return $this->rejectedAt;
  244.     }
  245.     public function setRejectedAt(?DateTimeInterface $rejectedAt): static
  246.     {
  247.         $this->rejectedAt $rejectedAt;
  248.         return $this;
  249.     }
  250.     /** @return Collection<int, Movement> */
  251.     public function getMovements(): Collection
  252.     {
  253.         return $this->movements;
  254.     }
  255.     public function addMovement(Movement $movement): static
  256.     {
  257.         if (!$this->movements->contains($movement)) {
  258.             $this->movements->add($movement);
  259.             $movement->setWithdrawal($this);
  260.         }
  261.         return $this;
  262.     }
  263.     public function removeMovement(Movement $movement): static
  264.     {
  265.         if ($this->movements->removeElement($movement)) {
  266.             // set the owning side to null (unless already changed)
  267.             if ($movement->getWithdrawal() === $this) {
  268.                 $movement->setWithdrawal(null);
  269.             }
  270.         }
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection<int, File>
  275.      */
  276.     public function getAttachments(): Collection
  277.     {
  278.         return $this->attachments;
  279.     }
  280.     public function addAttachment(File $attachment): self
  281.     {
  282.         if (!$this->attachments->contains($attachment)) {
  283.             $this->attachments->add($attachment);
  284.         }
  285.         return $this;
  286.     }
  287.     public function removeAttachment(File $attachment): self
  288.     {
  289.         $this->attachments->removeElement($attachment);
  290.         return $this;
  291.     }
  292.     /**
  293.      * @return Collection<int, Observation>
  294.      */
  295.     public function getObservations(): Collection
  296.     {
  297.         return $this->observations;
  298.     }
  299.     public function addObservation(Observation $observation): self
  300.     {
  301.         if (!$this->observations->contains($observation)) {
  302.             $this->observations->add($observation);
  303.             $observation->setWithdrawal($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeObservation(Observation $observation): self
  308.     {
  309.         if ($this->observations->removeElement($observation)) {
  310.             // set the owning side to null (unless already changed)
  311.             if ($observation->getWithdrawal() === $this) {
  312.                 $observation->setWithdrawal(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317. }