src/Entity/Inventory/PackageMovement.php line 41
<?php
namespace App\Entity\Inventory;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use App\Entity\Common as Common;
use App\Entity\Expediting\Package;
use App\Entity\Expediting\Repacking;
use App\Entity\Expediting\ShippingSegment;
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\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Table(name: 'inventory_package_movement')]
#[ORM\Index(columns: ['warehouse_id'], name: 'inventory_package_movement_warehouse_id_idx')]
#[ORM\Index(columns: ['package_id'], name: 'inventory_package_movement_package_id_idx')]
#[ORM\Index(columns: ['shipping_segment_id'], name: 'inventory_package_movement_shipping_segment_id_idx')]
#[ORM\Index(columns: ['repacking_id'], name: 'inventory_package_movement_repacking_id_idx')]
#[ORM\Index(columns: ['exit_id'], name: 'inventory_package_movement_exit_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'inventory_package_movement_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'inventory_package_movement_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'inventory_package_movement_identifier_key', columns: ['identifier'])]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type')]
#[ORM\DiscriminatorMap([
'ENTRY' => PackageStockEntry::class,
'EXIT' => PackageStockExit::class,
])]
#[ORM\Entity]
#[ApiFilter(SearchFilter::class, properties: [
'package.reference' => 'ipartial',
'package.items.order.number' => 'ipartial',
])]
Abstract class PackageMovement
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'inventory_package_movement_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
protected ?Ulid $identifier = null;
#[ApiFilter(SearchFilter::class, strategy: 'exact')]
#[ORM\ManyToOne(targetEntity: Warehouse::class, inversedBy: 'movements')]
#[ORM\JoinColumn(name: 'warehouse_id', referencedColumnName: 'id', nullable: false)]
protected ?Warehouse $warehouse = null;
#[ApiProperty(readableLink: true)]
#[ORM\ManyToOne(targetEntity: Package::class, inversedBy: 'movements')]
#[ORM\JoinColumn(name: 'package_id', referencedColumnName: 'id', nullable: false)]
protected ?Package $package = null;
#[ORM\ManyToOne(targetEntity: ShippingSegment::class, inversedBy: 'movements')]
#[ORM\JoinColumn(name: 'shipping_segment_id', referencedColumnName: 'id')]
protected ?ShippingSegment $shippingSegment = null;
#[ORM\ManyToOne(targetEntity: Repacking::class, inversedBy: 'movements')]
#[ORM\JoinColumn(name: 'repacking_id', referencedColumnName: 'id')]
protected ?Repacking $repacking = null;
#[Assert\Type(type: DateTimeInterface::class)]
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE, nullable: false)]
protected ?DateTimeInterface $completedAt = null;
/** @var Collection<int, ItemMovement> */
#[ORM\OneToMany(mappedBy: 'packageMovement', targetEntity: ItemMovement::class)]
private Collection $itemsMovements;
public function __construct()
{
$this->identifier = new Ulid();
$this->itemsMovements = new ArrayCollection();
}
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (empty($this->shipment) && empty($this->repacking)) {
$context->buildViolation('Package movement must be associated only with either, a shipment, or a repacking')
->atPath('shipment')
->addViolation();
$context->buildViolation('Package movement must be associated only with either, a shipment, or a repacking')
->atPath('repacking')
->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): static
{
$this->identifier = $identifier;
return $this;
}
public function getCompletedAt(): ?DateTimeInterface
{
return $this->completedAt;
}
public function setCompletedAt(DateTimeInterface $completedAt): static
{
$this->completedAt = $completedAt;
return $this;
}
public function getWarehouse(): ?Warehouse
{
return $this->warehouse;
}
public function setWarehouse(?Warehouse $warehouse): static
{
$this->warehouse = $warehouse;
return $this;
}
public function getPackage(): ?Package
{
return $this->package;
}
public function setPackage(?Package $package): static
{
$this->package = $package;
return $this;
}
public function getShippingSegment(): ?ShippingSegment
{
return $this->shippingSegment;
}
public function setShippingSegment(?ShippingSegment $shippingSegment): static
{
$this->shippingSegment = $shippingSegment;
return $this;
}
public function getRepacking(): ?Repacking
{
return $this->repacking;
}
public function setRepacking(?Repacking $repacking): static
{
$this->repacking = $repacking;
return $this;
}
/**
* @return Collection<int, ItemMovement>
*/
public function getItemsMovements(): Collection
{
return $this->itemsMovements;
}
public function addItemsMovement(ItemMovement $itemsMovement): static
{
if (!$this->itemsMovements->contains($itemsMovement)) {
$this->itemsMovements->add($itemsMovement);
$itemsMovement->setPackageMovement($this);
}
return $this;
}
public function removeItemsMovement(ItemMovement $itemsMovement): static
{
if ($this->itemsMovements->removeElement($itemsMovement)) {
// set the owning side to null (unless already changed)
if ($itemsMovement->getPackageMovement() === $this) {
$itemsMovement->setPackageMovement(null);
}
}
return $this;
}
}