<?php
namespace App\Entity\Reference;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Transaction;
use App\Repository\Reference\ReferenceFinancingModeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"reference-financing-mode:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"reference-financing-mode:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
*
* },
* attributes={
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
* @ORM\Entity(repositoryClass=ReferenceFinancingModeRepository::class)
*/
class ReferenceFinancingMode
{
public const TRANSLATION_DOMAIN = 'reference_financing_mode';
public const REFERENCE_FINANCING_MODE_CREDIT = 'reference.financing.mode.CREDIT';
public const REFERENCE_FINANCING_MODE_CASH = 'reference.financing.mode.CASH';
public const REFERENCE_CODE_FINANCING_MODE_CREDIT = 'CREDIT';
public const REFERENCE_CODE_FINANCING_MODE_CASH = 'CASH';
public const ALL_FINANCING_MODE = [
self::REFERENCE_FINANCING_MODE_CREDIT,
self::REFERENCE_FINANCING_MODE_CASH
];
public const ALL_CODE_FINANCING_MODE = [
self::REFERENCE_CODE_FINANCING_MODE_CREDIT,
self::REFERENCE_CODE_FINANCING_MODE_CASH
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Groups({
* "transaction-item:read",
* "reference-financing-mode:read",
* "business-indication:item:read"
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "transaction-item:read",
* "reference-financing-mode:read",
* "business-indication:item:read"
* })
*/
private ?string $name;
/**
* @ORM\Column(type="string", length=255)
*
* @Groups({
* "transaction-item:read",
* "reference-financing-mode:read",
* "business-indication:item:read"
* })
*/
private ?string $code;
/**
* @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="referenceFinancingMode")
*/
private $transactions;
public function __construct()
{
$this->transactions = 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 getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): self
{
if (!$this->transactions->contains($transaction)) {
$this->transactions[] = $transaction;
$transaction->setReferenceFinancingMode($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): self
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getReferenceFinancingMode() === $this) {
$transaction->setReferenceFinancingMode(null);
}
}
return $this;
}
}