src/Entity/Delete/Batch.php line 73
<?php
namespace App\Entity\Delete;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Doctrine\Type\Expediting\ContainerSize;
use App\Doctrine\Type\Expediting\TransportMode;
use App\Dto\Common\ObservationInput;
use App\Dto\Delete\BatchInput;
use App\Dto\Delete\BatchStatusUpdateInput;
use App\Dto\Delete\CurrenciesOutput;
use App\Dto\Delete\KitRequestInput;
use App\Entity\Common as Common;
use App\Entity\Common\Observation;
use App\Entity\Identity\User;
use App\Processor\Delete\BatchInputProcessor;
use App\Processor\Delete\BatchObservationProcessor;
use App\Processor\Delete\BatchStatusProcessor;
use App\Processor\Delete\KitRequestProcessor;
use App\Provider\Delete\BatchCurrenciesProvider;
use App\Provider\Delete\BatchProvider;
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 Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'expediting_z_batch')]
#[ORM\Index(columns: ['created_by'], name: 'expediting_z_batch_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'expediting_z_batch_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'expediting_z_batch_slug_key', columns: ['slug'])]
#[ORM\UniqueConstraint(name: 'expediting_z_batch_reference_key', columns: ['reference'])]
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(provider: BatchProvider::class),
new Get(uriTemplate: '/batches/{slug}/currencies' ,output: CurrenciesOutput::class, provider: BatchCurrenciesProvider::class),
new GetCollection(),
new Post(uriTemplate: '/batches/{slug}/update', input: BatchStatusUpdateInput::class, processor: BatchStatusProcessor::class),
new Post(uriTemplate: '/batches/{slug}/prepare', input: KitRequestInput::class, processor: KitRequestProcessor::class),
new Post(),
new Patch(),
new Put(),
new Delete(),
new Post(
uriTemplate: '/batches/{slug}/observations',
input: ObservationInput::class,
processor: BatchObservationProcessor::class
),
],
routePrefix: '/xpediting',
input: BatchInput::class,
order: ['id' => 'DESC'],
processor: BatchInputProcessor::class,
)]
#[ApiFilter(SearchFilter::class, properties: [
'reference' => 'ipartial',
'transportMode' => 'exact',
])]
class Batch
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_z_batch_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private int $id;
#[Gedmo\Slug(fields: ['reference'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private string $slug;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $reference = null;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $jv = null;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $dg = null;
#[Assert\NotNull]
#[IsValidEnum(enum: TransportMode::class)]
#[ORM\Column(type: Types::STRING, enumType: TransportMode::class)]
private ?TransportMode $transportMode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $carrier = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $vessel = 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 $bookingNumber = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $vectorReference = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $placeOfLoading = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $placeOfDischarge = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $departureCountryCode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $hubCountryCode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $description = null;
#[Assert\Valid]
#[Assert\Type(type: Party::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Party $buyer;
#[Assert\Valid]
#[Assert\Type(type: Party::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Party $shipper;
#[Assert\Valid]
#[Assert\Type(type: Party::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Party $consignee;
#[Assert\Valid]
#[Assert\Type(type: Party::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Party $notifyParty;
#[Assert\Valid]
#[Assert\Type(type: Waybill::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Waybill $waybill;
#[Assert\Valid]
#[Assert\Type(type: Metadata::class)]
#[ORM\Column(type: 'json_document', nullable: true, options: ['jsonb' => true])]
private Metadata $metadata;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $formM = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $baNumber = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2, nullable: true)]
private ?float $weight = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2, nullable: true)]
private ?float $volume = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2, nullable: true)]
private ?float $value = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 5, nullable: true)]
private ?float $pickupCost = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 5, nullable: true)]
private ?float $freightCost = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $greenLitOn = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $bookedOn = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $etd = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $atd = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $eta = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $ata = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $customsOn = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $deliveredOn = null;
#[Gedmo\Blameable(on: 'create')]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: true)]
protected ?User $createdBy = null;
/** @var Collection<int, Container> */
#[ORM\OneToMany(mappedBy: 'batch', targetEntity: Container::class, cascade: ['persist', 'remove'])]
private Collection $containers;
/** @var Collection<int, Movement> */
#[ORM\OneToMany(mappedBy: 'batch', targetEntity: Movement::class, cascade: ['persist', 'remove'])]
private Collection $movements;
/** @var Collection<int, Observation> */
#[ORM\OneToMany(mappedBy: 'batch', targetEntity: Observation::class, cascade: ['persist', 'remove'])]
private Collection $observations;
public $kitStatus = null;
public function __construct()
{
$this->metadata = new Metadata();
$this->containers = new ArrayCollection();
$this->movements = new ArrayCollection();
$this->observations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): static
{
$this->reference = $reference;
return $this;
}
public function isJv(): ?bool
{
return $this->jv;
}
public function setJv(?bool $jv): static
{
$this->jv = $jv;
return $this;
}
public function isDg(): ?bool
{
return $this->dg;
}
public function setDg(?bool $dg): static
{
$this->dg = $dg;
return $this;
}
public function isBreakBulk(): ?bool
{
return empty(count($this->containers));
}
public function getTransportMode(): ?TransportMode
{
return $this->transportMode;
}
public function setTransportMode(?TransportMode $transportMode): static
{
$this->transportMode = $transportMode;
return $this;
}
public function getCarrier(): ?string
{
return $this->carrier;
}
public function setCarrier(?string $carrier): static
{
$this->carrier = $carrier;
return $this;
}
public function getVessel(): ?string
{
return $this->vessel;
}
public function setVessel(?string $vessel): static
{
$this->vessel = $vessel;
return $this;
}
public function getBillNumber(): ?string
{
return $this->billNumber;
}
public function setBillNumber(?string $billNumber): static
{
$this->billNumber = $billNumber;
return $this;
}
public function getBookingNumber(): ?string
{
return $this->bookingNumber;
}
public function setBookingNumber(?string $bookingNumber): static
{
$this->bookingNumber = $bookingNumber;
return $this;
}
public function getVectorReference(): ?string
{
return $this->vectorReference;
}
public function setVectorReference(?string $vectorReference): static
{
$this->vectorReference = $vectorReference;
return $this;
}
public function getPlaceOfLoading(): ?string
{
return $this->placeOfLoading;
}
public function setPlaceOfLoading(?string $placeOfLoading): static
{
$this->placeOfLoading = $placeOfLoading;
return $this;
}
public function getPlaceOfDischarge(): ?string
{
return $this->placeOfDischarge;
}
public function setPlaceOfDischarge(?string $placeOfDischarge): static
{
$this->placeOfDischarge = $placeOfDischarge;
return $this;
}
public function getDepartureCountryCode(): ?string
{
return $this->departureCountryCode;
}
public function setDepartureCountryCode(?string $departureCountryCode): static
{
$this->departureCountryCode = $departureCountryCode;
return $this;
}
public function getHubCountryCode(): ?string
{
return $this->hubCountryCode;
}
public function setHubCountryCode(?string $hubCountryCode): static
{
$this->hubCountryCode = $hubCountryCode;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getBuyer(): Party
{
return $this->buyer;
}
public function setBuyer(?Party $buyer): static
{
$this->buyer = $buyer;
return $this;
}
public function getShipper(): ?Party
{
return $this->shipper;
}
public function setShipper(?Party $shipper): static
{
$this->shipper = $shipper;
return $this;
}
public function getConsignee(): ?Party
{
return $this->consignee;
}
public function setConsignee(?Party $consignee): static
{
$this->consignee = $consignee;
return $this;
}
public function getNotifyParty(): Party
{
return $this->notifyParty;
}
public function setNotifyParty(?Party $notifyParty): static
{
$this->notifyParty = $notifyParty;
return $this;
}
public function getWaybill(): Waybill
{
return $this->waybill ?? new Waybill();
}
public function setWaybill(?Waybill $waybill): static
{
$this->waybill = $waybill;
return $this;
}
public function getFormM(): ?string
{
return $this->formM;
}
public function setFormM(?string $formM): static
{
$this->formM = $formM;
return $this;
}
public function getBaNumber(): ?string
{
return $this->baNumber;
}
public function setBaNumber(?string $baNumber): static
{
$this->baNumber = $baNumber;
return $this;
}
public function getWeight(): ?float
{
return $this->weight;
}
public function setWeight(?float $weight): static
{
$this->weight = $weight;
return $this;
}
public function getVolume(): ?float
{
return $this->volume;
}
public function setVolume(?float $volume): static
{
$this->volume = $volume;
return $this;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue(?float $value): static
{
$this->value = $value;
return $this;
}
public function getPickupCost(): ?float
{
return $this->pickupCost;
}
public function setPickupCost(?float $pickupCost): static
{
$this->pickupCost = $pickupCost;
return $this;
}
public function getFreightCost(): ?float
{
if (!empty($this->freightCost) && $this->getContainers()?->isEmpty()) {
return $this->freightCost;
}
$freightCost = 0;
foreach ($this->containers as $container) {
$freightCost += $container->getContainerSize() === ContainerSize::SIZE_20
? 8000
: 15000;
}
return $freightCost;
}
public function setFreightCost(?float $freightCost): static
{
$this->freightCost = $freightCost;
return $this;
}
public function getGreenLitOn(): ?DateTimeInterface
{
return $this->greenLitOn;
}
public function setGreenLitOn(?DateTimeInterface $greenLitOn): static
{
$this->greenLitOn = $greenLitOn;
return $this;
}
public function getBookedOn(): ?DateTimeInterface
{
return $this->bookedOn;
}
public function setBookedOn(?DateTimeInterface $bookedOn): static
{
$this->bookedOn = $bookedOn;
return $this;
}
public function getEtd(): ?DateTimeInterface
{
return $this->etd;
}
public function setEtd(?DateTimeInterface $etd): static
{
$this->etd = $etd;
return $this;
}
public function getAtd(): ?DateTimeInterface
{
return $this->atd;
}
public function setAtd(?DateTimeInterface $atd): static
{
$this->atd = $atd;
return $this;
}
public function getEta(): ?DateTimeInterface
{
return $this->eta;
}
public function setEta(?DateTimeInterface $eta): static
{
$this->eta = $eta;
return $this;
}
public function getAta(): ?DateTimeInterface
{
return $this->ata;
}
public function setAta(?DateTimeInterface $ata): static
{
$this->ata = $ata;
return $this;
}
public function getCustomsOn(): ?DateTimeInterface
{
return $this->customsOn;
}
public function setCustomsOn(?DateTimeInterface $customsOn): static
{
$this->customsOn = $customsOn;
return $this;
}
public function getDeliveredOn(): ?DateTimeInterface
{
return $this->deliveredOn;
}
public function setDeliveredOn(?DateTimeInterface $deliveredOn): static
{
$this->deliveredOn = $deliveredOn;
return $this;
}
public function getMetadata(): Metadata
{
return $this->metadata ?? new Metadata();
}
public function setMetadata(?Metadata $metadata): static
{
$this->metadata = $metadata;
return $this;
}
/** @return Collection<int, Container> */
public function getContainers(): Collection
{
return $this->containers;
}
public function addContainer(Container $container): static
{
if (!$this->containers->contains($container)) {
$this->containers->add($container);
$container->setBatch($this);
}
return $this;
}
public function removeContainer(Container $container): static
{
if ($this->containers->removeElement($container)) {
// set the owning side to null (unless already changed)
if ($container->getBatch() === $this) {
$container->setBatch(null);
}
}
return $this;
}
/** @return Collection<int, Movement> */
public function getMovements(): Collection
{
return $this->movements;
}
public function addMovement(Movement $movement): static
{
if (!$this->movements->contains($movement)) {
$this->movements->add($movement);
$movement->setBatch($this);
}
return $this;
}
public function removeMovement(Movement $movement): static
{
if ($this->movements->removeElement($movement)) {
// set the owning side to null (unless already changed)
if ($movement->getBatch() === $this) {
$movement->setBatch(null);
}
}
return $this;
}
/**
* @return Collection<int, Observation>
*/
public function getObservations(): Collection
{
return $this->observations;
}
public function addObservation(Observation $observation): self
{
if (!$this->observations->contains($observation)) {
$this->observations->add($observation);
$observation->setBatch($this);
}
return $this;
}
public function removeObservation(Observation $observation): self
{
if ($this->observations->removeElement($observation)) {
// set the owning side to null (unless already changed)
if ($observation->getBatch() === $this) {
$observation->setBatch(null);
}
}
return $this;
}
}