<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PreOrderRepository;
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;
#[ORM\Entity(repositoryClass: PreOrderRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['pre_order_product:read', 'pre_order:read']],
denormalizationContext: ['groups' => ['pre_order:write']],
order: ['id' => 'DESC'],
)]
#[ORM\HasLifecycleCallbacks]
#[ApiFilter(
SearchFilter::class,
properties: [
'code1c' => 'exact',
'account.name' => 'ipartial',
'account.manager' => 'exact',
'manager.username' => 'ipartial',
'manager.firstName' => 'ipartial',
'manager.lastName' => 'ipartial',
'synced' => 'exact',
'client.id' => 'exact'
]
)]
class PreOrder
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
private ?int $id = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write','order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateModified = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\ManyToOne]
#[MaxDepth(1)]
private ?User $createdBy = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\ManyToOne]
#[MaxDepth(1)]
private ?User $modifiedUser = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateOrder = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $status = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $paymentMethod = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\Column(nullable: true)]
private ?float $sumOrdered = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 10, nullable: true)]
private ?string $curency = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $curencyRate = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?float $discountTotal = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?int $discountPercent = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressStreet = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressCity = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressBuilding = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressPost = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressCountry = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressDate = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?int $copyOrderId = null;
#[MaxDepth(6)]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\OneToMany(mappedBy: 'preOrder', targetEntity: PreOrderProduct::class, cascade:['persist'])]
private Collection $preOrderProducts;
#[MaxDepth(1)]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\OneToMany(mappedBy: 'preOrder', targetEntity: Orders::class)]
private Collection $orders;
#[MaxDepth(1)]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\OneToMany(mappedBy: 'pre_order', targetEntity: LoadInvoice::class)]
private Collection $loadInvoices;
#[MaxDepth(1)]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\OneToMany(mappedBy: 'pre_order', targetEntity: Accepted::class)]
private Collection $accepteds;
#[MaxDepth(1)]
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\OneToMany(mappedBy: 'pre_order_product', targetEntity: LoadInvoiceProduct::class)]
private Collection $loadInvoiceProducts;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne(inversedBy: 'preOrders')]
#[MaxDepth(1)]
private ?Accounts $account = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\Column(nullable: true)]
private ?bool $synced = false;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne(inversedBy: 'preOrders')]
private ?User $client = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne(inversedBy: 'ManagerPreOrders')]
private ?User $manager = null;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\ManyToMany(targetEntity: Fees::class, mappedBy: 'pre_orders')]
private Collection $fees;
#[Groups(['pre_order_product:read', 'pre_order:read', 'pre_order:write', 'order:read', 'order_product:read', 'load_invoice:read'])]
#[ORM\ManyToOne(inversedBy: 'pre_orders')]
private ?Coupons $coupons = null;
#[Groups(['pre_order:read', 'pre_order:write'])]
#[ORM\ManyToOne(inversedBy: 'preOrders')]
private ?AccountAddress $address = null;
public function __construct()
{
$this->preOrderProducts = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->loadInvoices = new ArrayCollection();
$this->accepteds = new ArrayCollection();
$this->loadInvoiceProducts = new ArrayCollection();
$this->fees = 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->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 getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getModifiedUser(): ?User
{
return $this->modifiedUser;
}
public function setModifiedUser(?User $modifiedUser): self
{
$this->modifiedUser = $modifiedUser;
return $this;
}
public function getDateOrder(): ?\DateTimeInterface
{
return $this->dateOrder;
}
public function setDateOrder(?\DateTimeInterface $dateOrder): self
{
$this->dateOrder = $dateOrder;
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 getPaymentMethod(): ?string
{
return $this->paymentMethod;
}
public function setPaymentMethod(?string $paymentMethod): self
{
$this->paymentMethod = $paymentMethod;
return $this;
}
public function getSumOrdered(): ?float
{
return $this->sumOrdered;
}
public function setSumOrdered(?float $sumOrdered): self
{
$this->sumOrdered = $sumOrdered;
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;
}
public function getDiscountTotal(): ?float
{
return $this->discountTotal;
}
public function setDiscountTotal(?float $discountTotal): self
{
$this->discountTotal = $discountTotal;
return $this;
}
public function getDiscountPercent(): ?int
{
return $this->discountPercent;
}
public function setDiscountPercent(?int $discountPercent): self
{
$this->discountPercent = $discountPercent;
return $this;
}
public function getShippingAddressStreet(): ?string
{
return $this->shippingAddressStreet;
}
public function setShippingAddressStreet(?string $shippingAddressStreet): self
{
$this->shippingAddressStreet = $shippingAddressStreet;
return $this;
}
public function getShippingAddressCity(): ?string
{
return $this->shippingAddressCity;
}
public function setShippingAddressCity(?string $shippingAddressCity): self
{
$this->shippingAddressCity = $shippingAddressCity;
return $this;
}
public function getShippingAddressBuilding(): ?string
{
return $this->shippingAddressBuilding;
}
public function setShippingAddressBuilding(?string $shippingAddressBuilding): self
{
$this->shippingAddressBuilding = $shippingAddressBuilding;
return $this;
}
public function getShippingAddressPost(): ?string
{
return $this->shippingAddressPost;
}
public function setShippingAddressPost(?string $shippingAddressPost): self
{
$this->shippingAddressPost = $shippingAddressPost;
return $this;
}
public function getShippingAddressCountry(): ?string
{
return $this->shippingAddressCountry;
}
public function setShippingAddressCountry(?string $shippingAddressCountry): self
{
$this->shippingAddressCountry = $shippingAddressCountry;
return $this;
}
public function getShippingAddressDate(): ?string
{
return $this->shippingAddressDate;
}
public function setShippingAddressDate(?string $shippingAddressDate): self
{
$this->shippingAddressDate = $shippingAddressDate;
return $this;
}
public function getCopyOrderId(): ?int
{
return $this->copyOrderId;
}
public function setCopyOrderId(?int $copyOrderId): self
{
$this->copyOrderId = $copyOrderId;
return $this;
}
/**
* @return Collection<int, PreOrderProduct>
*/
public function getPreOrderProducts(): Collection
{
return $this->preOrderProducts;
}
public function addPreOrderProduct(PreOrderProduct $preOrderProduct): self
{
if (!$this->preOrderProducts->contains($preOrderProduct)) {
$this->preOrderProducts->add($preOrderProduct);
$preOrderProduct->setPreOrder($this);
}
return $this;
}
public function removePreOrderProduct(PreOrderProduct $preOrderProduct): self
{
if ($this->preOrderProducts->removeElement($preOrderProduct)) {
// set the owning side to null (unless already changed)
if ($preOrderProduct->getPreOrder() === $this) {
$preOrderProduct->setPreOrder(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->setPreOrder($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->getPreOrder() === $this) {
$order->setPreOrder(null);
}
}
return $this;
}
/**
* @return Collection<int, LoadInvoice>
*/
public function getLoadInvoices(): Collection
{
return $this->loadInvoices;
}
public function addLoadInvoice(LoadInvoice $loadInvoice): self
{
if (!$this->loadInvoices->contains($loadInvoice)) {
$this->loadInvoices->add($loadInvoice);
$loadInvoice->setPreOrder($this);
}
return $this;
}
public function removeLoadInvoice(LoadInvoice $loadInvoice): self
{
if ($this->loadInvoices->removeElement($loadInvoice)) {
// set the owning side to null (unless already changed)
if ($loadInvoice->getPreOrder() === $this) {
$loadInvoice->setPreOrder(null);
}
}
return $this;
}
/**
* @return Collection<int, Accepted>
*/
public function getAccepteds(): Collection
{
return $this->accepteds;
}
public function addAccepted(Accepted $accepted): self
{
if (!$this->accepteds->contains($accepted)) {
$this->accepteds->add($accepted);
$accepted->setPreOrder($this);
}
return $this;
}
public function removeAccepted(Accepted $accepted): self
{
if ($this->accepteds->removeElement($accepted)) {
// set the owning side to null (unless already changed)
if ($accepted->getPreOrder() === $this) {
$accepted->setPreOrder(null);
}
}
return $this;
}
/**
* @return Collection<int, LoadInvoiceProduct>
*/
public function getLoadInvoiceProducts(): Collection
{
return $this->loadInvoiceProducts;
}
public function addLoadInvoiceProduct(LoadInvoiceProduct $loadInvoiceProduct): self
{
if (!$this->loadInvoiceProducts->contains($loadInvoiceProduct)) {
$this->loadInvoiceProducts->add($loadInvoiceProduct);
$loadInvoiceProduct->setPreOrderProduct($this);
}
return $this;
}
public function removeLoadInvoiceProduct(LoadInvoiceProduct $loadInvoiceProduct): self
{
if ($this->loadInvoiceProducts->removeElement($loadInvoiceProduct)) {
// set the owning side to null (unless already changed)
if ($loadInvoiceProduct->getPreOrderProduct() === $this) {
$loadInvoiceProduct->setPreOrderProduct(null);
}
}
return $this;
}
public function getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
return $this;
}
public function isSynced(): ?bool
{
return $this->synced;
}
public function setSynced(?bool $synced): self
{
$this->synced = $synced;
return $this;
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->dateEntered = new \DateTime();
}
// #[ORM\PrePersist]
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->dateModified = new \DateTime();
}
public function getClient(): ?User
{
return $this->client;
}
public function setClient(?User $client): self
{
$this->client = $client;
return $this;
}
public function getManager(): ?User
{
return $this->manager;
}
public function setManager(?User $manager): self
{
$this->manager = $manager;
return $this;
}
/**
* @return Collection<int, Fees>
*/
public function getFees(): Collection
{
return $this->fees;
}
public function addFee(Fees $fee): self
{
if (!$this->fees->contains($fee)) {
$this->fees->add($fee);
$fee->addPreOrder($this);
}
return $this;
}
public function removeFee(Fees $fee): self
{
if ($this->fees->removeElement($fee)) {
$fee->removePreOrder($this);
}
return $this;
}
public function getCoupons(): ?Coupons
{
return $this->coupons;
}
public function setCoupons(?Coupons $coupons): self
{
$this->coupons = $coupons;
return $this;
}
public function getAddress(): ?AccountAddress
{
return $this->address;
}
public function setAddress(?AccountAddress $address): self
{
$this->address = $address;
return $this;
}
}