src/Entity/Training/Groupe.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\User;
  5. use App\Repository\Training\GroupeRepository;
  6. use App\Traits\Actions;
  7. use App\Entity\Schoolyear;
  8. use DateInterval;
  9. use DatePeriod;
  10. use DateTime;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. #[ORM\Entity(repositoryClassGroupeRepository::class)]
  15. #[ORM\Table(name'hs_tc_training_groupe')]
  16. #[ApiResource]
  17. class Groupe implements \Stringable
  18. {
  19.     use Actions;
  20.     #[ORM\ManyToOne(inversedBy'groupes')]
  21.     private ?Training $training null;
  22.     #[ORM\ManyToOne(targetEntitySchoolyear::class)]
  23.     #[ORM\JoinColumn(nullabletrue)]
  24.     private ?Schoolyear $schoolyear1 null;
  25.     #[ORM\OneToMany(mappedBy"groupe"targetEntityTrainee::class)]
  26.     #[ORM\OrderBy(["regNumber" => "ASC"])]
  27.     private Collection $trainees;
  28.     #[ORM\OneToMany(mappedBy"groupe"targetEntityPlanning::class, cascade: ["all"], orphanRemovaltrue)]
  29.     private Collection $plannings;
  30.     #[ORM\OneToMany(mappedBy"groupe"targetEntityAssignation::class, cascade: ["all"], orphanRemovaltrue)]
  31.     private Collection $assignations;
  32.     #[ORM\OneToMany(mappedBy"groupe"targetEntitySchedule::class, cascade: ["all"], orphanRemovaltrue)]
  33.     private Collection $schedules;
  34.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy"groupes")]
  35.     #[ORM\JoinColumn(nullabletrue)]
  36.     private ?User $responsable;
  37.     public function __construct()
  38.     {
  39.         $this->trainees = new ArrayCollection();
  40.         $this->createAt=new \DateTime('now');
  41.         $this->published=true;
  42.     }
  43.     public function getStartAt($period='formation'): ?\DateTime{
  44.         if($this->getTraining()==null){
  45.             return null;
  46.         }
  47.         $startMonth=$this->getTraining()->getListMonths()[0];
  48.         if($period=='formation' or $period=='firstYear'){
  49.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$startMonth.'/' $this->getFirstYear()->getFirstYear(). ' 00:00');
  50.         }
  51.         elseif($period=='secondYear'){
  52.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$startMonth.'/' . ($this->getFirstYear()->getFirstYear()+1). ' 00:00');
  53.         }
  54.         else{
  55.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$startMonth.'/' . ($this->getFirstYear()->getFirstYear()+2). ' 00:00');
  56.         }
  57.     }
  58.     public function getEndAt($period='formation'): ?\DateTime{
  59.         if($this->getTraining()==null){
  60.             return null;
  61.         }
  62.         $endMonth=$this->getTraining()->getListMonths()[count($this->getTraining()->getListMonths())-1];
  63.         if($period=='thirdYear'){
  64.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$endMonth.'/' . ($this->getFirstYear()->getSecondYear()+2). ' 23:59');
  65.         }
  66.         elseif($period=='secondYear'){
  67.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$endMonth.'/' . ($this->getFirstYear()->getSecondYear()+1). ' 23:59');
  68.         }
  69.         elseif($period=='firstYear'){
  70.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$endMonth.'/' $this->getFirstYear()->getSecondYear(). ' 23:59');
  71.         }
  72.         else{
  73.             return \DateTime::createFromFormat('d/m/Y H:i''1/'.$endMonth.'/' . ($this->getFirstYear()->getSecondYear()+$this->getTraining()->getSchoolYearsNumber()-1). ' 23:59');
  74.         }
  75.     }
  76.     public function setTraining(Training $training)
  77.     {
  78.         $this->training $training;
  79.         return $this;
  80.     }
  81.     public function getTraining()
  82.     {
  83.         return $this->training;
  84.     }
  85.     public function getSchoolyear1()
  86.     {
  87.         return $this->schoolyear1;
  88.     }
  89.     public function setSchoolyear1(Schoolyear $schoolyear1=null)
  90.     {
  91.         $this->schoolyear1 $schoolyear1;
  92.         return $this;
  93.     }
  94.     public function getSchoolyear2()
  95.     {
  96.         if($this->training->getNbrYears()>=&& $this->getSchoolyear1() != null) return $this->getSchoolyear1()->getNext();
  97.         else return null;
  98.     }
  99.     public function getSchoolyear3()
  100.     {
  101.         if($this->training->getNbrYears()>=&& $this->getSchoolyear2() != null) return $this->getSchoolyear2()->getNext();
  102.         else return null;
  103.     }
  104.     public function addTrainee(Trainee $trainee)
  105.     {
  106.         $trainee->setGroupe($this);
  107.         $this->trainees[] = $trainee;
  108.         return $this;
  109.     }
  110.     public function removeTrainee(Trainee $trainee)
  111.     {
  112.         $this->trainees->removeElement($trainee);
  113.     }
  114.     public function getTrainees()
  115.     {
  116.         return $this->trainees;
  117.     }
  118.     public function getNbrTrainees(){
  119.         $n=0;
  120.         /** @var Trainee $trainee */
  121.         foreach ($this->trainees as $trainee){
  122.             if($trainee->getStatus()!="Abandonné"$n++;
  123.         }
  124.         return $n;
  125.     }
  126.     public function getNbrAbandonnes(){
  127.         $n=0;
  128.         /** @var Trainee $trainee */
  129.         foreach ($this->trainees as $trainee){
  130.             if($trainee->getStatus()=="Abandonné"$n++;
  131.         }
  132.         return $n;
  133.     }
  134.     public function addAssignation(Assignation $assignation)
  135.     {
  136.         $assignation->setGroupe($this);
  137.         $this->assignations[] = $assignation;
  138.         return $this;
  139.     }
  140.     public function removeAssignation(Assignation $assignation)
  141.     {
  142.         $this->assignations->removeElement($assignation);
  143.     }
  144.     public function getAssignations()
  145.     {
  146.         return $this->assignations;
  147.     }
  148.     public function getAssignationByModule(Module $module)
  149.     {
  150.         foreach ($this->assignations as $assignation){
  151.             if($assignation->getModule()==$module){
  152.                 return $assignation;
  153.             }
  154.         }
  155.         return null;
  156.     }
  157.     public function addSchedule(Schedule $schedule)
  158.     {
  159.         $schedule->setGroupe($this);
  160.         $this->schedules[] = $schedule;
  161.         return $this;
  162.     }
  163.     public function removeSchedule(Schedule $schedule)
  164.     {
  165.         $this->schedules->removeElement($schedule);
  166.     }
  167.     public function getSchedules()
  168.     {
  169.         return $this->schedules;
  170.     }
  171.     public function getResponsable(): ?User
  172.     {
  173.         return $this->responsable;
  174.     }
  175.     public function setResponsable(?User $responsable): void
  176.     {
  177.         $this->responsable $responsable;
  178.     }
  179.     public function getOthersGroupes(){
  180.         $groupes=[];
  181.         foreach ($this->getTraining()->getGroupesBySY($this->getSchoolyear1()) as $groupe){
  182.             if($groupe !== $this$groupes[] = $groupe;
  183.         }
  184.         return $groupes;
  185.     }
  186.     public function getNum()
  187.     {
  188.     }
  189.     public function getLabel(){
  190.         $i=1;
  191.         foreach ($this->getTraining()->getGroupesBySY($this->getSchoolyear1()) as $groupe){
  192.             if($groupe->getId()<$this->getId()) $i++;
  193.         }
  194.         $label=count($this->getTraining()->getGroupesBySY($this->getSchoolyear1()))>1?' G'.$i:'';
  195.         return $this->training->getAbbreviation().' '.$label;
  196.     }
  197.     public function getDiplome(){
  198.         return $this->getTraining()->getDiploma();
  199.     }
  200.     public function getActionsS($actionsItems=[])
  201.     {
  202.         $actions="<div class='btn-group'>" .
  203.             "<button type='button' class='btn btn-default btn-flat dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>" .
  204.             "<span class='fa fa-ellipsis-v'></span>" .
  205.             "<span class='sr-only'>Toggle Dropdown</span>" .
  206.             "</button>" .
  207.             "<ul class='dropdown-menu dropdown-menu-right' role='menu'>";
  208.         if(in_array('edit',$actionsItems))
  209.         $actions.="<li><a title='Modifier' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('edit')."'>"
  210.             ."<i class='fa text-warning fa-fw fa-edit'></i> Modifier</a></li>";
  211.         if(in_array('show',$actionsItems))
  212.             $actions.="<li><a title='Afficher' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('show')."'>"
  213.             ."<i class='fa text-info fa-fw fa-eye'></i> Afficher</a></li>";
  214.         if(in_array('remove',$actionsItems))
  215.             $actions.="<li><a title='Supprimer ?' 
  216.                 data-toggle='confirmation'
  217.                 data-btn-ok-label='Supprimer' 
  218.                 data-btn-ok-icon='glyphicon glyphicon-ok'
  219.                 data-btn-ok-class='btn-success'
  220.                 data-btn-cancel-label='Annuler' 
  221.                 data-btn-cancel-icon='glyphicon glyphicon-remove'
  222.                 data-btn-cancel-class='btn-danger'
  223.                 data-title='Supprimer ?'
  224.                 data-popout='true'
  225.                 data-content='Voulez-vous vraiment supprimer cet élément ?' 
  226.                 class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='".$this->getRoute('remove')."'>"
  227.             ."<i class='fa text-red fa-fw fa-trash-o'></i> Supprimer</a></li>";
  228.         if(in_array('add_trainee',$actionsItems))
  229.             $actions.="<li><a title='Ajouter un nouveau stagiaire' class='action' target='_self' href='javascript:void(0)' data-id='".$this->id."' data-route='hs_training_center_trainee_new'>"
  230.             ."<i class='fa text-success fa-fw fa-plus'></i> Stagiaire</a></li>";
  231.         $actions.="</ul></div>";
  232.         return $actions;
  233.     }
  234.     public function getYears(){
  235.         return $this->getSchoolyear1()->getFirstYear().'-'.($this->getSchoolyear1()->getFirstYear()+$this->getTraining()->getNbrYears());
  236.     }
  237.     public function getFirstYear(){
  238.         return $this->schoolyear1;
  239.     }
  240.     public function getLastYear(){
  241.         if($this->getTraining()->getNbrYears()==3) return $this->getSchoolyear3();
  242.         elseif($this->getTraining()->getNbrYears()==2) return $this->getSchoolyear2();
  243.         return $this->schoolyear1;
  244.     }
  245.     public function getSecondYear(){
  246.         $first=intval(substr($this->schoolyear1->getTitle(),0,4));
  247.         if($this->training->getNbrYears()<2) return '-------';
  248.         else return ($first+1).'/'.($first+2);
  249.     }
  250.     public function getThirdYear(){
  251.         $first=intval(substr($this->schoolyear1->getTitle(),0,4));
  252.         if($this->training->getNbrYears()<3) return '-------';
  253.         else return ($first+2).'/'.($first+3);
  254.     }
  255.     public function getTrainingYear(Schoolyear $schoolyear){
  256.         if ($schoolyear===$this->schoolyear1) return 'first_year';
  257.         elseif($schoolyear===$this->getSchoolyear2()) return 'second_year';
  258.         elseif($schoolyear===$this->getSchoolyear3()) return 'third_year';
  259.         return "none";
  260.     }
  261.     public function getTrainingYearFr(Schoolyear $schoolyear){
  262.         if ($schoolyear===$this->schoolyear1) return '1ère année';
  263.         elseif($schoolyear===$this->getSchoolyear2()) return '2ème année';
  264.         elseif($schoolyear===$this->getSchoolyear3()) return '3ème année';
  265.         return " ";
  266.     }
  267.     public function geSchoolYear($ty){
  268.         if ($ty=='first_year') return $this->schoolyear1;
  269.         elseif($ty=='second_year') return $this->getSchoolyear2();
  270.         elseif($ty=='third_year') return $this->getSchoolyear3();
  271.         return null;
  272.     }
  273.     public function getTrainingYears(){
  274.         $sys=[$this->schoolyear1];
  275.         if($this->training->getNbrYears()>=2$sys[]=$this->getSchoolyear2();
  276.         if($this->training->getNbrYears()>=3$sys[]=$this->getSchoolyear3();
  277.         return $sys;
  278.     }
  279.     public function getSchoolYearByMonth($month){
  280.         $sy=null;
  281.         foreach ($this->getTrainingYears() as $schoolyear){
  282.             $level=$this->getTrainingYear($schoolyear);
  283.             $months=$this->getMonthsByYear($level'number');
  284.             foreach ($months as $m) if($m==$month$sy=$schoolyear;
  285.         }
  286.         return $sy;
  287.     }
  288.     public function isEncours(Schoolyear $schoolyear){
  289.         if(in_array($schoolyear$this->getTrainingYears())) return true;
  290.         return false;
  291.     }
  292.     public function getMonths($format='long'): array
  293.     {
  294.         $mountsArray=[
  295.             '01'=>['number'=>'01','short'=>'Janv','long'=>'Janvier'],
  296.             '02'=>['number'=>'02','short'=>'Févr','long'=>'Février'],
  297.             '03'=>['number'=>'03''short'=>'Mars','long'=>'Mars'],
  298.             '04'=>['number'=>'04''short'=>'Avr','long'=>'Avril'],
  299.             '05'=>['number'=>'05','short'=>'Mai','long'=>'Mai'],
  300.             '06'=>['number'=>'06','short'=>'Juin','long'=>'Juin'],
  301.             '07'=>['number'=>'07''short'=>'Juil','long'=>'Juillet'],
  302.             '08'=>['number'=>'08''short'=>'Aout','long'=>'Août'],
  303.             '09'=>['number'=>'09''short'=>'Sept','long'=>'Septembre'],
  304.             '10'=>['number'=>'10','short'=>'Oct','long'=>'Octobre'],
  305.             '11'=>['number'=>'11','short'=>'Nov','long'=>'Novembre'],
  306.             '12'=> ['number'=>'12','short'=>'Déc','long'=>'Décembre'],
  307.         ];
  308.         if($format=='short') {
  309.             $sep=" ";
  310.             $yearformat='y';
  311.         }
  312.         elseif($format=='long') {
  313.             $sep=" ";
  314.             $yearformat='Y';
  315.         }
  316.         else {
  317.             $sep="/";
  318.             $yearformat='y';
  319.         }
  320.         $months = [];
  321.         $start $this->getStartAt();
  322.         $end $this->getEndAt();
  323.         $interval DateInterval::createFromDateString('1 month');
  324.         $period = new DatePeriod($start$interval$end);
  325.         foreach ($period as $date) {
  326.             $month $date->format('m');
  327.             if(in_array($month$this->getTraining()->getListMonths())){
  328.                 $monthName=$mountsArray[$month][$format];
  329.                 $year$date->format($yearformat);
  330.                 $months[] = $monthName.$sep.$year;
  331.             }
  332.         }
  333.         return $months;
  334.     }
  335.     public function getMonthsByYear(string $year$format='long'){
  336.         if($year=='third_year'$n=2;
  337.         elseif($year=='second_year'$n=1;
  338.         elseif ($year=='first_year'$n=0;
  339.         else return $this->getMonths($format);
  340.         return array_slice($this->getMonths($format), $n*count($this->getTraining()->getListMonths()), count($this->getTraining()->getListMonths()));
  341.     }
  342.     public function getMonth($index$format='long'){
  343.         $mounts=$this->getMonths($format);
  344.         return $index>=0?$mounts[$index]:null;
  345.     }
  346.     public function getIndexMonth($month){
  347.         if(array_search($month,$this->getMonths())) return array_search($month,$this->getMonths());
  348.         elseif(array_search($month,$this->getMonths('short'))) return array_search($month,$this->getMonths('short'));
  349.         else return array_search($month,$this->getMonths('number'));
  350.     }
  351.     public function getShortMonth($m){
  352.         return $this->getMonth($this->getIndexMonth($m),'short');
  353.     }
  354.     public function getCurrent($format='long'){
  355.         // date_default_timezone_set('Africa/Casablanca');
  356.         $now=new \DateTime('now');
  357.         $endAt= clone $this->schoolyear1->getEndAt();
  358.         $endAt->modify('+1 years');
  359.         if($now<$this->schoolyear1->getStartAt()) return 'before';
  360.         elseif($now>$endAt) return 'after';
  361.         elseif($now->format('m')=='08' || $now->format('m')=='09'$mc='07/'.$now->format('y');
  362.         else $mc=$now->format('m/y');
  363.         $index=array_search($mc$this->getMonths('number'));
  364.         return $this->getMonth($index$format);
  365.     }
  366.     public function getMonthsPassed($format='long'){
  367.         if ($this->getCurrent('number')=='before') return [];
  368.         elseif ($this->getCurrent('number')=='after') return $this->getMonths($format);
  369.         else{
  370.             $index=array_search($this->getCurrent('number'), $this->getMonths('number'));
  371.             $paased=[];
  372.             for($i=0$i<=$index$i++){
  373.                 $paased[]=$this->getMonths($format)[$i];
  374.             }
  375.             return $paased;
  376.         }
  377.     }
  378.     public function getMonthsPassedByYear($year$format='long'){
  379.         if ($this->getCurrent('number')=='before') return [];
  380.         elseif ($this->getCurrent('number')=='after') return $this->getMonthsByYear($year$format);
  381.         else{
  382.             $index=array_search($this->getCurrent('number'), $this->getMonthsByYear($year$format));
  383.             $paased=[];
  384.             for($i=0$i<=$index$i++){
  385.                 $paased[]=$this->getMonthsByYear($year$format)[$i];
  386.             }
  387.             return $paased;
  388.         }
  389.     }
  390.     public function getStatutMonth($index){
  391.         if($this->getCurrent('number')==$index){
  392.             return 'current';
  393.         }
  394.         elseif($this->getCurrent('number')>$index){
  395.             return 'passed';
  396.         }
  397.         else return 'coming';
  398.     }
  399.     public function getBgClass($m){
  400.         $m=$this->getMonth($this->getIndexMonth($m), 'short');
  401.         if($this->getCurrent('short')==$m){
  402.             return 'bg-yellow';
  403.         }
  404.         elseif(in_array($m,$this->getMonthsPassed('short'),true)){
  405.             return 'bg-red';
  406.         }
  407.         else return 'bg-gray';
  408.     }
  409.     public function __toString(): string
  410.     {
  411.         return $this->training->getAbbreviation().' '.$this->getYears();
  412.     }
  413.     public function getAbreviation(Schoolyear $schoolyear){
  414.         $i=1;
  415.         foreach ($this->getTraining()->getGroupesBySY($this->getSchoolyear1()) as $groupe){
  416.             if($groupe->getId()<$this->getId()) $i++;
  417.         }
  418.         $nbGroupe=count($this->getTraining()->getGroupesBySY($this->getSchoolyear1()))>1?' G'.$i:'';
  419.         if($this->getTraining()->getNbrYears()>1){
  420.             $level=match($this->getTrainingYear($schoolyear)){
  421.                 'first_year' => '1',
  422.                 'second_year' => '2',
  423.                 'third_year' => '3',
  424.             };
  425.         }
  426.         else $level='';
  427.         return $this->training->getAbbreviation().$level.$nbGroupe;
  428.     }
  429.     public function getTraineesSorted($note){
  430.         $items=$this->getTrainees()->toArray();
  431.         usort($items,[$this$note]);
  432.         return $items;
  433.     }
  434.     public function getTraineesSortedByAbsence($nombre$startAt$endAt){
  435.         // Récupérer tous les stagiaires
  436.         $trainees $this->getTrainees();
  437.         $traineeAbsences = [];
  438.         /** @var Trainee $trainee */
  439.         foreach ($trainees as $trainee) {
  440.             // Compter les absences pour chaque stagiaire
  441.             if($trainee->getStatus()!="Abandonné")
  442.             $traineeAbsences[] = [
  443.                 'trainee' => $trainee,
  444.                 'absenceCount' => count($trainee->getAbsencesByPeriod($startAt$endAt)),
  445.             ];
  446.         }
  447.         usort($traineeAbsences, function ($a$b) {
  448.             return $b['absenceCount'] <=> $a['absenceCount'];
  449.         });
  450.         $top10Trainees array_slice($traineeAbsences0$nombretrue);
  451.         return array_column($top10Trainees'trainee');
  452.     }
  453.     public function getModulesSortedByAbsence($nombreSchoolyear $schoolyear){
  454.         $assigns $this->getAssignationsBySY($schoolyear);
  455.         $assignsAbsences = [];
  456.         /** @var Trainee $trainee */
  457.         foreach ($assigns as $assign) {
  458.             // Compter les absences pour chaque stagiaire
  459.             $assignsAbsences[] = [
  460.                 'assign' => $assign,
  461.                 'absenceCount' => count($assign->getAbsences()),
  462.             ];
  463.         }
  464.         usort($assignsAbsences, function ($a$b) {
  465.             return $b['absenceCount'] <=> $a['absenceCount'];
  466.         });
  467.         $top10Assigns array_slice($assignsAbsences0$nombretrue);
  468.         return array_column($top10Assigns'assign');
  469.     }
  470.     public function getSeances(Schoolyear $schoolyear)
  471.     {
  472.         $allSeances = [];
  473.         foreach ($this->getAssignationsBySY($schoolyear) as $assign) {
  474.             $allSeances=array_merge($allSeances$assign->getSeances());
  475.         }
  476.         usort($allSeances, function($a$b) {
  477.             $dateA DateTime::createFromFormat('d-m-Y H:i'$a->getTakesplaceOn()->format('d-m-Y').' '.$a->getStartAt());
  478.             $dateB DateTime::createFromFormat('d-m-Y H:i'$b->getTakesplaceOn()->format('d-m-Y').' '.$b->getStartAt());
  479.             return $dateA <=> $dateB;
  480.         });
  481.         return $allSeances;
  482.     }
  483.     public function getSeancesCancelled(Schoolyear $schoolyear)
  484.     {
  485.         $allSeances = [];
  486.         foreach ($this->getAssignationsBySY($schoolyear) as $assign) {
  487.             $allSeances=array_merge($allSeances$assign->getSeancesCancelled());
  488.         }
  489.         usort($allSeances, function($a$b) {
  490.             $dateA DateTime::createFromFormat('d-m-Y H:i'$a['seanceDate'].' '.$a['scheduleitem']->getStartAt());
  491.             $dateB DateTime::createFromFormat('d-m-Y H:i'$b['seanceDate'].' '.$b['scheduleitem']->getStartAt());
  492.             return $dateA <=> $dateB;
  493.         });
  494.         return $allSeances;
  495.     }
  496.     public function getSeancesNotCreate(Schoolyear $schoolyear)
  497.     {
  498.         $allSeances = [];
  499.         foreach ($this->getAssignationsBySY($schoolyear) as $assign) {
  500.             $allSeances=array_merge($allSeances$assign->getSeancesNotCreate());
  501.         }
  502.         usort($allSeances, function($a$b) {
  503.             $dateA DateTime::createFromFormat('d-m-Y H:i'$a['seanceDate'].' '.$a['scheduleitem']->getStartAt());
  504.             $dateB DateTime::createFromFormat('d-m-Y H:i'$b['seanceDate'].' '.$b['scheduleitem']->getStartAt());
  505.             return $dateA <=> $dateB;
  506.         });
  507.         return $allSeances;
  508.     }
  509.     function mg1(Trainee $aTrainee $b)
  510.     {
  511.         return $b->getMG('first_year') <=> $a->getMG('first_year');
  512.     }
  513.     public function getFeesByMonth(Schoolyear $schoolyear){
  514.         $months=$this->getMonthsByYear($this->getTrainingYear($schoolyear), 'number');
  515.         $fees=[];
  516.         foreach ($months as $month) {
  517.             $toPay=0;
  518.             $pay=0;
  519.             $retard=0;
  520.             foreach ($this->getTrainees() as $trainee) {
  521.                 $fee=$trainee->getFeeByTypeNameSy('monthlyPayment'$month $this->getTrainingYear($schoolyear));
  522.                 if ($fee==null) continue;
  523.                 $toPay+=$fee->getMontant();
  524.                 $pay+=$fee->amountPaied();
  525.                 $retard+=$fee->restToPay();
  526.             }
  527.             $fees[]=['month'=>(\DateTime::createFromFormat('d/m/y','01/'.$month))->format('Y-m-d') , 'toPay'=>$toPay'pay'=>$pay'retard'=>$retard ];
  528.         }
  529.         return $fees;
  530.     }
  531.     public function getToPay($type='all'$year=null)
  532.     {
  533.         $toPay=0;
  534.         foreach ($this->getTrainees() as $trainee) {
  535.             $toPay+=$trainee->getToPay($type$year);
  536.         }
  537.         return $toPay;
  538.     }
  539.     public function getTotalFees($type$year=null){
  540.         $pay=0;
  541.         foreach ($this->getTrainees() as $trainee) {
  542.             $pay+=$trainee->getTotalFees($type$year);
  543.         }
  544.         return $pay;
  545.     }
  546.     public function getPay(){
  547.         $pay=0;
  548.         foreach ($this->getTrainees() as $trainee) {
  549.             $pay+=$trainee->getPay();
  550.         }
  551.         return $pay;
  552.     }
  553.     public function getTotalPay($fees$year=null){
  554.         $pay=0;
  555.         foreach ($this->getTrainees() as $trainee) {
  556.             $pay+=$trainee->getTotalPay($fees$year);
  557.         }
  558.         return $pay;
  559.     }
  560.     public function getRestPay($fees$year=null)
  561.     {
  562.         $restPay=0;
  563.         foreach ($this->getTrainees() as $trainee) {
  564.             $restPay+=$trainee->getRestPay($fees$year);
  565.         }
  566.         return $restPay;
  567.     }
  568.     public function getNbrRetard($fees$year=null)
  569.     {
  570.         $nbr=0;
  571.         foreach ($this->getTrainees() as $trainee) {
  572.             $nbr=$trainee->getRestPay($fees$year)>0?$nbr+1:$nbr;
  573.         }
  574.         return $nbr;
  575.     }
  576.     public function getAdvance($fees$year=null)
  577.     {
  578.         $advence=0;
  579.         foreach ($this->getTrainees() as $trainee) {
  580.             $advence+=$trainee->getAdvance($fees$year);
  581.         }
  582.         return $advence;
  583.     }
  584.     public function getAssignationsBySY(Schoolyear $schoolyear){
  585.         $level=$this->getTrainingYear($schoolyear);
  586.         $modules=$this->getTraining()->getModulesByLevel($level);
  587.         return $this->assignations->filter(function (Assignation $assignation) use ($modules) {
  588.             return $modules->contains($assignation->getModule());
  589.         });
  590.     }
  591.     public function getSpecialsTrainees()
  592.     {
  593.         $specialNumber=$this->docs!==null?explode(',',$this->docs):[];
  594.         $items=[];
  595.         /** @var Trainee $trainee */
  596.         foreach ($this->getTrainees() as $trainee) {
  597.             if(in_array($trainee->getRegNumber(), $specialNumber)) $items[]=$trainee;
  598.         }
  599.         return $items;
  600.     }
  601. }