src/Entity/Expediting/Freight.php line 73

  1. <?php
  2. namespace App\Entity\Expediting;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Link;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\OpenApi\Model;
  9. use App\Controller\Expediting\FreightDocumentUploadAction;
  10. use App\Entity\Common as Common;
  11. use App\Entity\File\File;
  12. use App\Entity\Purchasing\Order;
  13. use App\Entity\Sales\WorkOrder;
  14. use ArrayObject;
  15. use DateTimeInterface;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\DBAL\Types\Types;
  19. use Doctrine\ORM\Mapping as ORM;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  22. use Symfony\Component\Uid\Ulid;
  23. use Symfony\Component\Validator\Constraints as Assert;
  24. #[ORM\Table(name'expediting_freight')]
  25. #[ORM\Index(columns: ['order_id'], name'expediting_freight_order_id_idx')]
  26. #[ORM\Index(columns: ['work_order_id'], name'expediting_freight_work_order_id_idx')]
  27. #[ORM\Index(columns: ['created_by'], name'expediting_freight_created_by_idx')]
  28. #[ORM\Index(columns: ['updated_by'], name'expediting_freight_updated_by_idx')]
  29. #[ORM\UniqueConstraint(name'expediting_freight_identifier_key'columns: ['identifier'])]
  30. #[ORM\Entity]
  31. #[UniqueEntity(fields: ['identifier'])]
  32. #[ApiResource(routePrefix'/expediting')]
  33. #[ApiResource(
  34.     uriTemplate'/work_orders/{slug}/freights',
  35.     operations: [new GetCollection()],
  36.     uriVariables: [
  37.         'slug' => new Link(fromProperty'freights'fromClassWorkOrder::class),
  38.     ],
  39. )]
  40. #[ApiResource(
  41.     // FIXME : This does not work well with docker
  42.     uriTemplate'/freights/{slug}/attachments',
  43.     operations: [
  44.         new Post(
  45.             controllerFreightDocumentUploadAction::class,
  46.             openapi: new Model\Operation(
  47.                 requestBody: new Model\RequestBody(
  48.                     content: new ArrayObject([
  49.                         'multipart/form-data' => [
  50.                             'schema' => [
  51.                                 'type' => 'object',
  52.                                 'properties' => [
  53.                                     'file' => [
  54.                                         'type' => 'string',
  55.                                         'format' => 'binary'
  56.                                     ]
  57.                                 ]
  58.                             ]
  59.                         ]
  60.                     ])
  61.                 )
  62.             ),
  63.             shortName'Upload',
  64.             validationContext: ['groups' => ['Default''upload:create']],
  65.             deserializefalse,
  66.         ),
  67.     ],
  68.     routePrefix'/expediting',
  69. )]
  70. class Freight
  71. {
  72.     use Shippable;
  73.     use Common\Blameable;
  74.     use Common\Trackable;
  75.     #[ORM\Id]
  76.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  77.     #[ORM\SequenceGenerator(sequenceName'expediting_freight_id_seq')]
  78.     #[ORM\Column(typeTypes::INTEGER)]
  79.     #[ApiProperty(identifierfalse)]
  80.     private ?int $id null;
  81.     #[Gedmo\Slug(fields: ['reference'])]
  82.     #[ORM\Column(typeTypes::STRING)]
  83.     #[ApiProperty(identifiertrue)]
  84.     private ?string $slug null;
  85.     #[ORM\Column(typeTypes::STRING)]
  86.     private ?string $reference null;
  87.     #[Assert\Ulid]
  88.     #[Assert\NotNull]
  89.     #[ORM\Column(type'ulid'uniquetrue)]
  90.     private ?Ulid $identifier null;
  91.     #[ORM\ManyToOne(targetEntityWorkOrder::class, inversedBy'freights')]
  92.     #[ORM\JoinColumn(name'work_order_id'nullablefalse)]
  93.     private ?WorkOrder $workOrder null;
  94.     #[Assert\NotNull]
  95.     #[ORM\ManyToOne(targetEntityOrder::class, cascade: ['persist''remove'], inversedBy'freights')]
  96.     #[ORM\JoinColumn(name'order_id')]
  97.     private ?Order $order null;
  98.     #[Assert\NotNull]
  99.     #[Assert\Type(typeDateTimeInterface::class)]
  100.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  101.     private ?DateTimeInterface $availableOn null;
  102.     #[Assert\Type(typeTypes::FLOAT)]
  103.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  104.     private ?float $value null;
  105.     #[Assert\Type(typeTypes::STRING)]
  106.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  107.     private ?string $location null;
  108.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  109.     private ?array $invoicesNumbers = [];
  110.     #[Assert\Type(typeTypes::BOOLEAN)]
  111.     #[ORM\Column(typeTypes::BOOLEANnullabletrueoptions: ['default' => false])]
  112.     private ?bool $delayed false;
  113.     /** @var Collection<int, Item> */
  114.     #[ORM\OneToMany(mappedBy'freight'targetEntityItem::class, cascade: ['persist''remove'])]
  115.     private Collection $items;
  116.     /** @var Collection<int, File> */
  117.     #[ORM\ManyToMany(targetEntityFile::class, cascade: ['persist''remove'])]
  118.     #[ORM\JoinTable(name'expediting_freight_file_map')]
  119.     #[ORM\JoinColumn(name'freight_id')]
  120.     #[ORM\InverseJoinColumn(name'file_id')]
  121.     #[ORM\OrderBy(['id' => 'ASC'])]
  122.     private Collection $attachments;
  123.     public function __construct()
  124.     {
  125.         $this->identifier = new Ulid();
  126.         $this->items = new ArrayCollection();
  127.         $this->attachments = new ArrayCollection();
  128.     }
  129.     public function getId(): ?int
  130.     {
  131.         return $this->id;
  132.     }
  133.     public function getSlug(): ?string
  134.     {
  135.         return $this->slug;
  136.     }
  137.     public function setSlug(string $slug): self
  138.     {
  139.         $this->slug $slug;
  140.         return $this;
  141.     }
  142.     public function getReference(): ?string
  143.     {
  144.         return $this->reference;
  145.     }
  146.     public function setReference(string $reference): self
  147.     {
  148.         $this->reference $reference;
  149.         return $this;
  150.     }
  151.     public function getIdentifier(): ?Ulid
  152.     {
  153.         return $this->identifier;
  154.     }
  155.     public function setIdentifier(Ulid $identifier): self
  156.     {
  157.         $this->identifier $identifier;
  158.         return $this;
  159.     }
  160.     public function getAvailableOn(): ?DateTimeInterface
  161.     {
  162.         return $this->availableOn;
  163.     }
  164.     public function setAvailableOn(DateTimeInterface $availableOn): self
  165.     {
  166.         $this->availableOn $availableOn;
  167.         return $this;
  168.     }
  169.     public function getValue(): ?string
  170.     {
  171.         return $this->value;
  172.     }
  173.     public function setValue(?string $value): self
  174.     {
  175.         $this->value $value;
  176.         return $this;
  177.     }
  178.     public function getLocation(): ?string
  179.     {
  180.         return $this->location;
  181.     }
  182.     public function setLocation(?string $location): self
  183.     {
  184.         $this->location $location;
  185.         return $this;
  186.     }
  187.     public function isDelayed(): ?bool
  188.     {
  189.         return $this->delayed;
  190.     }
  191.     public function setDelayed(?bool $delayed): self
  192.     {
  193.         $this->delayed $delayed;
  194.         return $this;
  195.     }
  196.     public function getInvoicesNumbers(): ?array
  197.     {
  198.         return $this->invoicesNumbers;
  199.     }
  200.     public function addInvoiceNumber(string $invoiceNumber): self
  201.     {
  202.         $this->invoicesNumbers []= strtoupper($invoiceNumber);
  203.         $this->invoicesNumbers array_unique($this->invoicesNumbers);
  204.         return $this;
  205.     }
  206.     public function setInvoicesNumbers(?array $invoicesNumbers): self
  207.     {
  208.         $this->invoicesNumbers $invoicesNumbers;
  209.         return $this;
  210.     }
  211.     public function getWorkOrder(): ?WorkOrder
  212.     {
  213.         return $this->workOrder;
  214.     }
  215.     public function setWorkOrder(?WorkOrder $workOrder): self
  216.     {
  217.         $this->workOrder $workOrder;
  218.         return $this;
  219.     }
  220.     public function getOrder(): ?Order
  221.     {
  222.         return $this->order;
  223.     }
  224.     public function setOrder(?Order $order): self
  225.     {
  226.         $this->order $order;
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection<int, Item>
  231.      */
  232.     public function getItems(): Collection
  233.     {
  234.         return $this->items;
  235.     }
  236.     public function addItem(Item $item): self
  237.     {
  238.         if (!$this->items->contains($item)) {
  239.             $this->items->add($item);
  240.             $item->setFreight($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function removeItem(Item $item): self
  245.     {
  246.         if ($this->items->removeElement($item)) {
  247.             // set the owning side to null (unless already changed)
  248.             if ($item->getFreight() === $this) {
  249.                 $item->setFreight(null);
  250.             }
  251.         }
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return Collection<int, File>
  256.      */
  257.     public function getAttachments(): Collection
  258.     {
  259.         return $this->attachments;
  260.     }
  261.     public function addAttachment(File $attachment): self
  262.     {
  263.         if (!$this->attachments->contains($attachment)) {
  264.             $this->attachments->add($attachment);
  265.         }
  266.         return $this;
  267.     }
  268.     public function removeAttachment(File $attachment): self
  269.     {
  270.         $this->attachments->removeElement($attachment);
  271.         return $this;
  272.     }
  273. }