src/Entity/Expediting/ShippingSegment.php line 61
<?php
namespace App\Entity\Expediting;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\Doctrine\Type\Expediting\ShippingSegmentStatus;
use App\Doctrine\Type\Expediting\ShipmentType;
use App\Doctrine\Type\Expediting\TransportMode;
use App\Doctrine\Type\Expediting\TransportSpecification;
use App\Doctrine\Type\SelectableType;
use App\Dto\Expediting\BookingInput;
use App\Dto\Expediting\ShipmentStatusUpdateInput;
use App\Entity\Common as Common;
use App\Entity\Common\Company;
use App\Entity\Fleet\Driver;
use App\Entity\Fleet\Vehicle;
use App\Entity\Inventory\PackageMovement;
use App\Entity\Places\Facility;
use App\Entity\Scheduler\Task;
use App\Processor\Expediting\ShipmentBookingProcessor;
use App\Processor\Expediting\ShipmentStatusProcessor;
use App\Validator\IsValidEnum\IsValidEnum;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'expediting_shipping_segment')]
#[ORM\Index(columns: ['shipping_plan_id'], name: 'expediting_shipping_segment_shipping_plan_id_idx')]
#[ORM\Index(columns: ['place_of_loading_id'], name: 'expediting_shipping_segment_place_of_loading_id_idx')]
#[ORM\Index(columns: ['place_of_discharge_id'], name: 'expediting_shipping_segment_place_of_discharge_id_idx')]
#[ORM\Index(columns: ['transport_company_id'], name: 'expediting_shipping_segment_transport_company_id_idx')]
#[ORM\Index(columns: ['notify_party_id'], name: 'expediting_shipping_segment_notify_party_id_idx')]
#[ORM\Index(columns: ['consignee_id'], name: 'expediting_shipping_segment_consignee_id_idx')]
#[ORM\Index(columns: ['shipper_id'], name: 'expediting_shipping_segment_shipper_id_idx')]
#[ORM\Index(columns: ['vehicle_id'], name: 'expediting_shipping_segment_vehicle_id_idx')]
#[ORM\Index(columns: ['driver_id'], name: 'expediting_shipping_segment_driver_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'expediting_shipping_segment_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'expediting_shipping_segment_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'expediting_shipping_segment_identifier_key', columns: ['identifier'])]
#[ORM\Entity]
#[UniqueEntity(fields: ['identifier'])]
#[ApiResource(
operations: [
new Get(),
new Post(uriTemplate: '/shipments/{identifier}/book', input: BookingInput::class, processor: ShipmentBookingProcessor::class),
new Post(uriTemplate: '/shipments/{identifier}/update', input: ShipmentStatusUpdateInput::class, processor: ShipmentStatusProcessor::class),
new GetCollection(),
],
routePrefix: '/expediting',
)]
class ShippingSegment
{
use Shippable;
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_shipment_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
#[ApiProperty(identifier: true)]
private ?Ulid $identifier = null;
#[Assert\NotNull]
#[Assert\Type(type: ShippingPlan::class)]
#[ORM\ManyToOne(targetEntity: ShippingPlan::class, inversedBy: 'shippingSegments')]
#[ORM\JoinColumn(name: 'shipping_plan_id', nullable: false)]
private ?ShippingPlan $shippingPlan = null;
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'shipper_id')]
private ?Company $shipper = null;
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'consignee_id')]
private ?Company $consignee = null;
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'notify_party_id')]
private ?Company $notifyParty = null;
#[ORM\ManyToOne(targetEntity: Facility::class)]
#[ORM\JoinColumn(name: 'place_of_loading_id')]
#[ApiProperty(readableLink: true)]
private ?Facility $placeOfLoading = null;
#[ORM\ManyToOne(targetEntity: Facility::class)]
#[ORM\JoinColumn(name: 'place_of_discharge_id')]
#[ApiProperty(readableLink: true)]
private ?Facility $placeOfDischarge = null;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $etd = null;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $eta = null;
#[Assert\Length(exactly: 3)]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, length: 3, nullable: true)]
private ?string $currency = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 5, nullable: true)]
private ?float $freightValue = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $bookingNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $billNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $vectorReference = null;
#[Assert\NotNull]
#[IsValidEnum(enum: TransportMode::class)]
#[ORM\Column(type: Types::STRING, enumType: TransportMode::class)]
private ?TransportMode $transportMode = null;
#[Assert\Type(type: Company::class)]
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(name: 'transport_company_id')]
private ?Company $transportCompany = null;
#[Assert\Type(type: Driver::class)]
#[ORM\ManyToOne(targetEntity: Driver::class)]
#[ORM\JoinColumn(name: 'driver_id')]
private ?Driver $driver = null;
#[Assert\Type(type: Vehicle::class)]
#[ORM\ManyToOne(targetEntity: Vehicle::class)]
#[ORM\JoinColumn(name: 'vehicle_id')]
private ?Vehicle $vehicle = null;
#[Assert\NotNull]
#[IsValidEnum(enum: TransportSpecification::class)]
#[ORM\Column(type: Types::STRING, enumType: TransportSpecification::class, options: ['default' => 'STANDARD'])]
private ?TransportSpecification $transportSpecification = TransportSpecification::STANDARD;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true, options: ['default' => false])]
private ?bool $delayed = false;
/**
* @var ShipmentType[]
* Note : Types are automatically on the entity subscriber level
*/
#[Assert\NotNull]
#[ORM\Column(type: SelectableType::NAME, nullable: true, enumType: ShipmentType::class)]
private array $types = [];
#[Assert\NotNull]
#[IsValidEnum(enum: ShippingSegmentStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: ShippingSegmentStatus::class, options: ['default' => 'PLANNED'])]
private ?ShippingSegmentStatus $status = ShippingSegmentStatus::PLANNED;
/** @var Collection<int, PackageMovement> */
#[ORM\OneToMany(mappedBy: 'shippingSegment', targetEntity: PackageMovement::class)]
#[Ignore]
private Collection $movements;
/** @var Collection<int, Task> */
#[ORM\ManyToMany(targetEntity: Task::class, mappedBy: 'shippingSegments')]
private Collection $tasks;
public function __construct()
{
$this->identifier = new Ulid();
$this->movements = new ArrayCollection();
$this->tasks = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getShippingPlan(): ?ShippingPlan
{
return $this->shippingPlan;
}
public function setShippingPlan(?ShippingPlan $shippingPlan): self
{
$this->shippingPlan = $shippingPlan;
return $this;
}
public function getShipper(): ?Company
{
return $this->shipper;
}
public function setShipper(?Company $shipper): self
{
$this->shipper = $shipper;
return $this;
}
public function getConsignee(): ?Company
{
return $this->consignee;
}
public function setConsignee(?Company $consignee): self
{
$this->consignee = $consignee;
return $this;
}
public function getNotifyParty(): ?Company
{
return $this->notifyParty;
}
public function setNotifyParty(?Company $notifyParty): self
{
$this->notifyParty = $notifyParty;
return $this;
}
public function getPlaceOfLoading(): ?Facility
{
return $this->placeOfLoading;
}
public function setPlaceOfLoading(?Facility $placeOfLoading): self
{
$this->placeOfLoading = $placeOfLoading;
return $this;
}
public function getPlaceOfDischarge(): ?Facility
{
return $this->placeOfDischarge;
}
public function setPlaceOfDischarge(?Facility $placeOfDischarge): self
{
$this->placeOfDischarge = $placeOfDischarge;
return $this;
}
public function getEtd(): ?DateTimeInterface
{
return $this->etd;
}
public function setEtd(?DateTimeInterface $etd): self
{
$this->etd = $etd;
return $this;
}
public function getEta(): ?DateTimeInterface
{
return $this->eta;
}
public function setEta(?DateTimeInterface $eta): self
{
$this->eta = $eta;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getFreightValue(): ?string
{
return $this->freightValue;
}
public function setFreightValue(?string $freightValue): self
{
$this->freightValue = $freightValue;
return $this;
}
public function getBookingNumber(): ?string
{
return $this->bookingNumber;
}
public function setBookingNumber(?string $bookingNumber): self
{
$this->bookingNumber = $bookingNumber;
return $this;
}
public function getBillNumber(): ?string
{
return $this->billNumber;
}
public function setBillNumber(?string $billNumber): self
{
$this->billNumber = $billNumber;
return $this;
}
public function getVectorReference(): ?string
{
return $this->vectorReference;
}
public function setVectorReference(?string $vectorReference): self
{
$this->vectorReference = $vectorReference;
return $this;
}
public function getTransportMode(): ?TransportMode
{
return $this->transportMode;
}
public function setTransportMode(?TransportMode $transportMode): self
{
$this->transportMode = $transportMode;
return $this;
}
public function getTransportCompany(): ?Company
{
return $this->transportCompany;
}
public function setTransportCompany(?Company $transportCompany): self
{
$this->transportCompany = $transportCompany;
return $this;
}
public function getDriver(): ?Driver
{
return $this->driver;
}
public function setDriver(?Driver $driver): self
{
$this->driver = $driver;
return $this;
}
public function getVehicle(): ?Vehicle
{
return $this->vehicle;
}
public function setVehicle(?Vehicle $vehicle): self
{
$this->vehicle = $vehicle;
return $this;
}
public function getTransportSpecification(): ?TransportSpecification
{
return $this->transportSpecification;
}
public function setTransportSpecification(?TransportSpecification $transportSpecification): self
{
$this->transportSpecification = $transportSpecification;
return $this;
}
public function isDelayed(): ?bool
{
return $this->delayed;
}
public function setDelayed(?bool $delayed): self
{
$this->delayed = $delayed;
return $this;
}
public function getTypes(): array
{
return $this->types;
}
public function addType(ShipmentType $type): self
{
if (!in_array($type, $this->types)) {
$this->types []= $type;
}
return $this;
}
public function setTypes($types): self
{
$this->types = $types;
return $this;
}
public function getStatus(): ?ShippingSegmentStatus
{
return $this->status;
}
public function setStatus(?ShippingSegmentStatus $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection<int, PackageMovement>
*/
public function getMovements(): Collection
{
return $this->movements;
}
public function addMovement(PackageMovement $movement): static
{
if (!$this->movements->contains($movement)) {
$this->movements->add($movement);
$movement->setShippingSegment($this);
}
return $this;
}
public function removeMovement(PackageMovement $movement): static
{
if ($this->movements->removeElement($movement)) {
// set the owning side to null (unless already changed)
if ($movement->getShippingSegment() === $this) {
$movement->setShippingSegment(null);
}
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->addShippingSegment($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
$task->removeShippingSegment($this);
}
return $this;
}
}