<?php
namespace App\Entity;
use App\Repository\PaieRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PaieRepository::class)]
class Paie
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'paies')]
#[ORM\JoinColumn(nullable: false)]
private ?Employe $employe = null;
#[ORM\Column(type: Types::INTEGER)]
private ?int $mois = null;
#[ORM\Column(type: Types::INTEGER)]
private ?int $annee = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $salaireBase = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $primes = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $heuresSupplementaires = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $avantages = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $salaireBrut = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $cotisationsSociales = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $impots = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $autresDeductions = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $totalDeductions = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $salaireNet = null;
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2, nullable: true)]
private ?string $joursPresence = null;
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2, nullable: true)]
private ?string $joursAbsence = null;
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2, nullable: true)]
private ?string $joursConges = null;
#[ORM\Column(length: 50)]
private ?string $statut = 'brouillon'; // brouillon, validé, payé
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $datePaiement = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $modePaiement = null; // virement, especes, cheque
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $createdBy = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $validatedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $validatedBy = null;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmploye(): ?Employe
{
return $this->employe;
}
public function setEmploye(?Employe $employe): static
{
$this->employe = $employe;
return $this;
}
public function getMois(): ?int
{
return $this->mois;
}
public function setMois(int $mois): static
{
$this->mois = $mois;
return $this;
}
public function getAnnee(): ?int
{
return $this->annee;
}
public function setAnnee(int $annee): static
{
$this->annee = $annee;
return $this;
}
public function getSalaireBase(): ?string
{
return $this->salaireBase;
}
public function setSalaireBase(string $salaireBase): static
{
$this->salaireBase = $salaireBase;
return $this;
}
public function getPrimes(): ?string
{
return $this->primes;
}
public function setPrimes(?string $primes): static
{
$this->primes = $primes;
return $this;
}
public function getHeuresSupplementaires(): ?string
{
return $this->heuresSupplementaires;
}
public function setHeuresSupplementaires(?string $heuresSupplementaires): static
{
$this->heuresSupplementaires = $heuresSupplementaires;
return $this;
}
public function getAvantages(): ?string
{
return $this->avantages;
}
public function setAvantages(?string $avantages): static
{
$this->avantages = $avantages;
return $this;
}
public function getSalaireBrut(): ?string
{
return $this->salaireBrut;
}
public function setSalaireBrut(string $salaireBrut): static
{
$this->salaireBrut = $salaireBrut;
return $this;
}
public function getCotisationsSociales(): ?string
{
return $this->cotisationsSociales;
}
public function setCotisationsSociales(?string $cotisationsSociales): static
{
$this->cotisationsSociales = $cotisationsSociales;
return $this;
}
public function getImpots(): ?string
{
return $this->impots;
}
public function setImpots(?string $impots): static
{
$this->impots = $impots;
return $this;
}
public function getAutresDeductions(): ?string
{
return $this->autresDeductions;
}
public function setAutresDeductions(?string $autresDeductions): static
{
$this->autresDeductions = $autresDeductions;
return $this;
}
public function getTotalDeductions(): ?string
{
return $this->totalDeductions;
}
public function setTotalDeductions(string $totalDeductions): static
{
$this->totalDeductions = $totalDeductions;
return $this;
}
public function getSalaireNet(): ?string
{
return $this->salaireNet;
}
public function setSalaireNet(string $salaireNet): static
{
$this->salaireNet = $salaireNet;
return $this;
}
public function getJoursPresence(): ?string
{
return $this->joursPresence;
}
public function setJoursPresence(?string $joursPresence): static
{
$this->joursPresence = $joursPresence;
return $this;
}
public function getJoursAbsence(): ?string
{
return $this->joursAbsence;
}
public function setJoursAbsence(?string $joursAbsence): static
{
$this->joursAbsence = $joursAbsence;
return $this;
}
public function getJoursConges(): ?string
{
return $this->joursConges;
}
public function setJoursConges(?string $joursConges): static
{
$this->joursConges = $joursConges;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
public function getDatePaiement(): ?\DateTimeInterface
{
return $this->datePaiement;
}
public function setDatePaiement(?\DateTimeInterface $datePaiement): static
{
$this->datePaiement = $datePaiement;
return $this;
}
public function getModePaiement(): ?string
{
return $this->modePaiement;
}
public function setModePaiement(?string $modePaiement): static
{
$this->modePaiement = $modePaiement;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
public function getValidatedAt(): ?\DateTimeImmutable
{
return $this->validatedAt;
}
public function setValidatedAt(?\DateTimeImmutable $validatedAt): static
{
$this->validatedAt = $validatedAt;
return $this;
}
public function getValidatedBy(): ?User
{
return $this->validatedBy;
}
public function setValidatedBy(?User $validatedBy): static
{
$this->validatedBy = $validatedBy;
return $this;
}
public function calculerSalaireBrut(): void
{
$base = floatval($this->salaireBase ?? 0);
$primes = floatval($this->primes ?? 0);
$heuresSup = floatval($this->heuresSupplementaires ?? 0);
$avantages = floatval($this->avantages ?? 0);
$this->salaireBrut = number_format($base + $primes + $heuresSup + $avantages, 2, '.', '');
}
public function calculerTotalDeductions(): void
{
$cotisations = floatval($this->cotisationsSociales ?? 0);
$impots = floatval($this->impots ?? 0);
$autres = floatval($this->autresDeductions ?? 0);
$this->totalDeductions = number_format($cotisations + $impots + $autres, 2, '.', '');
}
public function calculerSalaireNet(): void
{
$this->calculerSalaireBrut();
$this->calculerTotalDeductions();
$brut = floatval($this->salaireBrut ?? 0);
$deductions = floatval($this->totalDeductions ?? 0);
$this->salaireNet = number_format($brut - $deductions, 2, '.', '');
}
public function getPeriode(): string
{
if ($this->mois && $this->annee) {
$moisNom = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin',
'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
return $moisNom[$this->mois] . ' ' . $this->annee;
}
return '';
}
public function __toString(): string
{
return $this->getPeriode() . ' - ' . ($this->employe ? $this->employe->getNomComplet() : '');
}
}