<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\StorageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: StorageRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['storage:read']],
denormalizationContext: ['groups' => ['storage:write']],
order: ['id' => 'DESC']
)]
#[ApiFilter(SearchFilter::class, properties: ['code1c' => 'exact', 'name' => 'ipartial'])]
#[ORM\HasLifecycleCallbacks]
class Storage
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['storage:read', 'storage:write', 'order:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read', 'load_invocie:read', 'storage_element:read', 'product:read', 'order_product:read', 'product_storage_balance:read'])]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'order:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read', 'load_invocie:read', 'storage_element:read', 'product:read', 'order_product:read', 'product_storage_balance:read'])]
private ?string $name = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_entered = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_modified = null;
#[ORM\ManyToOne]
private ?User $created_by = null;
#[ORM\ManyToOne]
private ?User $modified_user = null;
#[ORM\Column(length: 100, nullable: true)]
#[Groups(['storage:read', 'storage:write'])]
private ?string $status = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['storage:read', 'storage:write'])]
private ?string $description = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['storage:read', 'storage:write'])]
private ?string $stock_id = null;
#[ORM\ManyToOne(targetEntity: self::class)]
#[Groups(['storage:read', 'storage:write'])]
private ?self $parent = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'storage_element:read', 'product:read', 'order:read', 'order_product:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read', 'product_storage_balance:read', 'product:read'])]
private ?string $c1id = null;
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: IncomingInvoice::class)]
private Collection $incomingInvoices;
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: IncomingInvoiceProduct::class)]
private Collection $incomingInvoiceProducts;
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: Orders::class)]
private Collection $orders;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['storage:read', 'storage:write', 'order:read', 'order_product:read', 'pre_order_product:read', 'pre_order:read', 'load_invocie:read', 'product_storage_balance:read', 'product:read'])]
private ?string $code1c = null;
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: Products::class)]
private Collection $products;
#[Groups(['storage:read', 'storage:write', 'product:read'])]
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: StorageElement::class)]
private Collection $storageElements;
#[ORM\OneToMany(mappedBy: 'storage', targetEntity: ProductBalanceInStorage::class)]
private Collection $productBalanceInStorages;
#[Groups(['storage:read', 'storage:write'])]
#[ORM\ManyToMany(targetEntity: Location::class, inversedBy: 'storages', cascade:['persist', 'remove'])]
private Collection $location;
public function __construct()
{
$this->incomingInvoices = new ArrayCollection();
$this->incomingInvoiceProducts = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->products = new ArrayCollection();
$this->storageElements = new ArrayCollection();
$this->productBalanceInStorages = new ArrayCollection();
$this->location = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->date_entered;
}
public function setDateEntered(?\DateTimeInterface $date_entered): self
{
$this->date_entered = $date_entered;
return $this;
}
public function getDateModified(): ?\DateTimeInterface
{
return $this->date_modified;
}
public function setDateModified(?\DateTimeInterface $date_modified): self
{
$this->date_modified = $date_modified;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getModifiedUser(): ?User
{
return $this->modified_user;
}
public function setModifiedUser(?User $modified_user): self
{
$this->modified_user = $modified_user;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getStockId(): ?string
{
return $this->stock_id;
}
public function setStockId(?string $stock_id): self
{
$this->stock_id = $stock_id;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getC1Id(): ?string
{
return $this->c1id;
}
public function setC1Id(?string $c1id): self
{
$this->c1id = $c1id;
return $this;
}
/**
* @return Collection<int, IncomingInvoice>
*/
public function getIncomingInvoices(): Collection
{
return $this->incomingInvoices;
}
public function addIncomingInvoice(IncomingInvoice $incomingInvoice): self
{
if (!$this->incomingInvoices->contains($incomingInvoice)) {
$this->incomingInvoices->add($incomingInvoice);
$incomingInvoice->setStorage($this);
}
return $this;
}
public function removeIncomingInvoice(IncomingInvoice $incomingInvoice): self
{
if ($this->incomingInvoices->removeElement($incomingInvoice)) {
// set the owning side to null (unless already changed)
if ($incomingInvoice->getStorage() === $this) {
$incomingInvoice->setStorage(null);
}
}
return $this;
}
/**
* @return Collection<int, IncomingInvoiceProduct>
*/
public function getIncomingInvoiceProducts(): Collection
{
return $this->incomingInvoiceProducts;
}
public function addIncomingInvoiceProduct(IncomingInvoiceProduct $incomingInvoiceProduct): self
{
if (!$this->incomingInvoiceProducts->contains($incomingInvoiceProduct)) {
$this->incomingInvoiceProducts->add($incomingInvoiceProduct);
$incomingInvoiceProduct->setStorage($this);
}
return $this;
}
public function removeIncomingInvoiceProduct(IncomingInvoiceProduct $incomingInvoiceProduct): self
{
if ($this->incomingInvoiceProducts->removeElement($incomingInvoiceProduct)) {
// set the owning side to null (unless already changed)
if ($incomingInvoiceProduct->getStorage() === $this) {
$incomingInvoiceProduct->setStorage(null);
}
}
return $this;
}
/**
* @return Collection<int, Orders>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Orders $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setStorage($this);
}
return $this;
}
public function removeOrder(Orders $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getStorage() === $this) {
$order->setStorage(null);
}
}
return $this;
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->date_entered = new \DateTime();
}
// #[ORM\PrePersist]
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->date_modified = new \DateTime();
}
public function getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Products $product): self
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setStorage($this);
}
return $this;
}
public function removeProduct(Products $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getStorage() === $this) {
$product->setStorage(null);
}
}
return $this;
}
/**
* @return Collection<int, StorageElement>
*/
public function getStorageElements(): Collection
{
return $this->storageElements;
}
public function addStorageElement(StorageElement $storageElement): self
{
if (!$this->storageElements->contains($storageElement)) {
$this->storageElements->add($storageElement);
$storageElement->setStorage($this);
}
return $this;
}
public function removeStorageElement(StorageElement $storageElement): self
{
if ($this->storageElements->removeElement($storageElement)) {
// set the owning side to null (unless already changed)
if ($storageElement->getStorage() === $this) {
$storageElement->setStorage(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductBalanceInStorage>
*/
public function getProductBalanceInStorages(): Collection
{
return $this->productBalanceInStorages;
}
public function addProductBalanceInStorage(ProductBalanceInStorage $productBalanceInStorage): self
{
if (!$this->productBalanceInStorages->contains($productBalanceInStorage)) {
$this->productBalanceInStorages->add($productBalanceInStorage);
$productBalanceInStorage->setStorage($this);
}
return $this;
}
public function removeProductBalanceInStorage(ProductBalanceInStorage $productBalanceInStorage): self
{
if ($this->productBalanceInStorages->removeElement($productBalanceInStorage)) {
// set the owning side to null (unless already changed)
if ($productBalanceInStorage->getStorage() === $this) {
$productBalanceInStorage->setStorage(null);
}
}
return $this;
}
/**
* @return Collection<int, Location>
*/
public function getLocation(): Collection
{
return $this->location;
}
public function addLocation(Location $location): self
{
if (!$this->location->contains($location)) {
$this->location->add($location);
}
return $this;
}
public function removeLocation(Location $location): self
{
$this->location->removeElement($location);
return $this;
}
}