<?php
namespace App\Entity;
use App\Model\Workflow\Workflow;
use App\Repository\ProjetRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProjetRepository::class)
*/
class Projet
{
public object $workflow;
/**
* @return object
*/
public function getWorkflow(): object
{
return $this->workflow;
}
/**
* @param object $workflow
*/
public function setWorkflow(): void
{
$Workflow = new Workflow();
$this->workflow = $Workflow->processProjet($this);
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $num_prod;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $num_administratif;
/**
* @ORM\ManyToOne(targetEntity=Societe::class, inversedBy="projets")
* @ORM\JoinColumn(nullable=false)
*/
private $societe;
/**
* @ORM\ManyToOne(targetEntity=Tiers::class, inversedBy="projet_producteur")
* @ORM\JoinColumn(nullable=false)
*/
private $producteur;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lib_projet;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type_projet;
/**
* @ORM\Column(type="date")
*/
private $date_deb;
/**
* @ORM\Column(type="date")
*/
private $date_fin;
/**
* @ORM\Column(type="datetime")
*/
private $date_crea;
/**
* @ORM\Column(type="integer")
*/
private $user_crea;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date_modif;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $user_modif;
/**
* @ORM\Column(type="boolean")
*/
private $is_active;
/**
* @ORM\ManyToOne(targetEntity=Tiers::class, inversedBy="projet_tiers")
*/
private $tiers;
/**
* @ORM\ManyToOne(targetEntity=LdvStatutProjet::class)
* @ORM\JoinColumn(nullable=false)
*/
private $statut;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="projet")
*/
private $documents;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $commentaire;
/**
* @ORM\ManyToMany(targetEntity=Tiers::class, inversedBy="projet_salarie")
* @ORM\JoinTable(name="projet_salarie")
*/
private $salaries;
/**
* @ORM\ManyToMany(targetEntity=Tiers::class, inversedBy="projet_presta")
* @ORM\JoinTable(name="projet_presta")
*/
private $prestataires;
/**
* @ORM\Column(type="boolean")
*/
private $is_appel_offre;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->salaries = new ArrayCollection();
$this->prestataire = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNumProd(): ?string
{
return $this->num_prod;
}
public function setNumProd(?string $num_prod): self
{
$this->num_prod = $num_prod;
return $this;
}
public function getNumAdministratif(): ?string
{
return $this->num_administratif;
}
public function setNumAdministratif(?string $num_administratif): self
{
$this->num_administratif = $num_administratif;
return $this;
}
public function getSociete(): ?Societe
{
return $this->societe;
}
public function setSociete(?Societe $societe): self
{
$this->societe = $societe;
return $this;
}
public function getProducteur(): ?Tiers
{
return $this->producteur;
}
public function setProducteur(?Tiers $producteur): self
{
$this->producteur = $producteur;
return $this;
}
public function getLibProjet(): ?string
{
return $this->lib_projet;
}
public function setLibProjet(?string $lib_projet): self
{
$this->lib_projet = $lib_projet;
return $this;
}
public function getTypeProjet(): ?string
{
return $this->type_projet;
}
public function setTypeProjet(?string $type_projet): self
{
$this->type_projet = $type_projet;
return $this;
}
public function getDateDeb(): ?\DateTimeInterface
{
return $this->date_deb;
}
public function setDateDeb(\DateTimeInterface $date_deb): self
{
$this->date_deb = $date_deb;
return $this;
}
public function getDateFin(): ?\DateTimeInterface
{
return $this->date_fin;
}
public function setDateFin(\DateTimeInterface $date_fin): self
{
$this->date_fin = $date_fin;
return $this;
}
public function getDateCrea(): ?\DateTimeInterface
{
return $this->date_crea;
}
public function setDateCrea(\DateTimeInterface $date_crea): self
{
$this->date_crea = $date_crea;
return $this;
}
public function getUserCrea(): ?int
{
return $this->user_crea;
}
public function setUserCrea(int $user_crea): self
{
$this->user_crea = $user_crea;
return $this;
}
public function getDateModif(): ?\DateTimeInterface
{
return $this->date_modif;
}
public function setDateModif(?\DateTimeInterface $date_modif): self
{
$this->date_modif = $date_modif;
return $this;
}
public function getUserModif(): ?int
{
return $this->user_modif;
}
public function setUserModif(?int $user_modif): self
{
$this->user_modif = $user_modif;
return $this;
}
public function getIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
public function getTiers(): ?Tiers
{
return $this->tiers;
}
public function setTiers(?Tiers $tiers): self
{
$this->tiers = $tiers;
return $this;
}
public function getStatut(): ?LdvStatutProjet
{
return $this->statut;
}
public function setStatut(?LdvStatutProjet $statut): self
{
$this->statut = $statut;
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setProjet($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getProjet() === $this) {
$document->setProjet(null);
}
}
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
/**
* @return float
*/
public function getBudget(): float
{
$docList = $this->getDocuments()->filter(function (Document $document){
return $document->getTypeDocument() === 'FACTURE PROFORMA';
})->toArray();
return array_reduce(
$docList,
function (float $sum, Document $document){
return $sum + $document->getMontantHt();
},
0.0
);
}
/**
* @return float
*/
public function getChiffreAffaire(): float
{
$docList = $this->getDocuments()->filter(function (Document $document){
return in_array($document->getTypeDocument(), ['FACTURE', 'AVOIR']);
})->toArray();
return array_reduce(
$docList,
function (float $sum, Document $document){
$montant = $document->getMontantHt();
if('AVOIR'===$document->getTypeDocument()) $montant = $montant * -1;
return $sum + $montant;
},
0.0
);
}
/**
* @return float
*/
public function getChargeNdf(): float
{
$docList = $this->getDocuments()->filter(function (Document $document){
return $document->getTypeDocument() === 'NDF';
})->toArray();
return array_reduce(
$docList,
function (float $sum, Document $document){
return $sum + $document->getMontantHt();
},
0.0
);
}
/**
* @return Collection<int, Tiers>
*/
public function getSalaries(): Collection
{
return $this->salaries;
}
public function addSalary(Tiers $salary): self
{
if (!$this->salaries->contains($salary)) {
$this->salaries[] = $salary;
}
return $this;
}
/**
* @return float
*/
public function getChargeSalariale(): float
{
$chargeProjet = 0;
$salarieList = $this->getSalaries();
foreach ($salarieList as $salarie){
$contratList = $salarie->getContratByIdProjet($this->getId());
foreach ($contratList as $contrat){
$salaire = $contrat->getNbJourPointage() * $contrat->getTarifJour();
$charge = $salaire * $contrat->getCharge() / 100;
$chargeProjet+= $salaire + $charge;
}
}
return $chargeProjet;
}
public function removeSalary(Tiers $salary): self
{
$this->salaries->removeElement($salary);
return $this;
}
/**
* @return Collection<int, Tiers>
*/
public function getPrestataires(): Collection
{
return $this->prestataires;
}
public function addPrestataire(Tiers $prestataire): self
{
if (!$this->prestataires->contains($prestataire)) {
$this->prestataires[] = $prestataire;
}
return $this;
}
public function removePrestataire(Tiers $prestataire): self
{
$this->prestataires->removeElement($prestataire);
return $this;
}
/**
* @return float
*/
public function getChargePrestataire(): float
{
$docList = $this->getDocuments()->filter(function (Document $document){
return $document->getTypeDocument() === 'COMMANDE PRESTATAIRE';
})->toArray();
return array_reduce(
$docList,
function (float $sum, Document $document){
return $sum + $document->getMontantHt();
},
0.0
);
}
public function getMarge(): float
{
$charges = 0;
$charges+= $this->getChargeSalariale();
$charges+= $this->getChargePrestataire();
$charges+= $this->getChargeNdf();
$marge = $this->getBudget() - $charges;
if(0>$marge) return 0;
return $marge;
}
public function getPourcentageMarge(): float
{
$budget = $this->getBudget();
if(0.0===$budget) return 0;
$rounded = round($this->getMarge() / $budget * 10000);
return $rounded / 100;
}
public function getPourcentageFacture(): float
{
$budget = $this->getBudget();
if(0.0===$budget) return 0;
$rounded = round($this->getChiffreAffaire() / $budget * 10000);
return $rounded / 100;
}
public function getPourcentageSalaire(): float
{
$budget = $this->getBudget();
if(0.0===$budget) return 0;
$rounded = round($this->getChargeSalariale() / $budget * 10000);
return $rounded / 100;
}
public function getPourcentagePrestataire(): float
{
$budget = $this->getBudget();
if(0.0===$budget) return 0;
$rounded = round($this->getChargePrestataire() / $budget * 10000);
return $rounded / 100;
}
public function getPourcentageNdf(): float
{
$budget = $this->getBudget();
if(0.0===$budget) return 0;
$rounded = round($this->getChargeNdf() / $budget * 10000);
return $rounded / 100;
}
public function getIsAppelOffre(): ?bool
{
return $this->is_appel_offre;
}
public function setIsAppelOffre(bool $is_appel_offre): self
{
$this->is_appel_offre = $is_appel_offre;
return $this;
}
public function getNbJourProd()
{
$interval = $this->getDateDeb()->diff( $this->getDateFin(), true );
return $interval->days;
}
public function getPrestataireCount(): int
{
$commandeList = $this->getDocuments()->filter(function (Document $document){
return $document->getTypeDocument() === 'COMMANDE PRESTATAIRE';
});
$presta = array();
foreach ($commandeList as $commande){
$presta[] = $commande->getTiers()->getMainTiers()->getId();
}
if(empty($presta)) return 0;
return count(array_unique($presta));
}
}