<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MeasurmentUnitRepository;
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: MeasurmentUnitRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
order: ['id' => 'DESC']
)]
#[ApiFilter(SearchFilter::class, properties: ['code1c' => 'exact'])]
#[ORM\HasLifecycleCallbacks]
class MeasurmentUnit
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read', 'write', 'order:read', 'pre_order:read', 'load_invoice:read', 'product:read', 'cat:read', 'order_product:read', 'site_product:read'])]
private ?int $id = null;
#[ORM\Column(length: 100, nullable: true)]
#[Groups(['read', 'write', 'order:read', 'pre_order:read', 'load_invoice:read', 'product:read', 'cat:read', 'order_product:read', 'site_product:read'])]
private ?string $short_name = null;
#[ORM\Column(length: 255)]
#[Groups(['read', 'write', 'order:read', 'pre_order:read', 'load_invoice:read', 'product:read', 'cat:read', 'order_product:read', 'site_product: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\Column(nullable: true)]
private ?int $created_by = null;
#[ORM\Column(nullable: true)]
private ?int $modified_user_id = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['read', 'write', 'order:read', 'pre_order:read', 'load_invoice:read'])]
private ?string $code1c = null;
#[ORM\OneToMany(mappedBy: 'measurment_unit', targetEntity: SiteProducts::class)]
private Collection $siteProducts;
public function __construct()
{
$this->siteProducts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getShortName(): ?string
{
return $this->short_name;
}
public function setShortName(string $short_name): self
{
$this->short_name = $short_name;
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->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(): ?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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
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();
}
/**
* @return Collection<int, SiteProducts>
*/
public function getSiteProducts(): Collection
{
return $this->siteProducts;
}
public function addSiteProduct(SiteProducts $siteProduct): self
{
if (!$this->siteProducts->contains($siteProduct)) {
$this->siteProducts->add($siteProduct);
$siteProduct->setMeasurmentUnit($this);
}
return $this;
}
public function removeSiteProduct(SiteProducts $siteProduct): self
{
if ($this->siteProducts->removeElement($siteProduct)) {
// set the owning side to null (unless already changed)
if ($siteProduct->getMeasurmentUnit() === $this) {
$siteProduct->setMeasurmentUnit(null);
}
}
return $this;
}
}