<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PreOrderProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
#[ORM\Entity(repositoryClass: PreOrderProductRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['pre_order_product:read']],
denormalizationContext: ['groups' => ['pre_order_product:write']],
order: ['id' => 'DESC'],
)]
#[ORM\HasLifecycleCallbacks]
#[ApiFilter(SearchFilter::class, properties: ['preOrder' => 'exact'])]
class PreOrderProduct
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
private ?int $id = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\ManyToOne]
#[MaxDepth(3)]
#[ApiProperty(writable: true)]
private ?Products $product = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\ManyToOne]
#[MaxDepth(2)]
#[ApiProperty(writable: true)]
private ?MeasurmentUnit $measurment_unit = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne(inversedBy: 'preOrderProducts', cascade:['persist'])]
#[MaxDepth(2)]
private ?PreOrder $preOrder = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateModified = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read','pre_order:write'])]
#[ORM\ManyToOne]
#[MaxDepth(1)]
private ?User $modified_user = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne]
#[MaxDepth(1)]
private ?User $created_by = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $status = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $count = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\ManyToOne]
#[MaxDepth(1)]
private ?MeasurmentUnit $measurementUnit = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $priceForOne = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $priceIncome = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $markUp = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $sumOrdered = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $discount = 0;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(length: 10, nullable: true)]
private ?string $curency = null;
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read', 'load_invoice:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $curencyRate = 1;
#[MaxDepth(1)]
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\OneToMany(mappedBy: 'preOrderProduct', targetEntity: OrderProduct::class)]
private Collection $orderProducts;
#[MaxDepth(1)]
#[Groups(['pre_order_product:write', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\OneToMany(mappedBy: 'pre_order_product', targetEntity: AcceptedProduct::class)]
private Collection $acceptedProducts;
public function __construct()
{
$this->orderProducts = new ArrayCollection();
$this->acceptedProducts = 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 getProduct(): ?Products
{
return $this->product;
}
public function setProduct(?Products $product): self
{
$this->product = $product;
return $this;
}
public function getMeasurmentUnit(): ?MeasurmentUnit
{
return $this->measurment_unit;
}
public function setMeasurmentUnit(?MeasurmentUnit $measurment_unit): self
{
$this->measurment_unit = $measurment_unit;
return $this;
}
public function getPreOrder(): ?PreOrder
{
return $this->preOrder;
}
public function setPreOrder(?PreOrder $preOrder): self
{
$this->preOrder = $preOrder;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function getDateModified(): ?\DateTimeInterface
{
return $this->dateModified;
}
public function setDateModified(?\DateTimeInterface $dateModified): self
{
$this->dateModified = $dateModified;
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 getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
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 getCount(): ?float
{
return $this->count;
}
public function setCount(?float $count): self
{
$this->count = $count;
return $this;
}
public function getMeasurementUnit(): ?MeasurmentUnit
{
return $this->measurementUnit;
}
public function setMeasurementUnit(?MeasurmentUnit $measurementUnit): self
{
$this->measurementUnit = $measurementUnit;
return $this;
}
public function getPriceForOne(): ?float
{
return $this->priceForOne;
}
public function setPriceForOne(?float $priceForOne): self
{
$this->priceForOne = $priceForOne;
return $this;
}
public function getPriceIncome(): ?float
{
return $this->priceIncome;
}
public function setPriceIncome(?float $priceIncome): self
{
$this->priceIncome = $priceIncome;
return $this;
}
public function getMarkUp(): ?float
{
return $this->markUp;
}
public function setMarkUp(?float $markUp): self
{
$this->markUp = $markUp;
return $this;
}
public function getSumOrdered(): ?float
{
return $this->sumOrdered;
}
public function setSumOrdered(?float $sumOrdered): self
{
$this->sumOrdered = $sumOrdered;
return $this;
}
public function getDiscount(): ?float
{
return $this->discount;
}
public function setDiscount(?float $discount): self
{
$this->discount = $discount;
return $this;
}
public function getCurency(): ?string
{
return $this->curency;
}
public function setCurency(?string $curency): self
{
$this->curency = $curency;
return $this;
}
public function getCurencyRate(): ?float
{
return $this->curencyRate;
}
public function setCurencyRate(?float $curencyRate): self
{
$this->curencyRate = $curencyRate;
return $this;
}
/**
* @return Collection<int, OrderProduct>
*/
public function getOrderProducts(): Collection
{
return $this->orderProducts;
}
public function addOrderProduct(OrderProduct $orderProduct): self
{
if (!$this->orderProducts->contains($orderProduct)) {
$this->orderProducts->add($orderProduct);
$orderProduct->setPreOrderProduct($this);
}
return $this;
}
public function removeOrderProduct(OrderProduct $orderProduct): self
{
if ($this->orderProducts->removeElement($orderProduct)) {
// set the owning side to null (unless already changed)
if ($orderProduct->getPreOrderProduct() === $this) {
$orderProduct->setPreOrderProduct(null);
}
}
return $this;
}
/**
* @return Collection<int, AcceptedProduct>
*/
public function getAcceptedProducts(): Collection
{
return $this->acceptedProducts;
}
public function addAcceptedProduct(AcceptedProduct $acceptedProduct): self
{
if (!$this->acceptedProducts->contains($acceptedProduct)) {
$this->acceptedProducts->add($acceptedProduct);
$acceptedProduct->setPreOrderProduct($this);
}
return $this;
}
public function removeAcceptedProduct(AcceptedProduct $acceptedProduct): self
{
if ($this->acceptedProducts->removeElement($acceptedProduct)) {
// set the owning side to null (unless already changed)
if ($acceptedProduct->getPreOrderProduct() === $this) {
$acceptedProduct->setPreOrderProduct(null);
}
}
return $this;
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->dateEntered = new \DateTime();
}
// #[ORM\PrePersist]
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->dateModified = new \DateTime();
}
}