src/Entity/Expediting/ShippingSegment.php line 61

  1. <?php
  2. namespace App\Entity\Expediting;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use App\Doctrine\Type\Expediting\ShippingSegmentStatus;
  9. use App\Doctrine\Type\Expediting\ShipmentType;
  10. use App\Doctrine\Type\Expediting\TransportMode;
  11. use App\Doctrine\Type\Expediting\TransportSpecification;
  12. use App\Doctrine\Type\SelectableType;
  13. use App\Dto\Expediting\BookingInput;
  14. use App\Dto\Expediting\ShipmentStatusUpdateInput;
  15. use App\Entity\Common as Common;
  16. use App\Entity\Common\Company;
  17. use App\Entity\Fleet\Driver;
  18. use App\Entity\Fleet\Vehicle;
  19. use App\Entity\Inventory\PackageMovement;
  20. use App\Entity\Places\Facility;
  21. use App\Entity\Scheduler\Task;
  22. use App\Processor\Expediting\ShipmentBookingProcessor;
  23. use App\Processor\Expediting\ShipmentStatusProcessor;
  24. use App\Validator\IsValidEnum\IsValidEnum;
  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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  31. use Symfony\Component\Serializer\Annotation\Ignore;
  32. use Symfony\Component\Uid\Ulid;
  33. use Symfony\Component\Validator\Constraints as Assert;
  34. #[ORM\Table(name'expediting_shipping_segment')]
  35. #[ORM\Index(columns: ['shipping_plan_id'], name'expediting_shipping_segment_shipping_plan_id_idx')]
  36. #[ORM\Index(columns: ['place_of_loading_id'], name'expediting_shipping_segment_place_of_loading_id_idx')]
  37. #[ORM\Index(columns: ['place_of_discharge_id'], name'expediting_shipping_segment_place_of_discharge_id_idx')]
  38. #[ORM\Index(columns: ['transport_company_id'], name'expediting_shipping_segment_transport_company_id_idx')]
  39. #[ORM\Index(columns: ['notify_party_id'], name'expediting_shipping_segment_notify_party_id_idx')]
  40. #[ORM\Index(columns: ['consignee_id'], name'expediting_shipping_segment_consignee_id_idx')]
  41. #[ORM\Index(columns: ['shipper_id'], name'expediting_shipping_segment_shipper_id_idx')]
  42. #[ORM\Index(columns: ['vehicle_id'], name'expediting_shipping_segment_vehicle_id_idx')]
  43. #[ORM\Index(columns: ['driver_id'], name'expediting_shipping_segment_driver_id_idx')]
  44. #[ORM\Index(columns: ['created_by'], name'expediting_shipping_segment_created_by_idx')]
  45. #[ORM\Index(columns: ['updated_by'], name'expediting_shipping_segment_updated_by_idx')]
  46. #[ORM\UniqueConstraint(name'expediting_shipping_segment_identifier_key'columns: ['identifier'])]
  47. #[ORM\Entity]
  48. #[UniqueEntity(fields: ['identifier'])]
  49. #[ApiResource(
  50.     operations: [
  51.         new Get(),
  52.         new Post(uriTemplate'/shipments/{identifier}/book'inputBookingInput::class, processorShipmentBookingProcessor::class),
  53.         new Post(uriTemplate'/shipments/{identifier}/update'inputShipmentStatusUpdateInput::class, processorShipmentStatusProcessor::class),
  54.         new GetCollection(),
  55.     ],
  56.     routePrefix'/expediting',
  57. )]
  58. class ShippingSegment
  59. {
  60.     use Shippable;
  61.     use Common\Blameable;
  62.     use Common\Trackable;
  63.     #[ORM\Id]
  64.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  65.     #[ORM\SequenceGenerator(sequenceName'expediting_shipment_id_seq')]
  66.     #[ORM\Column(typeTypes::INTEGER)]
  67.     #[ApiProperty(identifierfalse)]
  68.     private ?int $id null;
  69.     #[Assert\Ulid]
  70.     #[Assert\NotNull]
  71.     #[ORM\Column(type'ulid'uniquetrue)]
  72.     #[ApiProperty(identifiertrue)]
  73.     private ?Ulid $identifier null;
  74.     #[Assert\NotNull]
  75.     #[Assert\Type(typeShippingPlan::class)]
  76.     #[ORM\ManyToOne(targetEntityShippingPlan::class, inversedBy'shippingSegments')]
  77.     #[ORM\JoinColumn(name'shipping_plan_id'nullablefalse)]
  78.     private ?ShippingPlan $shippingPlan null;
  79.     #[ORM\ManyToOne(targetEntityCompany::class)]
  80.     #[ORM\JoinColumn(name'shipper_id')]
  81.     private ?Company $shipper null;
  82.     #[ORM\ManyToOne(targetEntityCompany::class)]
  83.     #[ORM\JoinColumn(name'consignee_id')]
  84.     private ?Company $consignee null;
  85.     #[ORM\ManyToOne(targetEntityCompany::class)]
  86.     #[ORM\JoinColumn(name'notify_party_id')]
  87.     private ?Company $notifyParty null;
  88.     #[ORM\ManyToOne(targetEntityFacility::class)]
  89.     #[ORM\JoinColumn(name'place_of_loading_id')]
  90.     #[ApiProperty(readableLinktrue)]
  91.     private ?Facility $placeOfLoading null;
  92.     #[ORM\ManyToOne(targetEntityFacility::class)]
  93.     #[ORM\JoinColumn(name'place_of_discharge_id')]
  94.     #[ApiProperty(readableLinktrue)]
  95.     private ?Facility $placeOfDischarge null;
  96.     #[Assert\Type(typeTypes::DATE_MUTABLE)]
  97.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  98.     private ?DateTimeInterface $etd null;
  99.     #[Assert\Type(typeTypes::DATE_MUTABLE)]
  100.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  101.     private ?DateTimeInterface $eta null;
  102.     #[Assert\Length(exactly3)]
  103.     #[Assert\Type(typeTypes::STRING)]
  104.     #[ORM\Column(typeTypes::STRINGlength3nullabletrue)]
  105.     private ?string $currency null;
  106.     #[Assert\Type(typeTypes::FLOAT)]
  107.     #[ORM\Column(typeTypes::DECIMALprecision18scale5nullabletrue)]
  108.     private ?float $freightValue null;
  109.     #[Assert\Type(typeTypes::STRING)]
  110.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  111.     private ?string $bookingNumber null;
  112.     #[Assert\Type(typeTypes::STRING)]
  113.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  114.     private ?string $billNumber null;
  115.     #[Assert\Type(typeTypes::STRING)]
  116.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  117.     private ?string $vectorReference null;
  118.     #[Assert\NotNull]
  119.     #[IsValidEnum(enumTransportMode::class)]
  120.     #[ORM\Column(typeTypes::STRINGenumTypeTransportMode::class)]
  121.     private ?TransportMode $transportMode null;
  122.     #[Assert\Type(typeCompany::class)]
  123.     #[ORM\ManyToOne(targetEntityCompany::class)]
  124.     #[ORM\JoinColumn(name'transport_company_id')]
  125.     private ?Company $transportCompany null;
  126.     #[Assert\Type(typeDriver::class)]
  127.     #[ORM\ManyToOne(targetEntityDriver::class)]
  128.     #[ORM\JoinColumn(name'driver_id')]
  129.     private ?Driver $driver null;
  130.     #[Assert\Type(typeVehicle::class)]
  131.     #[ORM\ManyToOne(targetEntityVehicle::class)]
  132.     #[ORM\JoinColumn(name'vehicle_id')]
  133.     private ?Vehicle $vehicle null;
  134.     #[Assert\NotNull]
  135.     #[IsValidEnum(enumTransportSpecification::class)]
  136.     #[ORM\Column(typeTypes::STRINGenumTypeTransportSpecification::class, options: ['default' => 'STANDARD'])]
  137.     private ?TransportSpecification $transportSpecification TransportSpecification::STANDARD;
  138.     #[Assert\Type(typeTypes::BOOLEAN)]
  139.     #[ORM\Column(typeTypes::BOOLEANnullabletrueoptions: ['default' => false])]
  140.     private ?bool $delayed false;
  141.     /**
  142.      * @var ShipmentType[]
  143.      * Note : Types are automatically on the entity subscriber level
  144.      */
  145.     #[Assert\NotNull]
  146.     #[ORM\Column(typeSelectableType::NAMEnullabletrueenumTypeShipmentType::class)]
  147.     private array $types = [];
  148.     #[Assert\NotNull]
  149.     #[IsValidEnum(enumShippingSegmentStatus::class)]
  150.     #[ORM\Column(typeTypes::STRINGenumTypeShippingSegmentStatus::class, options: ['default' => 'PLANNED'])]
  151.     private ?ShippingSegmentStatus $status ShippingSegmentStatus::PLANNED;
  152.     /** @var Collection<int, PackageMovement> */
  153.     #[ORM\OneToMany(mappedBy'shippingSegment'targetEntityPackageMovement::class)]
  154.     #[Ignore]
  155.     private Collection $movements;
  156.     /** @var Collection<int, Task> */
  157.     #[ORM\ManyToMany(targetEntityTask::class, mappedBy'shippingSegments')]
  158.     private Collection $tasks;
  159.     public function __construct()
  160.     {
  161.         $this->identifier = new Ulid();
  162.         $this->movements = new ArrayCollection();
  163.         $this->tasks = new ArrayCollection();
  164.     }
  165.     public function getId(): ?int
  166.     {
  167.         return $this->id;
  168.     }
  169.     public function getIdentifier(): ?Ulid
  170.     {
  171.         return $this->identifier;
  172.     }
  173.     public function setIdentifier(Ulid $identifier): self
  174.     {
  175.         $this->identifier $identifier;
  176.         return $this;
  177.     }
  178.     public function getShippingPlan(): ?ShippingPlan
  179.     {
  180.         return $this->shippingPlan;
  181.     }
  182.     public function setShippingPlan(?ShippingPlan $shippingPlan): self
  183.     {
  184.         $this->shippingPlan $shippingPlan;
  185.         return $this;
  186.     }
  187.     public function getShipper(): ?Company
  188.     {
  189.         return $this->shipper;
  190.     }
  191.     public function setShipper(?Company $shipper): self
  192.     {
  193.         $this->shipper $shipper;
  194.         return $this;
  195.     }
  196.     public function getConsignee(): ?Company
  197.     {
  198.         return $this->consignee;
  199.     }
  200.     public function setConsignee(?Company $consignee): self
  201.     {
  202.         $this->consignee $consignee;
  203.         return $this;
  204.     }
  205.     public function getNotifyParty(): ?Company
  206.     {
  207.         return $this->notifyParty;
  208.     }
  209.     public function setNotifyParty(?Company $notifyParty): self
  210.     {
  211.         $this->notifyParty $notifyParty;
  212.         return $this;
  213.     }
  214.     public function getPlaceOfLoading(): ?Facility
  215.     {
  216.         return $this->placeOfLoading;
  217.     }
  218.     public function setPlaceOfLoading(?Facility $placeOfLoading): self
  219.     {
  220.         $this->placeOfLoading $placeOfLoading;
  221.         return $this;
  222.     }
  223.     public function getPlaceOfDischarge(): ?Facility
  224.     {
  225.         return $this->placeOfDischarge;
  226.     }
  227.     public function setPlaceOfDischarge(?Facility $placeOfDischarge): self
  228.     {
  229.         $this->placeOfDischarge $placeOfDischarge;
  230.         return $this;
  231.     }
  232.     public function getEtd(): ?DateTimeInterface
  233.     {
  234.         return $this->etd;
  235.     }
  236.     public function setEtd(?DateTimeInterface $etd): self
  237.     {
  238.         $this->etd $etd;
  239.         return $this;
  240.     }
  241.     public function getEta(): ?DateTimeInterface
  242.     {
  243.         return $this->eta;
  244.     }
  245.     public function setEta(?DateTimeInterface $eta): self
  246.     {
  247.         $this->eta $eta;
  248.         return $this;
  249.     }
  250.     public function getCurrency(): ?string
  251.     {
  252.         return $this->currency;
  253.     }
  254.     public function setCurrency(?string $currency): self
  255.     {
  256.         $this->currency $currency;
  257.         return $this;
  258.     }
  259.     public function getFreightValue(): ?string
  260.     {
  261.         return $this->freightValue;
  262.     }
  263.     public function setFreightValue(?string $freightValue): self
  264.     {
  265.         $this->freightValue $freightValue;
  266.         return $this;
  267.     }
  268.     public function getBookingNumber(): ?string
  269.     {
  270.         return $this->bookingNumber;
  271.     }
  272.     public function setBookingNumber(?string $bookingNumber): self
  273.     {
  274.         $this->bookingNumber $bookingNumber;
  275.         return $this;
  276.     }
  277.     public function getBillNumber(): ?string
  278.     {
  279.         return $this->billNumber;
  280.     }
  281.     public function setBillNumber(?string $billNumber): self
  282.     {
  283.         $this->billNumber $billNumber;
  284.         return $this;
  285.     }
  286.     public function getVectorReference(): ?string
  287.     {
  288.         return $this->vectorReference;
  289.     }
  290.     public function setVectorReference(?string $vectorReference): self
  291.     {
  292.         $this->vectorReference $vectorReference;
  293.         return $this;
  294.     }
  295.     public function getTransportMode(): ?TransportMode
  296.     {
  297.         return $this->transportMode;
  298.     }
  299.     public function setTransportMode(?TransportMode $transportMode): self
  300.     {
  301.         $this->transportMode $transportMode;
  302.         return $this;
  303.     }
  304.     public function getTransportCompany(): ?Company
  305.     {
  306.         return $this->transportCompany;
  307.     }
  308.     public function setTransportCompany(?Company $transportCompany): self
  309.     {
  310.         $this->transportCompany $transportCompany;
  311.         return $this;
  312.     }
  313.     public function getDriver(): ?Driver
  314.     {
  315.         return $this->driver;
  316.     }
  317.     public function setDriver(?Driver $driver): self
  318.     {
  319.         $this->driver $driver;
  320.         return $this;
  321.     }
  322.     public function getVehicle(): ?Vehicle
  323.     {
  324.         return $this->vehicle;
  325.     }
  326.     public function setVehicle(?Vehicle $vehicle): self
  327.     {
  328.         $this->vehicle $vehicle;
  329.         return $this;
  330.     }
  331.     public function getTransportSpecification(): ?TransportSpecification
  332.     {
  333.         return $this->transportSpecification;
  334.     }
  335.     public function setTransportSpecification(?TransportSpecification $transportSpecification): self
  336.     {
  337.         $this->transportSpecification $transportSpecification;
  338.         return $this;
  339.     }
  340.     public function isDelayed(): ?bool
  341.     {
  342.         return $this->delayed;
  343.     }
  344.     public function setDelayed(?bool $delayed): self
  345.     {
  346.         $this->delayed $delayed;
  347.         return $this;
  348.     }
  349.     public function getTypes(): array
  350.     {
  351.         return $this->types;
  352.     }
  353.     public function addType(ShipmentType $type): self
  354.     {
  355.         if (!in_array($type$this->types)) {
  356.             $this->types []= $type;
  357.         }
  358.         return $this;
  359.     }
  360.     public function setTypes($types): self
  361.     {
  362.         $this->types $types;
  363.         return $this;
  364.     }
  365.     public function getStatus(): ?ShippingSegmentStatus
  366.     {
  367.         return $this->status;
  368.     }
  369.     public function setStatus(?ShippingSegmentStatus $status): self
  370.     {
  371.         $this->status $status;
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return Collection<int, PackageMovement>
  376.      */
  377.     public function getMovements(): Collection
  378.     {
  379.         return $this->movements;
  380.     }
  381.     public function addMovement(PackageMovement $movement): static
  382.     {
  383.         if (!$this->movements->contains($movement)) {
  384.             $this->movements->add($movement);
  385.             $movement->setShippingSegment($this);
  386.         }
  387.         return $this;
  388.     }
  389.     public function removeMovement(PackageMovement $movement): static
  390.     {
  391.         if ($this->movements->removeElement($movement)) {
  392.             // set the owning side to null (unless already changed)
  393.             if ($movement->getShippingSegment() === $this) {
  394.                 $movement->setShippingSegment(null);
  395.             }
  396.         }
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection<int, Task>
  401.      */
  402.     public function getTasks(): Collection
  403.     {
  404.         return $this->tasks;
  405.     }
  406.     public function addTask(Task $task): self
  407.     {
  408.         if (!$this->tasks->contains($task)) {
  409.             $this->tasks[] = $task;
  410.             $task->addShippingSegment($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeTask(Task $task): self
  415.     {
  416.         if ($this->tasks->removeElement($task)) {
  417.             $task->removeShippingSegment($this);
  418.         }
  419.         return $this;
  420.     }
  421. }