src/Entity/Delete/Box.php line 60

  1. <?php
  2. namespace App\Entity\Delete;
  3. use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter;
  4. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  5. use ApiPlatform\Metadata\ApiFilter;
  6. use ApiPlatform\Metadata\ApiProperty;
  7. use ApiPlatform\Metadata\ApiResource;
  8. use ApiPlatform\Metadata\GetCollection;
  9. use ApiPlatform\Metadata\Link;
  10. use App\Doctrine\Type\Expediting\CasingMaterial;
  11. use App\Doctrine\Type\Expediting\CasingType;
  12. use App\Dto\Delete\BoxInput;
  13. use App\Dto\Expediting\ItemsListInput;
  14. use App\Entity\Common as Common;
  15. use App\Entity\Identity\User;
  16. use App\Processor\Delete\BoxInputProcessor;
  17. use App\Service\Common\ItemsListHelper;
  18. use App\Validator\IsValidEnum\IsValidEnum;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\DBAL\Types\Types;
  22. use Doctrine\ORM\Mapping as ORM;
  23. use Gedmo\Mapping\Annotation as Gedmo;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. #[ORM\Table(name'expediting_z_box')]
  26. #[ORM\Index(columns: ['batch'], name'expediting_z_box_batch_idx')]
  27. #[ORM\Index(columns: ['container_id'], name'expediting_z_container_id_idx')]
  28. #[ORM\Index(columns: ['repacking_id'], name'expediting_z_repacking_id_idx')]
  29. #[ORM\Index(columns: ['order_numbers'], name'expediting_z_box_order_numbers_idx')]
  30. #[ORM\UniqueConstraint(name'expediting_z_box_reference_key'columns: ['reference'])]
  31. #[ORM\UniqueConstraint(name'expediting_z_box_slug_key'columns: ['slug'])]
  32. #[ORM\Entity]
  33. #[ApiResource(
  34.     routePrefix'/xpediting',
  35.     inputBoxInput::class,
  36.     processorBoxInputProcessor::class,
  37. )]
  38. #[ApiResource(
  39.     uriTemplate'/containers/{slug}/observations',
  40.     operations: [new GetCollection()],
  41.     uriVariables: [
  42.         'slug' => new Link(fromProperty'boxes'fromClassContainer::class),
  43.     ],
  44.     routePrefix'/xpediting',
  45. )]
  46. #[ApiFilter(SearchFilter::class, properties: [
  47.     'vendor' => 'ipartial',
  48.     'reference' => 'ipartial',
  49.     'orderNumbers' => 'ipartial',
  50.     'batchReference' => 'ipartial',
  51.     'pickupCountryCode' => 'exact',
  52.     'hub' => 'exact',
  53. ])]
  54. #[ApiFilter(ExistsFilter::class, properties: [
  55.     'repacking',
  56. ])]
  57. class Box
  58. {
  59.     use Common\Blameable;
  60.     use Common\Trackable;
  61.     #[ORM\Id]
  62.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  63.     #[ORM\SequenceGenerator(sequenceName'expediting_z_box_id_seq')]
  64.     #[ORM\Column(typeTypes::INTEGER)]
  65.     #[ApiProperty(identifierfalse)]
  66.     private int $id;
  67.     #[ORM\ManyToOne(targetEntityContainer::class, inversedBy'boxes')]
  68.     #[ORM\JoinColumn(name'container_id')]
  69.     private ?Container $container null;
  70.     #[Gedmo\Slug(fields: ['reference'])]
  71.     #[ORM\Column(typeTypes::STRING)]
  72.     #[ApiProperty(identifiertrue)]
  73.     private string $slug;
  74.     #[Assert\NotBlank]
  75.     #[Assert\Type(typeTypes::STRING)]
  76.     #[ORM\Column(typeTypes::STRING)]
  77.     private ?string $reference null;
  78.     #[Assert\Type(typeTypes::STRING)]
  79.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  80.     private ?string $orderNumbers null;
  81.     #[Assert\Type(typeTypes::STRING)]
  82.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  83.     private ?string $pickupCountryCode null;
  84.     #[Assert\Type(typeTypes::STRING)]
  85.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  86.     private ?string $vendor null;
  87.     #[Assert\NotNull]
  88.     #[Assert\Type(typeTypes::STRING)]
  89.     #[ORM\Column(name'batch'typeTypes::STRINGnullabletrue)]
  90.     private ?string $batchReference 'AVAILABLE';
  91.     #[Assert\Type(typeTypes::STRING)]
  92.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  93.     private ?string $hub null;
  94.     #[Assert\Type(typeTypes::BOOLEAN)]
  95.     #[ORM\Column(typeTypes::BOOLEANnullabletrue)]
  96.     private ?bool $jv false;
  97.     #[Assert\Type(typeTypes::BOOLEAN)]
  98.     #[ORM\Column(typeTypes::BOOLEANnullabletrue)]
  99.     private ?bool $dg false;
  100.     #[IsValidEnum(enumCasingType::class)]
  101.     #[ORM\Column(typeTypes::STRINGnullabletrueenumTypeCasingType::class)]
  102.     private ?CasingType $casingType null;
  103.     #[IsValidEnum(enumCasingMaterial::class)]
  104.     #[ORM\Column(typeTypes::STRINGnullabletrueenumTypeCasingMaterial::class)]
  105.     private ?CasingMaterial $casingMaterial null;
  106.     #[Assert\Type(typeTypes::FLOAT)]
  107.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  108.     private ?float $length null;
  109.     #[Assert\Type(typeTypes::FLOAT)]
  110.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  111.     private ?float $width null;
  112.     #[Assert\Type(typeTypes::FLOAT)]
  113.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  114.     private ?float $height null;
  115.     #[Assert\Type(typeTypes::FLOAT)]
  116.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  117.     private ?float $weight null;
  118.     #[Assert\Type(typeTypes::FLOAT)]
  119.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  120.     private ?float $shippingWeight null;
  121.     #[Assert\Type(typeTypes::FLOAT)]
  122.     #[ORM\Column(typeTypes::DECIMALprecision18scale2nullabletrue)]
  123.     private ?float $value null;
  124.     #[ORM\ManyToOne(targetEntityBox::class, inversedBy'packages')]
  125.     #[ORM\JoinColumn(name'repacking_id'referencedColumnName'id')]
  126.     private ?Box $repacking null;
  127.     #[ORM\OneToMany(mappedBy'repacking'targetEntityBox::class)]
  128.     private Collection $packages;
  129.     #[Assert\Valid]
  130.     #[Assert\Type(typeItems::class)]
  131.     #[ORM\Column(type'json_document'options: ['jsonb' => true])]
  132.     private ?Items $items null;
  133.     #[Gedmo\Blameable(on'create')]
  134.     #[ORM\ManyToOne(targetEntityUser::class)]
  135.     #[ORM\JoinColumn(name'created_by'nullabletrue)]
  136.     protected ?User $createdBy null;
  137.     public function __construct()
  138.     {
  139.         $this->packages = new ArrayCollection();
  140.     }
  141.     public function getId(): ?int
  142.     {
  143.         return $this->id;
  144.     }
  145.     public function getContainer(): ?Container
  146.     {
  147.         return $this->container;
  148.     }
  149.     public function setContainer(?Container $container): static
  150.     {
  151.         $this->container $container;
  152.         return $this;
  153.     }
  154.     public function getSlug(): ?string
  155.     {
  156.         return $this->slug;
  157.     }
  158.     public function setSlug(?string $slug): static
  159.     {
  160.         $this->slug $slug;
  161.         return $this;
  162.     }
  163.     public function getReference(): ?string
  164.     {
  165.         return $this->reference;
  166.     }
  167.     public function setReference(?string $reference): static
  168.     {
  169.         $this->reference $reference;
  170.         return $this;
  171.     }
  172.     public function getOrderNumbers(): ?string
  173.     {
  174.         return $this->orderNumbers;
  175.     }
  176.     public function setOrderNumbers(?string $orderNumbers): static
  177.     {
  178.         $this->orderNumbers $orderNumbers;
  179.         return $this;
  180.     }
  181.     public function getPickupCountryCode(): ?string
  182.     {
  183.         return $this->pickupCountryCode;
  184.     }
  185.     public function setPickupCountryCode(?string $pickupCountryCode): static
  186.     {
  187.         $this->pickupCountryCode $pickupCountryCode;
  188.         return $this;
  189.     }
  190.     public function getVendor(): ?string
  191.     {
  192.         return $this->vendor;
  193.     }
  194.     public function setVendor(?string $vendor): static
  195.     {
  196.         $this->vendor $vendor;
  197.         return $this;
  198.     }
  199.     public function getBatchReference(): ?string
  200.     {
  201.         return $this->batchReference;
  202.     }
  203.     public function setBatchReference(?string $batchReference): static
  204.     {
  205.         $this->batchReference null === $batchReference
  206.             'AVAILABLE'
  207.             $batchReference;
  208.         return $this;
  209.     }
  210.     public function getHub(): ?string
  211.     {
  212.         return $this->hub;
  213.     }
  214.     public function setHub(?string $hub): static
  215.     {
  216.         $this->hub $hub;
  217.         return $this;
  218.     }
  219.     public function isJv(): ?bool
  220.     {
  221.         return $this->jv;
  222.     }
  223.     public function setJv(?bool $jv): static
  224.     {
  225.         $this->jv $jv;
  226.         return $this;
  227.     }
  228.     public function isDg(): ?bool
  229.     {
  230.         return $this->dg;
  231.     }
  232.     public function setDg(?bool $dg): static
  233.     {
  234.         $this->dg $dg;
  235.         return $this;
  236.     }
  237.     public function getCasingType(): ?CasingType
  238.     {
  239.         return $this->casingType;
  240.     }
  241.     public function setCasingType(?CasingType $casingType): static
  242.     {
  243.         $this->casingType $casingType;
  244.         return $this;
  245.     }
  246.     public function getCasingMaterial(): ?CasingMaterial
  247.     {
  248.         return $this->casingMaterial;
  249.     }
  250.     public function setCasingMaterial(?CasingMaterial $casingMaterial): static
  251.     {
  252.         $this->casingMaterial $casingMaterial;
  253.         return $this;
  254.     }
  255.     public function getLength(): ?float
  256.     {
  257.         return $this->length;
  258.     }
  259.     public function setLength(?float $length): static
  260.     {
  261.         $this->length $length;
  262.         return $this;
  263.     }
  264.     public function getWidth(): ?float
  265.     {
  266.         return $this->width;
  267.     }
  268.     public function setWidth(?float $width): static
  269.     {
  270.         $this->width $width;
  271.         return $this;
  272.     }
  273.     public function getHeight(): ?float
  274.     {
  275.         return $this->height;
  276.     }
  277.     public function setHeight(?float $height): static
  278.     {
  279.         $this->height $height;
  280.         return $this;
  281.     }
  282.     public function getVolume(): ?float
  283.     {
  284.         return ($this->length $this->width $this->height) / 1_000_000;
  285.     }
  286.     public function getWeight(): ?float
  287.     {
  288.         return $this->weight;
  289.     }
  290.     public function setWeight(?float $weight): static
  291.     {
  292.         $this->weight $weight;
  293.         return $this;
  294.     }
  295.     public function getShippingWeight(): ?float
  296.     {
  297.         return $this->shippingWeight;
  298.     }
  299.     public function setShippingWeight(?float $shippingWeight): static
  300.     {
  301.         $this->shippingWeight $shippingWeight;
  302.         return $this;
  303.     }
  304.     public function getValue(): ?float
  305.     {
  306.         return $this->value;
  307.     }
  308.     public function setValue(?float $value): static
  309.     {
  310.         $this->value $value;
  311.         return $this;
  312.     }
  313.     public function getItemsLists(): array
  314.     {
  315.         $items = [];
  316.         foreach ($this->items->items as $item) {
  317.             if (!isset($items[$item->orderNumber])) {
  318.                 $items[$item->orderNumber] = [
  319.                     'list' => [],
  320.                     'containsDangerousGood' => false,
  321.                 ];
  322.             }
  323.             if ($item->isDangerous) {
  324.                 $items[$item->orderNumber]['containsDangerousGood'] = true;
  325.             }
  326.             $items[$item->orderNumber]['list'] []= $item->number;
  327.         }
  328.         $itemsLists = [];
  329.         foreach ($items as $orderNumber => $orderData) {
  330.             $itemsLists []= new ItemsListInput(
  331.                 orderNumber$orderNumber,
  332.                 itemsListItemsListHelper::normalize($orderData['list']),
  333.                 containsDangerousGoods$orderData['containsDangerousGood'],
  334.             );
  335.         }
  336.         return $itemsLists;
  337.     }
  338.     public function getContainsDangerousGood(): bool
  339.     {
  340.         foreach ($this->items->items as $item) {
  341.             if ($item->isDangerous) {
  342.                 return true;
  343.             }
  344.         }
  345.         return false;
  346.     }
  347.     public function getRepacking(): ?self
  348.     {
  349.         return $this->repacking;
  350.     }
  351.     public function setRepacking(?self $repacking): self
  352.     {
  353.         $this->repacking $repacking;
  354.         return $this;
  355.     }
  356.     /** @return Collection<int, Box> */
  357.     public function getPackages(): Collection
  358.     {
  359.         return $this->packages;
  360.     }
  361.     public function addPackage(Box $package): self
  362.     {
  363.         if (!$this->packages->contains($package)) {
  364.             $this->packages->add($package);
  365.             $package->setRepacking($this);
  366.         }
  367.         return $this;
  368.     }
  369.     public function removePackage(Box $package): self
  370.     {
  371.         if ($this->packages->removeElement($package)) {
  372.             // set the owning side to null (unless already changed)
  373.             if ($package->getRepacking() === $this) {
  374.                 $package->setRepacking(null);
  375.             }
  376.         }
  377.         return $this;
  378.     }
  379.     public function getItems(): ?Items
  380.     {
  381.         return $this->items;
  382.     }
  383.     public function setItems(?Items $Items): static
  384.     {
  385.         $this->items $Items;
  386.         return $this;
  387.     }
  388. }