src/Entity/Delete/Box.php line 60
<?php
namespace App\Entity\Delete;
use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use App\Doctrine\Type\Expediting\CasingMaterial;
use App\Doctrine\Type\Expediting\CasingType;
use App\Dto\Delete\BoxInput;
use App\Dto\Expediting\ItemsListInput;
use App\Entity\Common as Common;
use App\Entity\Identity\User;
use App\Processor\Delete\BoxInputProcessor;
use App\Service\Common\ItemsListHelper;
use App\Validator\IsValidEnum\IsValidEnum;
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_box')]
#[ORM\Index(columns: ['batch'], name: 'expediting_z_box_batch_idx')]
#[ORM\Index(columns: ['container_id'], name: 'expediting_z_container_id_idx')]
#[ORM\Index(columns: ['repacking_id'], name: 'expediting_z_repacking_id_idx')]
#[ORM\Index(columns: ['order_numbers'], name: 'expediting_z_box_order_numbers_idx')]
#[ORM\UniqueConstraint(name: 'expediting_z_box_reference_key', columns: ['reference'])]
#[ORM\UniqueConstraint(name: 'expediting_z_box_slug_key', columns: ['slug'])]
#[ORM\Entity]
#[ApiResource(
routePrefix: '/xpediting',
input: BoxInput::class,
processor: BoxInputProcessor::class,
)]
#[ApiResource(
uriTemplate: '/containers/{slug}/observations',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'boxes', fromClass: Container::class),
],
routePrefix: '/xpediting',
)]
#[ApiFilter(SearchFilter::class, properties: [
'vendor' => 'ipartial',
'reference' => 'ipartial',
'orderNumbers' => 'ipartial',
'batchReference' => 'ipartial',
'pickupCountryCode' => 'exact',
'hub' => 'exact',
])]
#[ApiFilter(ExistsFilter::class, properties: [
'repacking',
])]
class Box
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_z_box_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private int $id;
#[ORM\ManyToOne(targetEntity: Container::class, inversedBy: 'boxes')]
#[ORM\JoinColumn(name: 'container_id')]
private ?Container $container = null;
#[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::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $orderNumbers = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $pickupCountryCode = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $vendor = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(name: 'batch', type: Types::STRING, nullable: true)]
private ?string $batchReference = 'AVAILABLE';
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
private ?string $hub = null;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $jv = false;
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $dg = false;
#[IsValidEnum(enum: CasingType::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: CasingType::class)]
private ?CasingType $casingType = null;
#[IsValidEnum(enum: CasingMaterial::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: CasingMaterial::class)]
private ?CasingMaterial $casingMaterial = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $length = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $width = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $height = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $weight = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $shippingWeight = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2, nullable: true)]
private ?float $value = null;
#[ORM\ManyToOne(targetEntity: Box::class, inversedBy: 'packages')]
#[ORM\JoinColumn(name: 'repacking_id', referencedColumnName: 'id')]
private ?Box $repacking = null;
#[ORM\OneToMany(mappedBy: 'repacking', targetEntity: Box::class)]
private Collection $packages;
#[Assert\Valid]
#[Assert\Type(type: Items::class)]
#[ORM\Column(type: 'json_document', options: ['jsonb' => true])]
private ?Items $items = null;
#[Gedmo\Blameable(on: 'create')]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: true)]
protected ?User $createdBy = null;
public function __construct()
{
$this->packages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): static
{
$this->container = $container;
return $this;
}
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 getOrderNumbers(): ?string
{
return $this->orderNumbers;
}
public function setOrderNumbers(?string $orderNumbers): static
{
$this->orderNumbers = $orderNumbers;
return $this;
}
public function getPickupCountryCode(): ?string
{
return $this->pickupCountryCode;
}
public function setPickupCountryCode(?string $pickupCountryCode): static
{
$this->pickupCountryCode = $pickupCountryCode;
return $this;
}
public function getVendor(): ?string
{
return $this->vendor;
}
public function setVendor(?string $vendor): static
{
$this->vendor = $vendor;
return $this;
}
public function getBatchReference(): ?string
{
return $this->batchReference;
}
public function setBatchReference(?string $batchReference): static
{
$this->batchReference = null === $batchReference
? 'AVAILABLE'
: $batchReference;
return $this;
}
public function getHub(): ?string
{
return $this->hub;
}
public function setHub(?string $hub): static
{
$this->hub = $hub;
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 getCasingType(): ?CasingType
{
return $this->casingType;
}
public function setCasingType(?CasingType $casingType): static
{
$this->casingType = $casingType;
return $this;
}
public function getCasingMaterial(): ?CasingMaterial
{
return $this->casingMaterial;
}
public function setCasingMaterial(?CasingMaterial $casingMaterial): static
{
$this->casingMaterial = $casingMaterial;
return $this;
}
public function getLength(): ?float
{
return $this->length;
}
public function setLength(?float $length): static
{
$this->length = $length;
return $this;
}
public function getWidth(): ?float
{
return $this->width;
}
public function setWidth(?float $width): static
{
$this->width = $width;
return $this;
}
public function getHeight(): ?float
{
return $this->height;
}
public function setHeight(?float $height): static
{
$this->height = $height;
return $this;
}
public function getVolume(): ?float
{
return ($this->length * $this->width * $this->height) / 1_000_000;
}
public function getWeight(): ?float
{
return $this->weight;
}
public function setWeight(?float $weight): static
{
$this->weight = $weight;
return $this;
}
public function getShippingWeight(): ?float
{
return $this->shippingWeight;
}
public function setShippingWeight(?float $shippingWeight): static
{
$this->shippingWeight = $shippingWeight;
return $this;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue(?float $value): static
{
$this->value = $value;
return $this;
}
public function getItemsLists(): array
{
$items = [];
foreach ($this->items->items as $item) {
if (!isset($items[$item->orderNumber])) {
$items[$item->orderNumber] = [
'list' => [],
'containsDangerousGood' => false,
];
}
if ($item->isDangerous) {
$items[$item->orderNumber]['containsDangerousGood'] = true;
}
$items[$item->orderNumber]['list'] []= $item->number;
}
$itemsLists = [];
foreach ($items as $orderNumber => $orderData) {
$itemsLists []= new ItemsListInput(
orderNumber: $orderNumber,
itemsList: ItemsListHelper::normalize($orderData['list']),
containsDangerousGoods: $orderData['containsDangerousGood'],
);
}
return $itemsLists;
}
public function getContainsDangerousGood(): bool
{
foreach ($this->items->items as $item) {
if ($item->isDangerous) {
return true;
}
}
return false;
}
public function getRepacking(): ?self
{
return $this->repacking;
}
public function setRepacking(?self $repacking): self
{
$this->repacking = $repacking;
return $this;
}
/** @return Collection<int, Box> */
public function getPackages(): Collection
{
return $this->packages;
}
public function addPackage(Box $package): self
{
if (!$this->packages->contains($package)) {
$this->packages->add($package);
$package->setRepacking($this);
}
return $this;
}
public function removePackage(Box $package): self
{
if ($this->packages->removeElement($package)) {
// set the owning side to null (unless already changed)
if ($package->getRepacking() === $this) {
$package->setRepacking(null);
}
}
return $this;
}
public function getItems(): ?Items
{
return $this->items;
}
public function setItems(?Items $Items): static
{
$this->items = $Items;
return $this;
}
}