src/Entity/Delete/Batch.php line 73

  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 App\Doctrine\Type\Expediting\ContainerSize;
  14. use App\Doctrine\Type\Expediting\TransportMode;
  15. use App\Dto\Common\ObservationInput;
  16. use App\Dto\Delete\BatchInput;
  17. use App\Dto\Delete\BatchStatusUpdateInput;
  18. use App\Dto\Delete\CurrenciesOutput;
  19. use App\Dto\Delete\KitRequestInput;
  20. use App\Entity\Common as Common;
  21. use App\Entity\Common\Observation;
  22. use App\Entity\Identity\User;
  23. use App\Processor\Delete\BatchInputProcessor;
  24. use App\Processor\Delete\BatchObservationProcessor;
  25. use App\Processor\Delete\BatchStatusProcessor;
  26. use App\Processor\Delete\KitRequestProcessor;
  27. use App\Provider\Delete\BatchCurrenciesProvider;
  28. use App\Provider\Delete\BatchProvider;
  29. use App\Validator\IsValidEnum\IsValidEnum;
  30. use DateTimeInterface;
  31. use Doctrine\Common\Collections\ArrayCollection;
  32. use Doctrine\Common\Collections\Collection;
  33. use Doctrine\DBAL\Types\Types;
  34. use Doctrine\ORM\Mapping as ORM;
  35. use Gedmo\Mapping\Annotation as Gedmo;
  36. use Symfony\Component\Validator\Constraints as Assert;
  37. #[ORM\Table(name'expediting_z_batch')]
  38. #[ORM\Index(columns: ['created_by'], name'expediting_z_batch_created_by_idx')]
  39. #[ORM\Index(columns: ['updated_by'], name'expediting_z_batch_updated_by_idx')]
  40. #[ORM\UniqueConstraint(name'expediting_z_batch_slug_key'columns: ['slug'])]
  41. #[ORM\UniqueConstraint(name'expediting_z_batch_reference_key'columns: ['reference'])]
  42. #[ORM\Entity]
  43. #[ApiResource(
  44.     operations: [
  45.         new Get(providerBatchProvider::class),
  46.         new Get(uriTemplate'/batches/{slug}/currencies' ,outputCurrenciesOutput::class, providerBatchCurrenciesProvider::class),
  47.         new GetCollection(),
  48.         new Post(uriTemplate'/batches/{slug}/update'inputBatchStatusUpdateInput::class, processorBatchStatusProcessor::class),
  49.         new Post(uriTemplate'/batches/{slug}/prepare'inputKitRequestInput::class, processorKitRequestProcessor::class),
  50.         new Post(),
  51.         new Patch(),
  52.         new Put(),
  53.         new Delete(),
  54.         new Post(
  55.             uriTemplate'/batches/{slug}/observations',
  56.             inputObservationInput::class,
  57.             processorBatchObservationProcessor::class
  58.         ),
  59.     ],
  60.     routePrefix'/xpediting',
  61.     inputBatchInput::class,
  62.     order: ['id' => 'DESC'],
  63.     processorBatchInputProcessor::class,
  64. )]
  65. #[ApiFilter(SearchFilter::class, properties: [
  66.     'reference' => 'ipartial',
  67.     'transportMode' => 'exact',
  68. ])]
  69. class Batch
  70. {
  71.     use Common\Blameable;
  72.     use Common\Trackable;
  73.     #[ORM\Id]
  74.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  75.     #[ORM\SequenceGenerator(sequenceName'expediting_z_batch_id_seq')]
  76.     #[ORM\Column(typeTypes::INTEGER)]
  77.     #[ApiProperty(identifierfalse)]
  78.     private int $id;
  79.     #[Gedmo\Slug(fields: ['reference'])]
  80.     #[ORM\Column(typeTypes::STRING)]
  81.     #[ApiProperty(identifiertrue)]
  82.     private string $slug;
  83.     #[Assert\NotBlank]
  84.     #[Assert\Type(typeTypes::STRING)]
  85.     #[ORM\Column(typeTypes::STRING)]
  86.     private ?string $reference null;
  87.     #[Assert\Type(typeTypes::BOOLEAN)]
  88.     #[ORM\Column(typeTypes::BOOLEANnullabletrue)]
  89.     private ?bool $jv null;
  90.     #[Assert\Type(typeTypes::BOOLEAN)]
  91.     #[ORM\Column(typeTypes::BOOLEANnullabletrue)]
  92.     private ?bool $dg null;
  93.     #[Assert\NotNull]
  94.     #[IsValidEnum(enumTransportMode::class)]
  95.     #[ORM\Column(typeTypes::STRINGenumTypeTransportMode::class)]
  96.     private ?TransportMode $transportMode null;
  97.     #[Assert\Type(typeTypes::STRING)]
  98.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  99.     private ?string $carrier null;
  100.     #[Assert\Type(typeTypes::STRING)]
  101.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  102.     private ?string $vessel null;
  103.     #[Assert\Type(typeTypes::STRING)]
  104.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  105.     private ?string $billNumber null;
  106.     #[Assert\Type(typeTypes::STRING)]
  107.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  108.     private ?string $bookingNumber null;
  109.     #[Assert\Type(typeTypes::STRING)]
  110.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  111.     private ?string $vectorReference null;
  112.     #[Assert\Type(typeTypes::STRING)]
  113.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  114.     private ?string $placeOfLoading null;
  115.     #[Assert\Type(typeTypes::STRING)]
  116.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  117.     private ?string $placeOfDischarge null;
  118.     #[Assert\NotBlank]
  119.     #[Assert\Type(typeTypes::STRING)]
  120.     #[ORM\Column(typeTypes::STRING)]
  121.     private ?string $departureCountryCode null;
  122.     #[Assert\Type(typeTypes::STRING)]
  123.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  124.     private ?string $hubCountryCode null;
  125.     #[Assert\Type(typeTypes::STRING)]
  126.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  127.     private ?string $description null;
  128.     #[Assert\Valid]
  129.     #[Assert\Type(typeParty::class)]
  130.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  131.     private Party $buyer;
  132.     #[Assert\Valid]
  133.     #[Assert\Type(typeParty::class)]
  134.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  135.     private Party $shipper;
  136.     #[Assert\Valid]
  137.     #[Assert\Type(typeParty::class)]
  138.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  139.     private Party $consignee;
  140.     #[Assert\Valid]
  141.     #[Assert\Type(typeParty::class)]
  142.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  143.     private Party $notifyParty;
  144.     #[Assert\Valid]
  145.     #[Assert\Type(typeWaybill::class)]
  146.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  147.     private Waybill $waybill;
  148.     #[Assert\Valid]
  149.     #[Assert\Type(typeMetadata::class)]
  150.     #[ORM\Column(type'json_document'nullabletrueoptions: ['jsonb' => true])]
  151.     private Metadata $metadata;
  152.     #[Assert\Type(typeTypes::STRING)]
  153.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  154.     private ?string $formM null;
  155.     #[Assert\Type(typeTypes::STRING)]
  156.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  157.     private ?string $baNumber null;
  158.     #[Assert\Type(typeTypes::FLOAT)]
  159.     #[ORM\Column(typeTypes::DECIMALprecision18scale2nullabletrue)]
  160.     private ?float $weight null;
  161.     #[Assert\Type(typeTypes::FLOAT)]
  162.     #[ORM\Column(typeTypes::DECIMALprecision18scale2nullabletrue)]
  163.     private ?float $volume null;
  164.     #[Assert\Type(typeTypes::FLOAT)]
  165.     #[ORM\Column(typeTypes::DECIMALprecision18scale2nullabletrue)]
  166.     private ?float $value null;
  167.     #[Assert\Type(typeTypes::FLOAT)]
  168.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  169.     private ?float $pickupCost null;
  170.     #[Assert\Type(typeTypes::FLOAT)]
  171.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  172.     private ?float $freightCost null;
  173.     #[Assert\Type(typeDateTimeInterface::class)]
  174.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  175.     private ?DateTimeInterface $greenLitOn null;
  176.     #[Assert\Type(typeDateTimeInterface::class)]
  177.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  178.     private ?DateTimeInterface $bookedOn null;
  179.     #[Assert\Type(typeDateTimeInterface::class)]
  180.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  181.     private ?DateTimeInterface $etd null;
  182.     #[Assert\Type(typeDateTimeInterface::class)]
  183.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  184.     private ?DateTimeInterface $atd null;
  185.     #[Assert\Type(typeDateTimeInterface::class)]
  186.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  187.     private ?DateTimeInterface $eta null;
  188.     #[Assert\Type(typeDateTimeInterface::class)]
  189.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  190.     private ?DateTimeInterface $ata null;
  191.     #[Assert\Type(typeDateTimeInterface::class)]
  192.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  193.     private ?DateTimeInterface $customsOn null;
  194.     #[Assert\Type(typeDateTimeInterface::class)]
  195.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  196.     private ?DateTimeInterface $deliveredOn null;
  197.     #[Gedmo\Blameable(on'create')]
  198.     #[ORM\ManyToOne(targetEntityUser::class)]
  199.     #[ORM\JoinColumn(name'created_by'nullabletrue)]
  200.     protected ?User $createdBy null;
  201.     /** @var Collection<int, Container> */
  202.     #[ORM\OneToMany(mappedBy'batch'targetEntityContainer::class, cascade: ['persist''remove'])]
  203.     private Collection $containers;
  204.     /** @var Collection<int, Movement> */
  205.     #[ORM\OneToMany(mappedBy'batch'targetEntityMovement::class, cascade: ['persist''remove'])]
  206.     private Collection $movements;
  207.     /** @var Collection<int, Observation> */
  208.     #[ORM\OneToMany(mappedBy'batch'targetEntityObservation::class, cascade: ['persist''remove'])]
  209.     private Collection $observations;
  210.     public $kitStatus null;
  211.     public function __construct()
  212.     {
  213.         $this->metadata = new Metadata();
  214.         $this->containers = new ArrayCollection();
  215.         $this->movements = new ArrayCollection();
  216.         $this->observations = new ArrayCollection();
  217.     }
  218.     public function getId(): ?int
  219.     {
  220.         return $this->id;
  221.     }
  222.     public function getSlug(): ?string
  223.     {
  224.         return $this->slug;
  225.     }
  226.     public function setSlug(?string $slug): static
  227.     {
  228.         $this->slug $slug;
  229.         return $this;
  230.     }
  231.     public function getReference(): ?string
  232.     {
  233.         return $this->reference;
  234.     }
  235.     public function setReference(?string $reference): static
  236.     {
  237.         $this->reference $reference;
  238.         return $this;
  239.     }
  240.     public function isJv(): ?bool
  241.     {
  242.         return $this->jv;
  243.     }
  244.     public function setJv(?bool $jv): static
  245.     {
  246.         $this->jv $jv;
  247.         return $this;
  248.     }
  249.     public function isDg(): ?bool
  250.     {
  251.         return $this->dg;
  252.     }
  253.     public function setDg(?bool $dg): static
  254.     {
  255.         $this->dg $dg;
  256.         return $this;
  257.     }
  258.     public function isBreakBulk(): ?bool
  259.     {
  260.         return empty(count($this->containers));
  261.     }
  262.     public function getTransportMode(): ?TransportMode
  263.     {
  264.         return $this->transportMode;
  265.     }
  266.     public function setTransportMode(?TransportMode $transportMode): static
  267.     {
  268.         $this->transportMode $transportMode;
  269.         return $this;
  270.     }
  271.     public function getCarrier(): ?string
  272.     {
  273.         return $this->carrier;
  274.     }
  275.     public function setCarrier(?string $carrier): static
  276.     {
  277.         $this->carrier $carrier;
  278.         return $this;
  279.     }
  280.     public function getVessel(): ?string
  281.     {
  282.         return $this->vessel;
  283.     }
  284.     public function setVessel(?string $vessel): static
  285.     {
  286.         $this->vessel $vessel;
  287.         return $this;
  288.     }
  289.     public function getBillNumber(): ?string
  290.     {
  291.         return $this->billNumber;
  292.     }
  293.     public function setBillNumber(?string $billNumber): static
  294.     {
  295.         $this->billNumber $billNumber;
  296.         return $this;
  297.     }
  298.     public function getBookingNumber(): ?string
  299.     {
  300.         return $this->bookingNumber;
  301.     }
  302.     public function setBookingNumber(?string $bookingNumber): static
  303.     {
  304.         $this->bookingNumber $bookingNumber;
  305.         return $this;
  306.     }
  307.     public function getVectorReference(): ?string
  308.     {
  309.         return $this->vectorReference;
  310.     }
  311.     public function setVectorReference(?string $vectorReference): static
  312.     {
  313.         $this->vectorReference $vectorReference;
  314.         return $this;
  315.     }
  316.     public function getPlaceOfLoading(): ?string
  317.     {
  318.         return $this->placeOfLoading;
  319.     }
  320.     public function setPlaceOfLoading(?string $placeOfLoading): static
  321.     {
  322.         $this->placeOfLoading $placeOfLoading;
  323.         return $this;
  324.     }
  325.     public function getPlaceOfDischarge(): ?string
  326.     {
  327.         return $this->placeOfDischarge;
  328.     }
  329.     public function setPlaceOfDischarge(?string $placeOfDischarge): static
  330.     {
  331.         $this->placeOfDischarge $placeOfDischarge;
  332.         return $this;
  333.     }
  334.     public function getDepartureCountryCode(): ?string
  335.     {
  336.         return $this->departureCountryCode;
  337.     }
  338.     public function setDepartureCountryCode(?string $departureCountryCode): static
  339.     {
  340.         $this->departureCountryCode $departureCountryCode;
  341.         return $this;
  342.     }
  343.     public function getHubCountryCode(): ?string
  344.     {
  345.         return $this->hubCountryCode;
  346.     }
  347.     public function setHubCountryCode(?string $hubCountryCode): static
  348.     {
  349.         $this->hubCountryCode $hubCountryCode;
  350.         return $this;
  351.     }
  352.     public function getDescription(): ?string
  353.     {
  354.         return $this->description;
  355.     }
  356.     public function setDescription(?string $description): static
  357.     {
  358.         $this->description $description;
  359.         return $this;
  360.     }
  361.     public function getBuyer(): Party
  362.     {
  363.         return $this->buyer;
  364.     }
  365.     public function setBuyer(?Party $buyer): static
  366.     {
  367.         $this->buyer $buyer;
  368.         return $this;
  369.     }
  370.     public function getShipper(): ?Party
  371.     {
  372.         return $this->shipper;
  373.     }
  374.     public function setShipper(?Party $shipper): static
  375.     {
  376.         $this->shipper $shipper;
  377.         return $this;
  378.     }
  379.     public function getConsignee(): ?Party
  380.     {
  381.         return $this->consignee;
  382.     }
  383.     public function setConsignee(?Party $consignee): static
  384.     {
  385.         $this->consignee $consignee;
  386.         return $this;
  387.     }
  388.     public function getNotifyParty(): Party
  389.     {
  390.         return $this->notifyParty;
  391.     }
  392.     public function setNotifyParty(?Party $notifyParty): static
  393.     {
  394.         $this->notifyParty $notifyParty;
  395.         return $this;
  396.     }
  397.     public function getWaybill(): Waybill
  398.     {
  399.         return $this->waybill ?? new Waybill();
  400.     }
  401.     public function setWaybill(?Waybill $waybill): static
  402.     {
  403.         $this->waybill $waybill;
  404.         return $this;
  405.     }
  406.     public function getFormM(): ?string
  407.     {
  408.         return $this->formM;
  409.     }
  410.     public function setFormM(?string $formM): static
  411.     {
  412.         $this->formM $formM;
  413.         return $this;
  414.     }
  415.     public function getBaNumber(): ?string
  416.     {
  417.         return $this->baNumber;
  418.     }
  419.     public function setBaNumber(?string $baNumber): static
  420.     {
  421.         $this->baNumber $baNumber;
  422.         return $this;
  423.     }
  424.     public function getWeight(): ?float
  425.     {
  426.         return $this->weight;
  427.     }
  428.     public function setWeight(?float $weight): static
  429.     {
  430.         $this->weight $weight;
  431.         return $this;
  432.     }
  433.     public function getVolume(): ?float
  434.     {
  435.         return $this->volume;
  436.     }
  437.     public function setVolume(?float $volume): static
  438.     {
  439.         $this->volume $volume;
  440.         return $this;
  441.     }
  442.     public function getValue(): ?float
  443.     {
  444.         return $this->value;
  445.     }
  446.     public function setValue(?float $value): static
  447.     {
  448.         $this->value $value;
  449.         return $this;
  450.     }
  451.     public function getPickupCost(): ?float
  452.     {
  453.         return $this->pickupCost;
  454.     }
  455.     public function setPickupCost(?float $pickupCost): static
  456.     {
  457.         $this->pickupCost $pickupCost;
  458.         return $this;
  459.     }
  460.     public function getFreightCost(): ?float
  461.     {
  462.         if (!empty($this->freightCost) && $this->getContainers()?->isEmpty()) {
  463.             return $this->freightCost;
  464.         }
  465.         $freightCost 0;
  466.         foreach ($this->containers as $container) {
  467.             $freightCost += $container->getContainerSize() === ContainerSize::SIZE_20
  468.             8000
  469.             15000;
  470.         }
  471.         return $freightCost;
  472.     }
  473.     public function setFreightCost(?float $freightCost): static
  474.     {
  475.         $this->freightCost $freightCost;
  476.         return $this;
  477.     }
  478.     public function getGreenLitOn(): ?DateTimeInterface
  479.     {
  480.         return $this->greenLitOn;
  481.     }
  482.     public function setGreenLitOn(?DateTimeInterface $greenLitOn): static
  483.     {
  484.         $this->greenLitOn $greenLitOn;
  485.         return $this;
  486.     }
  487.     public function getBookedOn(): ?DateTimeInterface
  488.     {
  489.         return $this->bookedOn;
  490.     }
  491.     public function setBookedOn(?DateTimeInterface $bookedOn): static
  492.     {
  493.         $this->bookedOn $bookedOn;
  494.         return $this;
  495.     }
  496.     public function getEtd(): ?DateTimeInterface
  497.     {
  498.         return $this->etd;
  499.     }
  500.     public function setEtd(?DateTimeInterface $etd): static
  501.     {
  502.         $this->etd $etd;
  503.         return $this;
  504.     }
  505.     public function getAtd(): ?DateTimeInterface
  506.     {
  507.         return $this->atd;
  508.     }
  509.     public function setAtd(?DateTimeInterface $atd): static
  510.     {
  511.         $this->atd $atd;
  512.         return $this;
  513.     }
  514.     public function getEta(): ?DateTimeInterface
  515.     {
  516.         return $this->eta;
  517.     }
  518.     public function setEta(?DateTimeInterface $eta): static
  519.     {
  520.         $this->eta $eta;
  521.         return $this;
  522.     }
  523.     public function getAta(): ?DateTimeInterface
  524.     {
  525.         return $this->ata;
  526.     }
  527.     public function setAta(?DateTimeInterface $ata): static
  528.     {
  529.         $this->ata $ata;
  530.         return $this;
  531.     }
  532.     public function getCustomsOn(): ?DateTimeInterface
  533.     {
  534.         return $this->customsOn;
  535.     }
  536.     public function setCustomsOn(?DateTimeInterface $customsOn): static
  537.     {
  538.         $this->customsOn $customsOn;
  539.         return $this;
  540.     }
  541.     public function getDeliveredOn(): ?DateTimeInterface
  542.     {
  543.         return $this->deliveredOn;
  544.     }
  545.     public function setDeliveredOn(?DateTimeInterface $deliveredOn): static
  546.     {
  547.         $this->deliveredOn $deliveredOn;
  548.         return $this;
  549.     }
  550.     public function getMetadata(): Metadata
  551.     {
  552.         return $this->metadata ?? new Metadata();
  553.     }
  554.     public function setMetadata(?Metadata $metadata): static
  555.     {
  556.         $this->metadata $metadata;
  557.         return $this;
  558.     }
  559.     /** @return Collection<int, Container> */
  560.     public function getContainers(): Collection
  561.     {
  562.         return $this->containers;
  563.     }
  564.     public function addContainer(Container $container): static
  565.     {
  566.         if (!$this->containers->contains($container)) {
  567.             $this->containers->add($container);
  568.             $container->setBatch($this);
  569.         }
  570.         return $this;
  571.     }
  572.     public function removeContainer(Container $container): static
  573.     {
  574.         if ($this->containers->removeElement($container)) {
  575.             // set the owning side to null (unless already changed)
  576.             if ($container->getBatch() === $this) {
  577.                 $container->setBatch(null);
  578.             }
  579.         }
  580.         return $this;
  581.     }
  582.     /** @return Collection<int, Movement> */
  583.     public function getMovements(): Collection
  584.     {
  585.         return $this->movements;
  586.     }
  587.     public function addMovement(Movement $movement): static
  588.     {
  589.         if (!$this->movements->contains($movement)) {
  590.             $this->movements->add($movement);
  591.             $movement->setBatch($this);
  592.         }
  593.         return $this;
  594.     }
  595.     public function removeMovement(Movement $movement): static
  596.     {
  597.         if ($this->movements->removeElement($movement)) {
  598.             // set the owning side to null (unless already changed)
  599.             if ($movement->getBatch() === $this) {
  600.                 $movement->setBatch(null);
  601.             }
  602.         }
  603.         return $this;
  604.     }
  605.     /**
  606.      * @return Collection<int, Observation>
  607.      */
  608.     public function getObservations(): Collection
  609.     {
  610.         return $this->observations;
  611.     }
  612.     public function addObservation(Observation $observation): self
  613.     {
  614.         if (!$this->observations->contains($observation)) {
  615.             $this->observations->add($observation);
  616.             $observation->setBatch($this);
  617.         }
  618.         return $this;
  619.     }
  620.     public function removeObservation(Observation $observation): self
  621.     {
  622.         if ($this->observations->removeElement($observation)) {
  623.             // set the owning side to null (unless already changed)
  624.             if ($observation->getBatch() === $this) {
  625.                 $observation->setBatch(null);
  626.             }
  627.         }
  628.         return $this;
  629.     }
  630. }