<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\AgreementsRepository;
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;
use Symfony\Component\Serializer\Annotation\MaxDepth;
#[ORM\Entity(repositoryClass: AgreementsRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['agreements:read']],
denormalizationContext: ['groups' => ['agreements:write']],
order: ['id' => 'DESC']
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'name' => 'ipartial',
'account.id' => 'exact',
'virtual' => 'exact',
'account.user.id' => 'exact',
'account.name' => 'ipartial',
'account.manager' => 'exact',
]
)]
class Agreements
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[Groups(['agreements:read', 'agreements:write', 'agreements:read', 'order:read', 'order_product:read', 'job:read', 'account:read'])]
#[ORM\Column]
private ?int $id = null;
#[Groups(['agreements:read', 'agreements:write', 'agreements:read', 'order:read', 'order_product:read', 'job:read', 'account:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['agreements:read', 'agreements:write', 'agreements:read', 'order:read', 'order_product:read', 'job:read', 'account:read'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $code1c = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateEntered = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $type = null;
#[MaxDepth(1)]
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\ManyToOne(inversedBy: 'organization')]
private ?Accounts $organization = null;
#[MaxDepth(1)]
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\ManyToOne(inversedBy: 'agreements')]
private ?Accounts $account = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $curency = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(nullable: true)]
private ?float $maxBorg = 0;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $typePayment = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(nullable: true)]
private ?bool $paymentInCash = null;
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(nullable: true)]
private ?int $dayDelay = null;
#[MaxDepth(1)]
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\OneToMany(mappedBy: 'agreement', targetEntity: Calculations::class, cascade:['persist'])]
private Collection $calculations;
#[MaxDepth(1)]
#[ORM\OneToMany(mappedBy: 'agreement', targetEntity: Orders::class)]
private Collection $orders;
#[MaxDepth(1)]
#[ORM\OneToMany(mappedBy: 'agreement', targetEntity: Prices::class)]
private Collection $prices;
#[MaxDepth(1)]
#[Groups(['agreements:read'])]
#[ORM\OneToMany(mappedBy: 'virtualAgreementSpecfication', targetEntity: Accounts::class)]
private Collection $accounts;
#[MaxDepth(1)]
#[Groups(['agreements:read', 'agreements:write'])]
#[ORM\Column(nullable: true)]
private ?bool $virtual = null;
public function __construct()
{
$this->calculations = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->prices = new ArrayCollection();
$this->accounts = 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 getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): self
{
$this->code1c = $code1c;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(?\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getOrganization(): ?Accounts
{
return $this->organization;
}
public function setOrganization(?Accounts $organization): self
{
$this->organization = $organization;
return $this;
}
public function getAccount(): ?Accounts
{
return $this->account;
}
public function setAccount(?Accounts $account): self
{
$this->account = $account;
return $this;
}
public function getCurency(): ?string
{
return $this->curency;
}
public function setCurency(?string $curency): self
{
$this->curency = $curency;
return $this;
}
public function getMaxBorg(): ?float
{
return $this->maxBorg;
}
public function setMaxBorg(?float $maxBorg): self
{
$this->maxBorg = $maxBorg;
return $this;
}
public function getTypePayment(): ?string
{
return $this->typePayment;
}
public function setTypePayment(?string $typePayment): self
{
$this->typePayment = $typePayment;
return $this;
}
public function isPaymentInCash(): ?bool
{
return $this->paymentInCash;
}
public function setPaymentInCash(?bool $paymentInCash): self
{
$this->paymentInCash = $paymentInCash;
return $this;
}
public function getDayDelay(): ?int
{
return $this->dayDelay;
}
public function setDayDelay(?int $dayDelay): self
{
$this->dayDelay = $dayDelay;
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->setAgreement($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->getAgreement() === $this) {
$calculation->setAgreement(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->setAgreement($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->getAgreement() === $this) {
$order->setAgreement(null);
}
}
return $this;
}
/**
* @return Collection<int, Prices>
*/
public function getPrices(): Collection
{
return $this->prices;
}
public function addPrice(Prices $price): static
{
if (!$this->prices->contains($price)) {
$this->prices->add($price);
$price->setAgreement($this);
}
return $this;
}
public function removePrice(Prices $price): static
{
if ($this->prices->removeElement($price)) {
// set the owning side to null (unless already changed)
if ($price->getAgreement() === $this) {
$price->setAgreement(null);
}
}
return $this;
}
/**
* @return Collection<int, Accounts>
*/
public function getAccounts(): Collection
{
return $this->accounts;
}
public function addAccount(Accounts $account): static
{
if (!$this->accounts->contains($account)) {
$this->accounts->add($account);
$account->setVirtualAgreementSpecfication($this);
}
return $this;
}
public function removeAccount(Accounts $account): static
{
if ($this->accounts->removeElement($account)) {
// set the owning side to null (unless already changed)
if ($account->getVirtualAgreementSpecfication() === $this) {
$account->setVirtualAgreementSpecfication(null);
}
}
return $this;
}
public function isVirtual(): ?bool
{
return $this->virtual;
}
public function setVirtual(?bool $virtual): static
{
$this->virtual = $virtual;
return $this;
}
}