<?php
namespace App\Entity\Training;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Training\Fee;
use App\Repository\Training\TraineeRepository;
use App\Traits\Actions;
use App\Entity\Schoolyear;
use App\Entity\User;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
#[ORM\Entity(repositoryClass: TraineeRepository::class)]
#[ORM\Table(name: 'hs_tc_training_trainee')]
#[ApiResource]
class Trainee implements \Stringable
{
use Actions;
final public const SERVER_PATH_TO_IMAGE_FOLDER = 'uploads/images/trainee';
#[ORM\OneToOne(inversedBy: "trainee", targetEntity: User::class, cascade: ["persist"])]
#[ORM\JoinColumn(nullable: true)]
private ?User $user = null;
#[ORM\ManyToOne(targetEntity: "Groupe", inversedBy: "trainees")]
#[ORM\JoinColumn(nullable: true)]
private ?Groupe $groupe = null;
#[ORM\Column(name: "first_name", type: "string", length: 255)]
private $firstName;
#[ORM\Column(name: "last_name", type: "string", length: 255)]
private $lastName;
#[ORM\Column(name: "first_name_ar", type: "string", length: 255, nullable: true)]
private ?string $firstNameAr = null;
#[ORM\Column(name: "last_name_ar", type: "string", length: 255, nullable: true)]
private ?string $lastNameAr = null;
#[ORM\Column(name: "cin", type: "string", length: 255, nullable: true)]
private $cin;
#[ORM\Column(name: "gender", type: "string", length: 255, nullable: true)]
private $gender;
#[ORM\Column(name: "birth_in", type: "string", length: 255, nullable: true)]
private $birthIn;
#[ORM\Column(name: "birth_in_ar", type: "string", length: 255, nullable: true)]
private ?string $birthInAr = null;
#[ORM\Column(name: "birth_at", type: "datetime", nullable: true)]
private $birthAt;
#[ORM\Column(name: "nationality", type: "string", length: 255, nullable: true)]
private string $nationality = "Marocaine";
#[ORM\Column(name: "phone", type: "string", length: 255, nullable: true)]
private $phone;
#[ORM\Column(name: "phone2", type: "string", length: 255, nullable: true)]
private $phone2;
#[ORM\Column(name: 'wp', type: 'string', length: 255, nullable: true)]
private ?string $wp = null;
#[ORM\Column(name: "email", type: "string", length: 255, nullable: true)]
private $email;
#[ORM\Column(name: "address", type: "string", length: 255, nullable: true)]
private $address;
#[ORM\Column(name: "address_ar", type: "string", length: 255, nullable: true)]
private ?string $addressAr = null;
#[ORM\Column(name: "city", type: "string", length: 255, nullable: true)]
private $city;
#[ORM\Column(name: "school_level", type: "string", length: 255, nullable: true)]
private $schoolLevel;
#[ORM\Column(name: "school_last", type: "string", length: 255, nullable: true)]
private $schoolLast;
#[ORM\Column(name: "registration_number", type: "string", length: 255, nullable: true)]
private $regNumber;
#[ORM\Column(name: "serie_number", type: "string", length: 255, nullable: true)]
private ?string $serieNumber = null;
#[ORM\Column(name: "id_massar", type: "string", length: 255, nullable: true)]
private ?string $idMassar = null;
#[ORM\Column(name: "diplome_number", type: "string", length: 255, nullable: true)]
private ?string $diplomeNumber = null;
#[ORM\Column(name:"registration_at", type:"datetime", nullable:true)]
private \DateTime $registrationAt;
#[ORM\Column(name: "status", type: "string", length: 255, nullable: true)]
private $status;
#[ORM\Column(name: "status_at", type: "datetime", nullable: true)]
private ?\DateTime $statusAt = null;
#[ORM\Column(name: "image_name", type: "string", length: 255, nullable: true)]
protected $imageName = 'photo.jpg';
protected $imageFile;
#[ORM\Column(name: "cin_image", type: "string", length: 255, nullable: true)]
protected $cinImage = 'cin.png';
protected $cinImageFile;
#[ORM\Column(name: "school_level_image", type: "string", length: 255, nullable: true)]
protected $schoolLevelImage = 'attestation.png';
protected $schoolLevelImageFile;
#[ORM\Column(name: "monthly_payment", type: "float", nullable: true)]
private ?float $monthlyPayment = null;
#[ORM\Column(name: "register_fees", type: "float", nullable: true)]
private ?float $registerFees = null;
#[ORM\Column(name: "exam_fees", type: "float", nullable: true)]
private ?float $examFees = null;
#[ORM\Column(name: "diploma_fees", type: "float", nullable: true)]
private ?float $diplomaFees = null;
#[ORM\Column(name: "discount", type: "boolean")]
private $discount;
#[ORM\OneToMany(mappedBy: "trainee", targetEntity: Fpayment::class)]
#[ORM\OrderBy(["createAt" => "ASC"])]
private ?Collection $payments = null;
#[ORM\OneToMany(mappedBy: "trainee", targetEntity: Note::class, cascade: ["persist"], orphanRemoval: true)]
private ?Collection $notes = null;
#[ORM\OneToMany(mappedBy: "trainee", targetEntity: "Nsti", cascade: ["persist"], orphanRemoval: true)]
private ?Collection $nstis;
#[ORM\OneToMany(mappedBy: "trainee", targetEntity: "Fee", cascade: ["persist"], orphanRemoval: true)]
#[ORM\OrderBy(["datePaie" => "ASC"])]
private ?Collection $fees = null;
#[ORM\OneToMany(mappedBy: "trainee", targetEntity: Absence::class, cascade: ["persist"], orphanRemoval: true)]
private ?Collection $absences = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $plainPassword = null;
public function __construct()
{
// date_default_timezone_set('Africa/Casablanca');
$this->createAt=new \DateTime('now');
$this->registrationAt=new \DateTime('now');
$this->published=true;
$this->nstis=new ArrayCollection();
$this->payments=new ArrayCollection();
$this->notes=new ArrayCollection();
$this->fees=new ArrayCollection();
$this->wp="212";
$this->status="En cours";
$this->discount=true;
}
/**
* Set user
*
*
* @return Trainee
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* Set groupe
*
*
* @return Trainee
*/
public function setGroupe(Groupe $groupe)
{
$this->groupe = $groupe;
return $this;
}
/**
* Get groupe
*
* @return Groupe
*/
public function getGroupe()
{
return $this->groupe;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
* @return Trainee
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
* @return Trainee
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* @return \DateTime
*/
public function getBirthAt()
{
return $this->birthAt;
}
/**
* @param \DateTime $birthAt
* @return Trainee
*/
public function setBirthAt($birthAt)
{
$this->birthAt = $birthAt;
return $this;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param string $phone
* @return Trainee
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
public function getWp(): ?string
{
return $this->wp;
}
public function setWp(?string $wp): void
{
$this->wp = $wp;
}
/**
* @return string
*/
public function getPhone2()
{
return $this->phone2;
}
/**
* @param string $phone2
* @return Trainee
*/
public function setPhone2($phone2)
{
$this->phone2 = $phone2;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
* @return Trainee
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @param string $address
* @return Trainee
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
* @return Trainee
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* @return string
*/
public function getSchoolLevel()
{
return $this->schoolLevel;
}
/**
* @param string $schoolLevel
* @return Trainee
*/
public function setSchoolLevel($schoolLevel)
{
$this->schoolLevel = $schoolLevel;
return $this;
}
/**
* @return string
*/
public function getCin()
{
return $this->cin;
}
/**
* @param string $cin
* @return Trainee
*/
public function setCin($cin)
{
$this->cin = $cin;
return $this;
}
/**
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* @param string $gender
* @return Trainee
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* @return string
*/
public function getBirthIn()
{
return $this->birthIn;
}
/**
* @param string $birthIn
* @return Trainee
*/
public function setBirthIn($birthIn)
{
$this->birthIn = $birthIn;
return $this;
}
/**
* @return string
*/
public function getNationality()
{
return $this->nationality;
}
/**
* @param string $nationality
* @return Trainee
*/
public function setNationality($nationality)
{
$this->nationality = $nationality;
return $this;
}
/**
* @return string
*/
public function getSchoolLast()
{
return $this->schoolLast;
}
/**
* @param string $schoolLast
* @return Trainee
*/
public function setSchoolLast($schoolLast)
{
$this->schoolLast = $schoolLast;
return $this;
}
/**
* @return string
*/
public function getRegNumber()
{
return $this->regNumber;
}
/**
* @param string $regNumber
* @return Trainee
*/
public function setRegNumber($regNumber)
{
$this->regNumber = $regNumber;
return $this;
}
/**
* @return string
*/
public function getSerieNumber(): ?string
{
return $this->serieNumber;
}
/**
* @param string $serieNumber
*/
public function setSerieNumber(?string $serieNumber): Trainee
{
$this->serieNumber = $serieNumber;
return $this;
}
/**
* @return string
*/
public function getDiplomeNumber(): ?string
{
return $this->diplomeNumber;
}
/**
* @param string $diplomeNumber
*/
public function setDiplomeNumber(?string $diplomeNumber): Trainee
{
$this->diplomeNumber = $diplomeNumber;
return $this;
}
/**
* @return string
*/
public function getIdMassar(): ?string
{
return $this->idMassar;
}
/**
* @param string $idMassar
*/
public function setIdMassar(?string $idMassar): Trainee
{
$this->idMassar = $idMassar;
return $this;
}
/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* @param string $status
* @return Trainee
*/
public function setStatus($status)
{
$this->status = $status;
// date_default_timezone_set('Africa/Casablanca');
$this->statusAt=new \DateTime('now');
return $this;
}
/**
* @return \DateTime
*/
public function getStatusAt()
{
return $this->statusAt;
}
/**
* @param \DateTime $statusAt
* @return Trainee
*/
public function setStatusAt($statusAt)
{
$this->statusAt = $statusAt;
return $this;
}
/**
* @return string
*/
public function getCinImage()
{
return $this->cinImage;
}
/**
* @param string $cinImage
* @return Trainee
*/
public function setCinImage($cinImage)
{
$this->cinImage = $cinImage;
return $this;
}
/**
* @return mixed
*/
public function getCinImageFile()
{
return $this->cinImageFile;
}
/**
* @return Trainee
*/
public function setCinImageFile(mixed $cinImageFile)
{
$this->cinImageFile = $cinImageFile;
return $this;
}
/**
* @return string
*/
public function getSchoolLevelImage()
{
return $this->schoolLevelImage;
}
/**
* @param string $schoolLevelImage
* @return Trainee
*/
public function setSchoolLevelImage($schoolLevelImage)
{
$this->schoolLevelImage = $schoolLevelImage;
return $this;
}
/**
* @return mixed
*/
public function getSchoolLevelImageFile()
{
return $this->schoolLevelImageFile;
}
/**
* @return Trainee
*/
public function setSchoolLevelImageFile(mixed $schoolLevelImageFile)
{
$this->schoolLevelImageFile = $schoolLevelImageFile;
return $this;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* @param string $imageName
* @return Trainee
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
return $this;
}
/**
* @return mixed
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param mixed $imageFile
* @return Trainee
*/
public function setImageFile(UploadedFile $imageFile=null)
{
$this->imageFile = $imageFile;
return $this;
}
public function getPhoto(){
return "<img src='../../../../".self::SERVER_PATH_TO_IMAGE_FOLDER.'/'.$this->imageName."' style='width: 100px;'>";
}
public function getCompletName(){
return $this->gender.' '.$this->lastName.' '.$this->firstName;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(?string $plainPassword): Trainee
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* @return float
*/
public function getMonthlyPayment(): ?float
{
return $this->monthlyPayment;
}
/**
* @param float $monthlyPayment
*/
public function setMonthlyPayment(?float $monthlyPayment): Trainee
{
$this->monthlyPayment = $monthlyPayment;
return $this;
}
/**
* @return float
*/
public function getRegisterFees(): ?float
{
return $this->registerFees;
}
/**
* @param float $registerFees
*/
public function setRegisterFees(?float $registerFees): Trainee
{
$this->registerFees = $registerFees;
return $this;
}
/**
* @return float
*/
public function getExamFees(): ?float
{
return $this->examFees;
}
/**
* @param float $examFees
*/
public function setExamFees(?float $examFees): Trainee
{
$this->examFees = $examFees;
return $this;
}
/**
* @return float
*/
public function getDiplomaFees(): ?float
{
return $this->diplomaFees;
}
/**
* @param float $diplomaFees
*/
public function setDiplomaFees(?float $diplomaFees): Trainee
{
$this->diplomaFees = $diplomaFees;
return $this;
}
/**
* @return string
*/
public function getFirstNameAr(): ?string
{
return $this->firstNameAr;
}
/**
* @param string $firstNameAr
*/
public function setFirstNameAr(?string $firstNameAr): Trainee
{
$this->firstNameAr = $firstNameAr;
return $this;
}
/**
* @return string
*/
public function getLastNameAr(): ?string
{
return $this->lastNameAr;
}
/**
* @param string $lastNameAr
*/
public function setLastNameAr(?string $lastNameAr): Trainee
{
$this->lastNameAr = $lastNameAr;
return $this;
}
/**
* @return string
*/
public function getBirthInAr(): ?string
{
return $this->birthInAr;
}
/**
* @param string $birthInAr
*/
public function setBirthInAr(?string $birthInAr): Trainee
{
$this->birthInAr = $birthInAr;
return $this;
}
/**
* @return string
*/
public function getAddressAr(): ?string
{
return $this->addressAr;
}
/**
* @param string $addressAr
*/
public function setAddressAr(?string $addressAr): Trainee
{
$this->addressAr = $addressAr;
return $this;
}
/**
* @return bool
*/
public function isDiscount()
{
return $this->discount;
}
/**
* @param bool $discount
* @return Trainee
*/
public function setDiscount($discount)
{
$this->discount = $discount;
return $this;
}
/**
* Add payment
*
*
* @return Trainee
*/
public function addPayment(Fpayment $payment)
{
$payment->setTrainee($this);
$this->payments[] = $payment;
return $this;
}
/**
* Remove payment
*/
public function removePayment(Fpayment $payment)
{
$this->payments->removeElement($payment);
}
/**
* Get payments
*
* @return Collection
*/
public function getPayments()
{
return $this->payments;
}
/**
* Add note
*
*
* @return Trainee
*/
public function addNote(Note $note)
{
$note->setTrainee($this);
$this->notes[] = $note;
return $this;
}
/**
* Remove note
*/
public function removeNote(Note $note)
{
$this->notes->removeElement($note);
}
/**
* Get notes
*
* @return Collection
*/
public function getNotes()
{
return $this->notes;
}
/**
* Add nsti
*
*
* @return Trainee
*/
public function addNsti(Nsti $nsti)
{
$nsti->setTrainee($this);
$this->nstis[] = $nsti;
return $this;
}
/**
* Remove nsti
*/
public function removeNsti(Nsti $nsti)
{
$this->nstis->removeElement($nsti);
}
/**
* Get nstis
*
* @return Collection
*/
public function getNstis()
{
return $this->nstis;
}
public function getNsti(Creval $creval, $jury){
/** @var Nsti $nsti */
foreach ($this->nstis as $nsti){
if($nsti->getCreval()===$creval && $nsti->getJury()===$jury) return $nsti;
}
return null;
}
public function getNstiByJury($jury){
$m=0;
$c=0;
/** @var Nsti $nsti */
foreach ($this->nstis as $nsti){
if($jury==$nsti->getJury()){
$m+=$nsti->getVal()*$nsti->getCreval()->getCoefficient();
$c+=$nsti->getCreval()->getCoefficient();
}
}
return ($c!=0?$m/$c:0)*4;
}
public function getMNsti(){
$m=0;
$c=0;
/** @var Nsti $nsti */
foreach ($this->nstis as $nsti){
$m+=$nsti->getVal()*$nsti->getCreval()->getCoefficient();
$c+=$nsti->getCreval()->getCoefficient();
}
return ($c!=0?$m/$c:0)*4;
}
/**
* Add fee
*
*
* @return Trainee
*/
public function addFee(Fee $fee)
{
$fee->setTrainee($this);
$this->fees[] = $fee;
return $this;
}
/**
* Remove fee
*/
public function removeFee(Fee $fee)
{
$this->fees->removeElement($fee);
}
/**
* Get fees
*
* @return Collection
*/
public function getFees()
{
return $this->fees;
}
/**
* Add absence
*
*
* @return Trainee
*/
public function addAbsence(Absence $absence)
{
$absence->setTrainee($this);
$this->absences[] = $absence;
return $this;
}
/**
* Remove absence
*/
public function removeAbsence(Absence $absence)
{
$this->absences->removeElement($absence);
}
/**
* Get absences
*
* @return Collection
*/
public function getAbsences()
{
return $this->absences;
}
public function getAbsencesByScheduleItemAndPeriod(Scheduleitem $scheduleitem, $start, $end){
$startDate =DateTime::createFromFormat('d-m-Y H:i', $start.' 00:00');
$endDate =DateTime::createFromFormat('d-m-Y H:i', $end.' 23:59');
/** @var Absence $absence */
foreach ($this->absences as $absence){
if($absence->getSeance()->getScheduleitem()===$scheduleitem && $absence->getSeance()->getTakesplaceOn() >= $startDate && $absence->getSeance()->getTakesplaceOn() <= $endDate) return $absence;
}
return null;
}
public function getAbsencesByPeriod($start, $end)
{
$startDate =DateTime::createFromFormat('d-m-Y H:i', $start.' 00:00');
$endDate =DateTime::createFromFormat('d-m-Y H:i', $end.' 23:59');
$absences=[];
/** @var Absence $absence */
foreach ($this->absences as $absence){
if($absence->getSeance()->getTakesplaceOn() >= $startDate && $absence->getSeance()->getTakesplaceOn() <= $endDate && $absence->isPublished()) {
$absences[]=$absence;
}
}
// usort($absences, function (Absence $a, Absence $b) {
// return $a->getSeance()->getTakesplaceOn() <=> $b->getSeance()->getTakesplaceOn();
// });
return $absences;
}
public function getLastAbsentSeance(): ?Seance
{
$lastAbsence = null;
/** @var Absence $absence */
foreach ($this->getAbsences() as $absence) {
if (($lastAbsence === null || $absence->getSeance()->getTakesplaceOn() > $lastAbsence->getSeance()->getTakesplaceOn()) && $absence->isPublished()) {
$lastAbsence = $absence;
}
}
return $lastAbsence ? $lastAbsence->getSeance() : null;
}
/**
* Add schedule
*
*
* @return Trainee
*/
public function getFeeByTypeNameSy($type, $name, $sy){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getName()==$name && $fee->getTrainingYear()==$sy && $fee->getType()==$type) return $fee;
}
return null;
}
public function getFeesTraining(){
return $this->monthlyPayment ?? $this->groupe->getTraining()->getMonthlyPayment();
}
public function getFeesRegister(){
return $this->registerFees ?? $this->groupe->getTraining()->getRegisterFees();
}
public function getFeesExam(){
return $this->examFees ?? $this->groupe->getTraining()->getExamFees();
}
public function getFeesDiploma(){
return $this->diplomaFees ?? $this->groupe->getTraining()->getDiplomaFees();
}
public function getTrainingYear(Schoolyear $schoolyear){
if($this->getGroupe()->getSchoolyear3()===$schoolyear) return '3eme Année';
elseif($this->getGroupe()->getSchoolyear2()===$schoolyear) return '2eme Année';
elseif($this->getGroupe()->getSchoolyear1()===$schoolyear) return '1ier Année';
else return '-';
}
public function monthStart($month){
// date_default_timezone_set('Africa/Casablanca');
$format = 'd/m/y H:i:s';
//$month=$this->groupe->getMonth($this->groupe->getIndexMonth($month), 'number');
$date= \DateTime::createFromFormat($format, '1/'.$month.' 00:00:00');
if($date && $date->format('m/y')==$month) return $date;
else return \DateTime::createFromFormat($format, '01/07/16 00:00:00');
}
public function monthEnd($month){
// date_default_timezone_set('Africa/Casablanca');
$format = 'd/m/y H:i:s';
return \DateTime::createFromFormat($format, $this->monthStart($month)->format('t/m/y').' 23:59:59');
}
public function isAbandoned(){
return $this->status=='Abandonné';
}
public function isAbandonedMonth($month){
if($this->status=='Abandonné' && $this->monthStart($month)>$this->statusAt) return true;
return false;
}
public function isAbandonedSY(Schoolyear $schoolyear){
if($this->status=='Abandonné' && $schoolyear->getStartAt()>$this->statusAt) return true;
return false;
}
public function isEncours(Schoolyear $schoolyear){
if($this->status==='En cours' && in_array($schoolyear, $this->getGroupe()->getTrainingYears()) ) return true;
return false;
}
public function getMonthsPassed($format='long'){
$items=[];
foreach ($this->groupe->getMonthsPassed($format) as $month){
if($this->isAbandonedMonth($month)) continue;
$items[]=$month;
}
return $items;
}
public function getNbrMonthsPassed(){
return is_countable($this->getMonthsPassed()) ? count($this->getMonthsPassed()) : 0;
}
public function getMonthsPassedByYear($year, $format='long'){
$items=[];
foreach ($this->groupe->getMonthsPassedByYear($year, 'number') as $month){
if($this->status=='Abandonné' && $this->monthStart($month)>$this->statusAt) continue;
$items[]=$this->groupe->getMonth($this->groupe->getIndexMonth($month), $format);
}
return $items;
}
public function getNbrMonthsPassedByYear($year){
return is_countable($this->getMonthsPassedByYear($year)) ? count($this->getMonthsPassedByYear($year)) : 0;
}
public function getTotalFees($type, $year=null)
{
$mFees=0;
if($type=='all' && $year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->isNotAbandoned()) $mFees+=$fee->getMontant();
}
}
elseif($year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
}
}
elseif($type=='all'){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getTrainingYear()==$year && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
}
}
else{
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isNotAbandoned()) $mFees+=$fee->getMontant();
}
}
return $mFees;
}
public function getToPay($type='all', $year=null){
$mFees=0;
if($type=='all' && $year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->isCounted()) $mFees+=$fee->getMontant();
}
}
elseif($year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->isCounted()) $mFees+=$fee->getMontant();
}
}
elseif($type=='all'){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getTrainingYear()==$year && $fee->isCounted()) $mFees+=$fee->getMontant();
}
}
else{
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isCounted()) $mFees+=$fee->getMontant();
}
}
return $mFees;
}
public function isExempt($type, $year=null)
{
$i=0;
$mFees=0;
if($type=='all' && $year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->isCounted()) {
$i++;
$mFees+=$fee->getMontant();
}
}
}
elseif($year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->isCounted()) {
$i++;
$mFees+=$fee->getMontant();
}
}
}
elseif($type=='all'){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getTrainingYear()==$year && $fee->isCounted()) {
$i++;
$mFees+=$fee->getMontant();
}
}
}
else{
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isCounted()) {
$i++;
$mFees+=$fee->getMontant();
}
}
}
return $i>0 && $mFees==0;
}
public function getOutDate($type, $year=null){
$mFees=0;
if($type=='all' && $year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->isExpired()) $mFees+=$fee->getMontant();
}
}
elseif($year==null){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->isExpired()) $mFees+=$fee->getMontant();
}
}
elseif($type=='all'){
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getTrainingYear()==$year && $fee->isExpired()) $mFees+=$fee->getMontant();
}
}
else{
/** @var Fee $fee */
foreach ($this->fees as $fee){
if($fee->getType()==$type && $fee->getTrainingYear()==$year && $fee->isExpired()) $mFees+=$fee->getMontant();
}
}
return $mFees;
}
public function getToPayByYear($fees, $year){
$mFees = match ($fees) {
'monthlyPayment' => $this->getFeesTraining()*(is_countable($this->groupe->getMonthsPassed('number')) ? count($this->groupe->getMonthsPassed('number')) : 0),
'registerFees' => $this->getFeesRegister(),
'examFees' => $this->getFeesExam(),
'all' => $this->getToPay('monthlyPayment')+$this->getToPay('registerFees')+$this->getToPay('examFees')+$this->getToPay('diplomaFees'),
default => 0,
};
return $mFees;
}
public function getTotalPay(string $fees, $year = null): float
{
$m = 0.0;
if ($fees === 'all' && $year === null) {
/** @var Fpayment $payment */
foreach ($this->payments as $payment) {
$m += (float)$payment->getAmount();
}
} elseif ($fees === 'all') {
/** @var Fpayment $payment */
foreach ($this->payments as $payment) {
/** @var Fpayline $item */
foreach ($payment->getItems() as $item) {
$fee = $item->getFee();
if ($fee && $fee->getTrainingYear() == $year) {
$m += (float)$item->getAmount();
}
}
}
} elseif ($year === null) {
/** @var Fpayment $payment */
foreach ($this->payments as $payment) {
/** @var Fpayline $item */
foreach ($payment->getItems() as $item) {
$fee = $item->getFee();
if ($fee && $fee->getType() == $fees) {
$m += (float)$item->getAmount();
}
}
}
} else {
/** @var Fpayment $payment */
foreach ($this->payments as $payment) {
/** @var Fpayline $item */
foreach ($payment->getItems() as $item) {
$fee = $item->getFee();
if ($fee && $fee->getType() == $fees && $fee->getTrainingYear() == $year) {
$m += (float)$item->getAmount();
}
}
}
}
return $m;
}
/**
* Calcule le reste à payer pour le stagiaire selon le type de frais et l'année.
* Amélioration : typage strict, robustesse.
*/
public function getRestPay(string $fees, $year = null): float
{
$toPay = (float)$this->getToPay($fees, $year);
$totalPay = (float)$this->getTotalPay($fees, $year);
$rest = $toPay - $totalPay;
return $rest > 0 ? $rest : 0.0;
}
/**
* Calcule l'avance de paiement pour le stagiaire selon le type de frais et l'année.
* Amélioration : typage strict, robustesse, float.
*/
public function getAdvance(string $fees, $year = null): float
{
$toPay = (float)$this->getToPay($fees, $year);
$totalPay = (float)$this->getTotalPay($fees, $year);
$advance = $totalPay - $toPay;
return $advance > 0 ? $advance : 0.0;
}
public function getLatePaid($fees, $year=null){
return ($this->getOutDate($fees, $year)-$this->getTotalPay($fees, $year)>0)?($this->getOutDate($fees, $year)-$this->getTotalPay($fees, $year)):0;
}
public function getLateAdvance($fees, $year=null){
return ($this->getOutDate($fees, $year)-$this->getTotalPay($fees, $year)<0)?-($this->getOutDate($fees, $year)-$this->getTotalPay($fees, $year)):0;
}
public function getPcPay($fees, $year=null){
if($this->getToPay($fees, $year)!=0)
return round($this->getTotalPay($fees, $year)/$this->getToPay($fees, $year)*100,0);
else
return -1;
}
public function getToPayFeesTraining(){
return $this->getFeesTraining()*(is_countable($this->groupe->getMonthsPassed('number')) ? count($this->groupe->getMonthsPassed('number')) : 0);
}
public function getBgClassFess(Fee $fee){
if($fee->isPaied()) return 'bg-green';
elseif ($fee->amountPaied()>0) return 'bg-light-blue';
else return $this->groupe->getBgClass($fee->getName());
}
public function getBgClass($m){
if(in_array($m,$this->getMonthsPaid('short'),true)){
return 'bg-green';
}
elseif($m==$this->getMonthPaidPartially('short'))
return 'bg-light-blue';
else return $this->groupe->getBgClass($m);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
* * * * * * * * * * * * *
* * * * * * * *
* * * * * * * * * * *
* * * * * * * *
* * * * * * * * *
* */
public function getNoteVal(Noteassign $noteassign){
/** @var Note $ligne */
foreach ($this->getNotes() as $ligne){
if($ligne->getNoteassign()===$noteassign) return $ligne;
}
return null;
}
public function getNoteValByName(Module $module, $note){
/** @var Note $n */
foreach ($this->getNotes() as $n){
if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()==$note) return $n->getVal();
}
return -1;
}
public function getNoteObsByName(Module $module, $note){
/** @var Note $n */
foreach ($this->getNotes() as $n){
if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()==$note) return $n->getRemarque();
}
return '';
}
public function getNoteByNoteModule(Notemodule $notemodule)
{
foreach ($this->getNotes() as $n){
if($n->getNoteassign()->getNotemodule()==$notemodule) return $n;
}
return null;
}
public function getMoyenCC(Module $module){
if($module->hasCC()){
$sum=0;
$nbr=1;
/** @var Note $n */
foreach ($this->getNotes() as $n){
if(
$n->getNoteassign()->getAssignation()->getModule()===$module &&
$n->getNoteassign()->getNotemodule()->getGenre()=='controle' &&
$n->getVal()!=null
) {
$sum+=$n->getVal();
$nbr=$n->getNoteassign()->getAssignation()->getNbrControle();
}
}
if($module->getNbrCC()!=0) return $sum/$nbr;
}
return '';
}
public function getNotePratique(Module $module){
/** @var Note $n */
foreach ($this->getNotes() as $n){
if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()=='ep') return $n->getVal();
}
return 0;
}
public function getNotetheorique(Module $module){
/** @var Note $n */
foreach ($this->getNotes() as $n){
if($n->getNoteassign()->getAssignation()->getModule()===$module && $n->getNoteassign()->getNotemodule()->getName()=='et') return $n->getVal();
}
return 0;
}
public function getMoyen(Module $module){
if($module->hasCC())
return ($this->getMoyenCC($module)*3+$this->getNotePratique($module)*3+$this->getNotetheorique($module)*2)/8;
else
return ($this->getNotePratique($module)*3+$this->getNotetheorique($module)*2)/5;
}
public function getMGCC($type){
$sumCof=0;
$sumNote=0;
switch ($type){
case 'semestre1':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'semestre2':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 2'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'semestre3':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'semestre4':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 4'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'semestre5':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'semestre6':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 6'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
break;
case 'first_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
if($module->hasCC()){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
}
break;
case 'second_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
if($module->hasCC()){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
}
break;
case 'third_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
if($module->hasCC()){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getMoyenCC($module)*$module->getCoefficient();
}
}
}
break;
default:
if($this->getGroupe()->getTraining()->getNbrYears()==3)
return (round($this->getMGCC('first_year'),2)+round($this->getMGCC('second_year'),2)+round($this->getMGCC('third_year'),2))/3;
elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
return (round($this->getMGCC('first_year'),2)+round($this->getMGCC('second_year'),2))/2;
else return $this->getMGCC('first_year');
}
if($sumCof!=0){
return $sumNote/$sumCof;
}
return 0;
}
public function getMGPratique($type){
$sumCof=0;
$sumNote=0;
switch ($type){
case 'semestre1':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'semestre2':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 2'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'semestre3':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'semestre4':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 4'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'semestre5':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'semestre6':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 6'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'first_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'second_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
case 'third_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotePratique($module)*$module->getCoefficient();
}
}
break;
default:
if($this->getGroupe()->getTraining()->getNbrYears()==3)
return (round($this->getMGPratique('first_year'),2)+round($this->getMGPratique('second_year'),2)+round($this->getMGPratique('third_year'),2))/3;
elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
return (round($this->getMGPratique('first_year'),2)+round($this->getMGPratique('second_year'),2))/2;
else return $this->getMGPratique('first_year');
}
if($sumCof!=0){
return $sumNote/$sumCof;
}
return 0;
}
public function getMGTheorique($type){
$sumCof=0;
$sumNote=0;
switch ($type){
case 'semestre1':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'semestre2':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 2'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'semestre3':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'semestre4':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 4'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'semestre5':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'semestre6':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 6'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'first_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 1' || $module->getSemester()=='Semestre 2'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'second_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 3' || $module->getSemester()=='Semestre 4'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
case 'third_year':
/** @var Module $module */
foreach ($this->getGroupe()->getTraining()->getModules() as $module){
if($module->getSemester()=='Semestre 5' || $module->getSemester()=='Semestre 6'){
$sumCof+=$module->getCoefficient();
$sumNote+=$this->getNotetheorique($module)*$module->getCoefficient();
}
}
break;
default:
if($this->getGroupe()->getTraining()->getNbrYears()==3)
return (round($this->getMGTheorique('first_year'),2)+round($this->getMGTheorique('second_year'),2)+round($this->getMGTheorique('third_year'),2))/3;
elseif($this->getGroupe()->getTraining()->getNbrYears()==2)
return (round($this->getMGTheorique('first_year'),2)+round($this->getMGTheorique('second_year'),2))/2;
else return $this->getMGTheorique('first_year');
}
if($sumCof!=0){
return $sumNote/$sumCof;
}
return 0;
}
public function getMG($type){
return ($this->getMGCC($type)*3+$this->getMGPratique($type)*3+$this->getMGTheorique($type)*2)/8;
}
public function getJuryDecisionPassage($type){
if($this->getMG($type)<8.5) return 'Redoublant';
elseif ($this->getMG($type)<10) return 'Admis par Rachtage';
else return 'Admis';
}
public function getClassement($note){
$i=1;
/** @var Trainee $trainee */
foreach ($this->getGroupe()->getTraineesSorted($note) as $trainee){
if($trainee===$this) return $i;
$i++;
}
}
public function getMoyenneGeneral(){
return (
$this->getMGCC('training')*3
+
$this->getMGPratique('training')*3
+
$this->getMGTheorique('training')*2
+
$this->getMNsti()*2
)/10;
}
public function __toString(): string
{
return $this->getLastName().' '.$this->getFirstName();
}
public function getRegistrationAt(): DateTime
{
return $this->registrationAt;
}
public function setRegistrationAt(DateTime $registrationAt): Trainee
{
$this->registrationAt = $registrationAt;
return $this;
}
public function createAvatar(ParameterBagInterface $parameterBag)
{
$thumbWidth = 70;
$sourceImagePath = $parameterBag->get('kernel.project_dir') . '/public/images/trainee/';
$sourceImage = imagecreatefromjpeg($sourceImagePath.$this->imageName);
$destImagePath = $sourceImagePath . 'thumbs/'.$this->imageName;
$orgWidth = imagesx($sourceImage);
$orgHeight = imagesy($sourceImage);
$thumbHeight = floor($orgHeight * ($thumbWidth / $orgWidth));
$destImage = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($destImage, $sourceImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $orgWidth, $orgHeight);
imagejpeg($destImage, $destImagePath);
imagedestroy($sourceImage);
imagedestroy($destImage);
}
}