<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\OrdersRepository;
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 ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use App\Controller\OrdersController;
#[ORM\Entity(repositoryClass: OrdersRepository::class)]
#[ApiResource(
operations: [
new Get(),
new Post(),
new Delete(),
new GetCollection(),
new Put(),
new Post(
name: 'synced_orders',
uriTemplate: '/orders/synced',
controller: OrdersController::class
)
],
normalizationContext: ['groups' => ['order:read']],
denormalizationContext: ['groups' => ['order:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'code1c' => 'exact',
'synced' => 'exact',
'status' => 'exact',
'createdIn' => 'exact',
'account.name' => 'ipartial',
'account.manager' => 'exact',
'account.user' => 'exact',
'manager.username' => 'ipartial',
'manager.firstName' => 'ipartial',
'manager.lastName' => 'ipartial',
]
)]
#[ORM\HasLifecycleCallbacks]
class Orders
{
#[Groups(['order:read', 'order_product:write','load_invoice:read', 'order:write', 'media_object:read', 'agreements:read', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['order:read', 'order_product:write','load_invoice:read', 'order:write', 'media_object:read', 'agreements:read', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['order:read', 'order_product:write','load_invoice:read', 'order:write','media_object:read', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateModified = null;
#[ORM\Column(nullable: true)]
private ?int $created_by = null;
#[ORM\Column(nullable: true)]
private ?int $modified_user_id = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'pre_order:read'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?User $client = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'pre_order:read', 'load_invoice:read'])]
#[ORM\ManyToOne(inversedBy: 'managerOrders')]
private ?User $manager = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'pre_order_product:read', 'pre_order:read', 'load_invoice:read'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?Accounts $account = null;
#[Groups(['order:read', 'order_product:write','load_invoice:read', 'order:write', 'pre_order_product:read', 'pre_order:read', 'load_invoice:read'])]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateOrder = null;
#[Groups(['order:read', 'order_product:write','load_invoice:read', 'order:write', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $status = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[Groups(['order:read', 'order_product:write', 'load_invoice:read', 'order:write', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $paymentMethod = null;
#[Groups(['order:read', 'order_product:write', 'load_invoice:read', 'order:write', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(nullable: true)]
private ?float $sumOrdered = null;
#[Groups(['order:read', 'order_product:write', 'load_invoice:read', 'order:write', 'media_object:read', 'agreements:read', 'pre_order_product:read', 'pre_order:read'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $code1c = null;
#[Groups(['order:read', 'order_product:write', 'load_invoice:read', 'order:write'])]
#[ORM\Column(length: 10, nullable: true)]
private ?string $curency = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?float $curencyRate = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?float $discountTotal = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?int $discount_percent = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressStreet = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressCity = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressBuilding = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressPost = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressCountry = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $shippingAddressDate = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?int $copyOrderId = null;
#[ApiProperty(writable: true)]
#[Groups(['order:read', 'order:write'])]
#[ORM\OneToMany(mappedBy: 'order', targetEntity: OrderProduct::class, cascade:['persist', 'remove'])]
#[MaxDepth(4)]
private Collection $orderProducts;
#[MaxDepth(1)]
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?Storage $storage = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $shippingMethod = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $dovirenistSeries = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $dovirenistNumber = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?bool $isGot = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dovirenistDate = null;
#[Groups(['order_product:write', 'order:write'])]
#[ORM\ManyToOne]
private ?User $releaseAllowed = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?bool $isReleaseAllowed = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?bool $isChecked = null;
#[Groups(['order_product:write', 'order:write'])]
#[ORM\ManyToOne]
private ?User $checked = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $carrier = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(length: 10, nullable: true)]
private ?string $id_1c = null;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\Column(nullable: true)]
private ?float $sumTransport = null;
#[MaxDepth(1)]
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?PreOrder $preOrder = null;
// #[ORM\ManyToOne(inversedBy: 'orders')]
// private ?LoadInvoice $load_invoice = null;
// #[ORM\OneToMany(mappedBy: '_order', targetEntity: LoadInvoice::class)]
// private Collection $loadInvoices;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\OneToMany(mappedBy: 'order', targetEntity: Accepted::class)]
private Collection $accepteds;
#[Groups(['order:read', 'order_product:write', 'order:write'])]
#[ORM\ManyToMany(targetEntity: LoadInvoice::class, inversedBy: 'orders')]
private Collection $loadInvoice;
#[ORM\OneToMany(mappedBy: 'orders', targetEntity: Calculations::class)]
private Collection $calculations;
#[Groups([ 'order_product:write'])]
#[ORM\OneToMany(mappedBy: 'orders', targetEntity: MediaObject::class)]
private Collection $mediaObjects;
#[Groups(['order:read', 'order_product:write', 'order:write', 'pre_order_product:read', 'pre_order:read', 'load_invoice:read'])]
#[ORM\Column(nullable: true)]
private ?bool $synced = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'load_invoice:read'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?Agreements $agreement = null;
#[Groups(['order:read', 'order_product:write', 'order:write', 'load_invoice:read'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $createdIn = 'crm';
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'parentOrders')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $parentOrders;
#[Groups(['order:read','order:write'])]
#[ORM\ManyToOne(inversedBy: 'orders')]
private ?AccountAddress $address = null;
#[Groups(['order:read','order:write'])]
#[ORM\Column(nullable: true)]
private ?bool $deleted = null;
public function __construct()
{
$this->orderProducts = new ArrayCollection();
// $this->loadInvoices = new ArrayCollection();
$this->accepteds = new ArrayCollection();
$this->loadInvoice = new ArrayCollection();
$this->calculations = new ArrayCollection();
$this->mediaObjects = new ArrayCollection();
$this->parentOrders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(?string $id): self
{
$this->id = $id;
return $this;
}
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(): ?int
{
return $this->created_by;
}
public function setCreatedBy(?int $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getModifiedUserId(): ?int
{
return $this->modified_user_id;
}
public function setModifiedUserId(?int $modified_user_id): self
{
$this->modified_user_id = $modified_user_id;
return $this;
}
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;
}
public function getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
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 getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
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->discount_percent;
}
public function setDiscountPercent(?int $discount_percent): self
{
$this->discount_percent = $discount_percent;
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, OrderProduct>
*/
public function getOrderProducts(): Collection
{
return $this->orderProducts;
}
public function addOrderProduct(OrderProduct $orderProduct): self
{
if (!$this->orderProducts->contains($orderProduct)) {
$this->orderProducts->add($orderProduct);
$orderProduct->setOrder($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->getOrder() === $this) {
$orderProduct->setOrder(null);
}
}
return $this;
}
public function getStorage(): ?Storage
{
return $this->storage;
}
public function setStorage(?Storage $storage): self
{
$this->storage = $storage;
return $this;
}
public function getShippingMethod(): ?string
{
return $this->shippingMethod;
}
public function setShippingMethod(?string $shippingMethod): self
{
$this->shippingMethod = $shippingMethod;
return $this;
}
public function getDovirenistSeries(): ?string
{
return $this->dovirenistSeries;
}
public function setDovirenistSeries(?string $dovirenistSeries): self
{
$this->dovirenistSeries = $dovirenistSeries;
return $this;
}
public function getDovirenistNumber(): ?string
{
return $this->dovirenistNumber;
}
public function setDovirenistNumber(?string $dovirenistNumber): self
{
$this->dovirenistNumber = $dovirenistNumber;
return $this;
}
public function isIsGot(): ?bool
{
return $this->isGot;
}
public function setIsGot(?bool $isGot): self
{
$this->isGot = $isGot;
return $this;
}
public function getDovirenistDate(): ?\DateTimeInterface
{
return $this->dovirenistDate;
}
public function setDovirenistDate(?\DateTimeInterface $dovirenistDate): self
{
$this->dovirenistDate = $dovirenistDate;
return $this;
}
public function getReleaseAllowed(): ?User
{
return $this->releaseAllowed;
}
public function setReleaseAllowed(?User $releaseAllowed): self
{
$this->releaseAllowed = $releaseAllowed;
return $this;
}
public function isIsReleaseAllowed(): ?bool
{
return $this->isReleaseAllowed;
}
public function setIsReleaseAllowed(?bool $isReleaseAllowed): self
{
$this->isReleaseAllowed = $isReleaseAllowed;
return $this;
}
public function getIsChecked(): ?bool
{
return $this->isChecked;
}
public function setIsChecked(?bool $isChecked): self
{
$this->isChecked = $isChecked;
return $this;
}
public function getChecked(): ?User
{
return $this->checked;
}
public function setChecked(?User $checked): self
{
$this->checked = $checked;
return $this;
}
public function getCarrier(): ?string
{
return $this->carrier;
}
public function setCarrier(?string $carrier): self
{
$this->carrier = $carrier;
return $this;
}
public function getId1c(): ?string
{
return $this->id_1c;
}
public function setId1c(?string $id_1c): self
{
$this->id_1c = $id_1c;
return $this;
}
public function getSumTransport(): ?float
{
return $this->sumTransport;
}
public function setSumTransport(?float $sumTransport): self
{
$this->sumTransport = $sumTransport;
return $this;
}
public function getPreOrder(): ?PreOrder
{
return $this->preOrder;
}
public function setPreOrder(?PreOrder $preOrder): self
{
$this->preOrder = $preOrder;
return $this;
}
// public function getLoadInvoice(): ?LoadInvoice
// {
// return $this->load_invoice;
// }
// public function setLoadInvoice(?LoadInvoice $load_invoice): self
// {
// $this->load_invoice = $load_invoice;
// 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->setOrder($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->getOrder() === $this) {
// $loadInvoice->setOrder(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->setOrder($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->getOrder() === $this) {
$accepted->setOrder(null);
}
}
return $this;
}
/**
* @return Collection<int, LoadInvoice>
*/
public function getLoadInvoice(): Collection
{
return $this->loadInvoice;
}
public function addLoadInvoice(LoadInvoice $loadInvoice): self
{
if (!$this->loadInvoice->contains($loadInvoice)) {
$this->loadInvoice->add($loadInvoice);
}
return $this;
}
public function removeLoadInvoice(LoadInvoice $loadInvoice): self
{
$this->loadInvoice->removeElement($loadInvoice);
return $this;
}
/**
* @return Collection<int, Calculations>
*/
public function getCalculations(): Collection
{
return $this->calculations;
}
public function addCalculation(Calculations $calculation): self
{
if (!$this->calculations->contains($calculation)) {
$this->calculations->add($calculation);
$calculation->setOrders($this);
}
return $this;
}
public function removeCalculation(Calculations $calculation): self
{
if ($this->calculations->removeElement($calculation)) {
// set the owning side to null (unless already changed)
if ($calculation->getOrders() === $this) {
$calculation->setOrders(null);
}
}
return $this;
}
/**
* @return Collection<int, MediaObject>
*/
public function getMediaObjects(): Collection
{
return $this->mediaObjects;
}
public function addMediaObject(MediaObject $mediaObject): self
{
if (!$this->mediaObjects->contains($mediaObject)) {
$this->mediaObjects->add($mediaObject);
$mediaObject->setOrders($this);
}
return $this;
}
public function removeMediaObject(MediaObject $mediaObject): self
{
if ($this->mediaObjects->removeElement($mediaObject)) {
// set the owning side to null (unless already changed)
if ($mediaObject->getOrders() === $this) {
$mediaObject->setOrders(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();
}
public function isSynced(): ?bool
{
return $this->synced;
}
public function setSynced(?bool $synced): self
{
$this->synced = $synced;
return $this;
}
public function getAgreement(): ?Agreements
{
return $this->agreement;
}
public function setAgreement(?Agreements $agreement): self
{
$this->agreement = $agreement;
return $this;
}
public function getCreatedIn(): ?string
{
return $this->createdIn;
}
public function setCreatedIn(?string $createdIn): self
{
$this->createdIn = $createdIn;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getParentOrders(): Collection
{
return $this->parentOrders;
}
public function addParentOrder(self $parentOrder): self
{
if (!$this->parentOrders->contains($parentOrder)) {
$this->parentOrders->add($parentOrder);
$parentOrder->setParent($this);
}
return $this;
}
public function removeParentOrder(self $parentOrder): self
{
if ($this->parentOrders->removeElement($parentOrder)) {
// set the owning side to null (unless already changed)
if ($parentOrder->getParent() === $this) {
$parentOrder->setParent(null);
}
}
return $this;
}
public function getAddress(): ?AccountAddress
{
return $this->address;
}
public function setAddress(?AccountAddress $address): self
{
$this->address = $address;
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(?bool $deleted): static
{
$this->deleted = $deleted;
return $this;
}
}