<?php
namespace App\Entity\Department;
use App\Entity\Docs\Finance\Receipt;
use App\Entity\Docs\Finance\Requisition;
use App\Entity\Planning\Action;
use App\Entity\User;
use App\Entity\Company\Company;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Department\Section;
use App\Entity\Docs\Finance\Budget;
use App\Entity\Company\Presentation;
use App\Entity\Utils\TimestampTrait;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use App\State\Providers\AllDepartmentsByCompanyUserProcessor;
use App\Repository\Department\DepartmentRepository;
/**
* @ORM\Entity(repositoryClass="App\Repository\Department\DepartmentRepository")
* @ORM\HasLifecycleCallbacks()
*/
#[GetCollection(
uriTemplate:"/v2/departments/my",
provider:AllDepartmentsByCompanyUserProcessor::class,
normalizationContext:["groups" => ["budget:get:all"]],
)]
#[Get(
normalizationContext:["groups" => ["budget:get:all"]]
)]
class Department
{
use TimestampTrait;
const TAGS = [
self::TAG_ADMIN,
self::TAG_FINANCE,
self::TAG_CEO_DEPARTMENT,
self::TAG_NORMAL,
self::TAG_HUMAN_RESOURCE,
self::TAG_OPERATION,
self::TAG_INTERNAL_CONTROL,
];
const TAG_FINANCE= "FINANCE";
const TAG_CEO_DEPARTMENT= "CEO_DEPARTMENT";
const TAG_ADMIN= "ADMIN";
const TAG_NORMAL= "NORMAL";
const TAG_HUMAN_RESOURCE= "HUMAN_RESOURCE";
const TAG_OPERATION= "OPERATION";
const TAG_INTERNAL_CONTROL= "INTERNAL_CONTROL";
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"rmq:user","budget:get:all","user.details", "requisition:fread","requisition:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(min=3)
* @Groups({"user:fRead","user.details","requisition:fread","receipt:fRead","atime:fread","presence:read","rmq:user","budget:get:all", "requisition:fread","requisition:read"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Company\Company", mappedBy="departments")
*/
private $companies;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Department\Section", mappedBy="department")
*/
private $sections;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="department")
*/
private $users;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="departmentsAdded")
* @Groups({"rmq:user"})
*/
private $company;
/**
* @ORM\ManyToMany(targetEntity=Presentation::class, inversedBy="departments")
*/
private $natures;
/**
* @ORM\OneToMany(targetEntity=Budget::class, mappedBy="department")
*/
private $budgets;
/**
* @ORM\OneToMany(targetEntity=Requisition::class, mappedBy="department")
*/
private $requisitions;
/**
* @ORM\OneToMany(targetEntity=\App\Entity\Docs\Finance\V2\Budget\Budget::class, mappedBy="departement")
*/
private $budgetsV2;
/**
* @Assert\Choice(choices=Department::TAGS, message="La valeur doit ĂȘtre soit FINANCE, CEO_DEPARTMENT, ADMIN ou NORMAL")
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:fRead","requisition:fread","receipt:fRead","atime:fread","presence:read","rmq:user","budget:get:all", "requisition:fread","requisition:read"})
*/
private $tag;
/**
* @ORM\OneToMany(targetEntity=Receipt::class, mappedBy="department")
*/
private $receipts;
/**
* @Groups({"user:fRead","requisition:fread","receipt:fRead","atime:fread","presence:read","rmq:user","budget:get:all", "requisition:fread","requisition:read"})
* @ORM\Column(type="integer", nullable=true)
*/
private $numOrderCompany;
/**
* @ORM\OneToMany(targetEntity=Action::class, mappedBy="department")
*/
private $actions;
static public function getTagsLabels ()
{
$normalTags = [];
foreach (self::TAGS as $key => $tag) {
$normalTags[$tag] = $tag;
}
return $normalTags;
}
public function __construct()
{
$this->companies = new ArrayCollection();
$this->sections = new ArrayCollection();
$this->users = new ArrayCollection();
$this->natures = new ArrayCollection();
$this->projects = new ArrayCollection();
$this->budgets = new ArrayCollection();
$this->requisitions = new ArrayCollection();
$this->budgetsV2 = new ArrayCollection();
$this->tag = self::TAG_NORMAL;
$this->receipts = new ArrayCollection();
$this->actions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
#[Groups(["budget:get:all"])]
public function getIri()
{
return "/api/departments/". $this->getId();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
$company->addDepartment($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->contains($company)) {
$this->companies->removeElement($company);
$company->removeDepartment($this);
}
return $this;
}
/**
* @return Collection|Section[]
*/
public function getSections(): Collection
{
return $this->sections;
}
public function addSection(Section $section): self
{
if (!$this->sections->contains($section)) {
$this->sections[] = $section;
$section->setDepartment($this);
}
return $this;
}
public function removeSection(Section $section): self
{
if ($this->sections->contains($section)) {
$this->sections->removeElement($section);
// set the owning side to null (unless already changed)
if ($section->getDepartment() === $this) {
$section->setDepartment(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setDepartment($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
// set the owning side to null (unless already changed)
if ($user->getDepartment() === $this) {
$user->setDepartment(null);
}
}
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|Presentation[]
*/
public function getNatures(): Collection
{
return $this->natures;
}
public function addNature(Presentation $nature): self
{
if (!$this->natures->contains($nature)) {
$this->natures[] = $nature;
}
return $this;
}
public function removeNature(Presentation $nature): self
{
if ($this->natures->contains($nature)) {
$this->natures->removeElement($nature);
}
return $this;
}
/**
* @return Collection|Budget[]
*/
public function getBudgets(): Collection
{
return $this->budgets;
}
public function addBudget(Budget $budget): self
{
if (!$this->budgets->contains($budget)) {
$this->budgets[] = $budget;
$budget->setDepartment($this);
}
return $this;
}
public function removeBudget(Budget $budget): self
{
if ($this->budgets->removeElement($budget)) {
// set the owning side to null (unless already changed)
if ($budget->getDepartment() === $this) {
$budget->setDepartment(null);
}
}
return $this;
}
/**
* @return User
*/
public function firstUser(): ?User
{
$user = $this->getUsers()->first();
if ($user) {
return $user??null;
}
return null;
}
/**
* @return Collection|Requisition[]
*/
public function getRequisitions(): Collection
{
return $this->requisitions;
}
public function addRequisition(Requisition $requisition): self
{
if (!$this->requisitions->contains($requisition)) {
$this->requisitions[] = $requisition;
$requisition->setDepartment($this);
}
return $this;
}
public function removeRequisition(Requisition $requisition): self
{
if ($this->requisitions->removeElement($requisition)) {
// set the owning side to null (unless already changed)
if ($requisition->getDepartment() === $this) {
$requisition->setDepartment(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Docs\Finance\V2\Budget\Budget>
*/
public function getBudgetsV2(): Collection
{
return $this->budgetsV2;
}
public function addBudgetsV2(\App\Entity\Docs\Finance\V2\Budget\Budget $budgetsV2): self
{
if (!$this->budgetsV2->contains($budgetsV2)) {
$this->budgetsV2[] = $budgetsV2;
$budgetsV2->setDepartement($this);
}
return $this;
}
public function removeBudgetsV2(\App\Entity\Docs\Finance\V2\Budget\Budget $budgetsV2): self
{
if ($this->budgetsV2->removeElement($budgetsV2)) {
// set the owning side to null (unless already changed)
if ($budgetsV2->getDepartement() === $this) {
$budgetsV2->setDepartement(null);
}
}
return $this;
}
public function getTag(): ?string
{
return $this->tag;
}
public function setTag(string $tag): self
{
$this->tag = $tag;
return $this;
}
/**
* @return Collection<int, Receipt>
*/
public function getReceipts(): Collection
{
return $this->receipts;
}
public function addReceipt(Receipt $receipt): self
{
if (!$this->receipts->contains($receipt)) {
$this->receipts[] = $receipt;
$receipt->setDepartment($this);
}
return $this;
}
public function removeReceipt(Receipt $receipt): self
{
if ($this->receipts->removeElement($receipt)) {
// set the owning side to null (unless already changed)
if ($receipt->getDepartment() === $this) {
$receipt->setDepartment(null);
}
}
return $this;
}
public function getNumOrderCompany(): ?int
{
return $this->numOrderCompany;
}
public function setNumOrderCompany(?int $numOrderCompany): self
{
$this->numOrderCompany = $numOrderCompany;
return $this;
}
/**
* @return Collection<int, Action>
*/
public function getActions(): Collection
{
return $this->actions;
}
public function addAction(Action $action): self
{
if (!$this->actions->contains($action)) {
$this->actions[] = $action;
$action->setDepartment($this);
}
return $this;
}
public function removeAction(Action $action): self
{
if ($this->actions->removeElement($action)) {
// set the owning side to null (unless already changed)
if ($action->getDepartment() === $this) {
$action->setDepartment(null);
}
}
return $this;
}
}