src/Entity/Formation/Intervenant.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Formation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Schoolyear;
  5. use App\Repository\Formation\IntervenantRepository;
  6. use App\Traits\Actions;
  7. use App\Entity\Formation\Attribution;
  8. use DateInterval;
  9. use DatePeriod;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use App\Entity\User;
  14. #[ORM\Entity(repositoryClassIntervenantRepository::class)]
  15. #[ORM\Table(name'hs_tc_formation_intervenant')]
  16. #[ApiResource]
  17. class Intervenant implements \Stringable
  18. {
  19.     use Actions;
  20.     #[ORM\Column(name"first_name"type"string"length255)]
  21.     private string $firstName;
  22.     #[ORM\Column(name"last_name"type"string"length255)]
  23.     private string $lastName;
  24.     #[ORM\Column(name"email"type"string"length255nullabletrue)]
  25.     private ?string $email;
  26.     #[ORM\Column(name"phone"type"string"length255nullabletrue)]
  27.     private ?string $phone;
  28.     #[ORM\Column(name'wp'type'string'length255nullabletrue)]
  29.     private ?string $wp null;
  30.     #[ORM\Column(name"specialty"type"string"length255nullabletrue)]
  31.     private ?string $specialty;
  32.     #[ORM\Column(name'type_pay'type'string'length255nullabletrue)]
  33.     private ?string $typePay null;
  34.     #[ORM\Column(name'pc_pay'type'float'nullabletrue)]
  35.     private ?float $pcPay null;
  36.     #[ORM\Column(name'min_pay'type'float'nullabletrue)]
  37.     private ?float $minPay null;
  38.     #[ORM\OneToOne(inversedBy"intervenant"targetEntityUser::class, cascade: ["persist""remove"])]
  39.     #[ORM\JoinColumn(nullabletrue)]
  40.     private ?User $user=null;
  41.     #[ORM\OneToMany(mappedBy"intervenant"targetEntity"Attribution")]
  42.     private Collection $attributions;
  43.     #[ORM\OneToMany(mappedBy'intervenant'targetEntityAregulation::class, cascade: ["persist"], orphanRemovaltrue)]
  44.     private Collection $regulations;
  45.     public function __construct()
  46.     {
  47.         // date_default_timezone_set('Africa/Casablanca');
  48.         $this->createAt=new \DateTime('now');
  49.         $this->published=false;
  50.         $this->wp="212";
  51.     }
  52.     /**
  53.      * @return string
  54.      */
  55.     public function getFirstName(): ?string
  56.     {
  57.         return $this->firstName;
  58.     }
  59.     /**
  60.      * @param string $firstName
  61.      */
  62.     public function setFirstName(?string $firstName): Intervenant
  63.     {
  64.         $this->firstName $firstName;
  65.         return $this;
  66.     }
  67.     /**
  68.      * @return string
  69.      */
  70.     public function getLastName(): ?string
  71.     {
  72.         return $this->lastName;
  73.     }
  74.     /**
  75.      * @param string $lastName
  76.      */
  77.     public function setLastName(?string $lastName): Intervenant
  78.     {
  79.         $this->lastName $lastName;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return string
  84.      */
  85.     public function getEmail()
  86.     {
  87.         return $this->email;
  88.     }
  89.     /**
  90.      * @param string $email
  91.      * @return Intervenant
  92.      */
  93.     public function setEmail($email)
  94.     {
  95.         $this->email $email;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return string
  100.      */
  101.     public function getPhone()
  102.     {
  103.         return $this->phone;
  104.     }
  105.     /**
  106.      * @param string $phone
  107.      * @return Intervenant
  108.      */
  109.     public function setPhone($phone)
  110.     {
  111.         $this->phone $phone;
  112.         return $this;
  113.     }
  114.     public function getWp(): ?string
  115.     {
  116.         return $this->wp;
  117.     }
  118.     public function setWp(?string $wp): void
  119.     {
  120.         $this->wp $wp;
  121.     }
  122.     /**
  123.      * @return string
  124.      */
  125.     public function getSpecialty()
  126.     {
  127.         return $this->specialty;
  128.     }
  129.     /**
  130.      * @param string $specialty
  131.      * @return Intervenant
  132.      */
  133.     public function setSpecialty($specialty)
  134.     {
  135.         $this->specialty $specialty;
  136.         return $this;
  137.     }
  138.     public function __toString(): string
  139.     {
  140.         return $this->lastName.' '.$this->firstName;
  141.     }
  142.     public function getRegulations(): Collection
  143.     {
  144.         return $this->regulations;
  145.     }
  146.     public function setRegulations(Collection $regulations): void
  147.     {
  148.         $this->regulations $regulations;
  149.     }
  150.     public function getUser(): ?User
  151.     {
  152.         return $this->user;
  153.     }
  154.     public function setUser(?User $user): void
  155.     {
  156.         $this->user $user;
  157.     }
  158.     /**
  159.      * Add attribution
  160.      *
  161.      *
  162.      * @return Intervenant
  163.      */
  164.     public function addAttribution(Attribution $attribution)
  165.     {
  166.         $attribution->setIntervenant($this);
  167.         $this->attributions[] = $attribution;
  168.         return $this;
  169.     }
  170.     /**
  171.      * Remove attribution
  172.      */
  173.     public function removeAttribution(Attribution $attribution)
  174.     {
  175.         $this->attributions->removeElement($attribution);
  176.     }
  177.     /**
  178.      * Get attributions
  179.      *
  180.      * @return Collection
  181.      */
  182.     public function getAttributions()
  183.     {
  184.         return $this->attributions;
  185.     }
  186.     public function getTypePay(): ?string
  187.     {
  188.         return $this->typePay;
  189.     }
  190.     public function setTypePay(?string $typePay): void
  191.     {
  192.         $this->typePay $typePay;
  193.     }
  194.     public function getPcPay(): ?float
  195.     {
  196.         return $this->pcPay;
  197.     }
  198.     public function setPcPay(?float $pcPay): void
  199.     {
  200.         $this->pcPay $pcPay;
  201.     }
  202.     public function getMinPay(): ?float
  203.     {
  204.         return $this->minPay;
  205.     }
  206.     public function setMinPay(?float $minPay): void
  207.     {
  208.         $this->minPay $minPay;
  209.     }
  210.     public function getAregulations(): Collection
  211.     {
  212.         return $this->regulations;
  213.     }
  214.     public function addAregulation(Aregulation $aregulation): self
  215.     {
  216.         if (!$this->regulations->contains($aregulation)) {
  217.             $this->regulations->add($aregulation);
  218.             $aregulation->setIntervenant($this);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeAregulation(Aregulation $aregulation): self
  223.     {
  224.         if ($this->regulations->removeElement($aregulation)) {
  225.             // set the owning side to null (unless already changed)
  226.             if ($aregulation->getIntervenant() === $this) {
  227.                 $aregulation->setIntervenant(null);
  228.             }
  229.         }
  230.         return $this;
  231.     }
  232.     public function getAttributionsBySY(Schoolyear $schoolyear)
  233.     {
  234.         return $this->attributions->filter(function (Attribution $attribution) use ($schoolyear) {
  235.             return $attribution->getClasse()->getSchoolYear() === $schoolyear;
  236.         });
  237.     }
  238.     public function getStartWorkInSY(Schoolyear $schoolyear)
  239.     {
  240.         $start null;
  241.         foreach ($this->getAttributionsBySY($schoolyear) as $att) {
  242.             if ($att->getStartAt() instanceof \DateTimeInterface) {
  243.                 if ($start === null || $att->getStartAt() < $start) {
  244.                     $start $att->getStartAt();
  245.                 }
  246.             }
  247.         }
  248.         return $start;
  249.     }
  250.     public function getEndWorkInSY(Schoolyear $schoolyear)
  251.     {
  252.         $end null;
  253.         foreach ($this->getAttributionsBySY($schoolyear) as $att) {
  254.             if ($att->getEndAt() instanceof \DateTimeInterface) {
  255.                 if ($end === null || $att->getEndAt() > $end) {
  256.                     $end $att->getEndAt();
  257.                 }
  258.             }
  259.         }
  260.         return $end;
  261.     }
  262.     public function getMonthBySY(Schoolyear $schoolyear)
  263.     {
  264.         $months = [];
  265.         $start $this->getStartWorkInSY($schoolyear);
  266.         $end $this->getEndWorkInSY($schoolyear);
  267.         if($start instanceof \DateTimeInterface && $end instanceof \DateTimeInterface) {
  268.             $interval DateInterval::createFromDateString('1 month');
  269.             $period = new DatePeriod($start$interval$end);
  270.             foreach ($period as $date) {
  271.                 $months[] = $date->format('m-y');
  272.             }
  273.         }
  274.         return $months;
  275.     }
  276.     public function getHourlyBySY(Schoolyear $schoolyear)
  277.     {
  278.         $hourly=0;
  279.         foreach($this->getAttributionsBySY($schoolyear) as $attribution){
  280.             $hourly+=$attribution->getHoulyAchievedAsHoure('aseance');
  281.         }
  282.         return $hourly;
  283.     }
  284.     public function getHourlyBySYOnStr(Schoolyear $schoolyear)
  285.     {
  286.         $h=floor($this->getHourlyBySY($schoolyear));
  287.         $m=($this->getHourlyBySY($schoolyear)-$h)*60;
  288.         return $h.'h'.$m.'min';
  289.     }
  290.     public function getRemunerationDueBySY(Schoolyear $schoolyear)
  291.     {
  292.         if($this->typePay=='Salary') return $this->pcPay*count($this->getMonthBySY($schoolyear));
  293.         $m=0;
  294.         foreach ($this->getAttributionsBySY($schoolyear) as $attribution){
  295.             $m+=$attribution->getRemunerationDue();
  296.         }
  297.         return $m;
  298.     }
  299.     public function getRemunerationRegledBySY(Schoolyear $schoolyear)
  300.     {
  301.         $m=0;
  302.         foreach($this->getAregulations() as $fregulation){
  303.             if($fregulation->getSchoolyear() === $schoolyear)
  304.                 $m+=$fregulation->getAmount();
  305.         }
  306.         return $m;
  307.     }
  308.     public function getRemunerationResteBySY(Schoolyear $schoolyear)
  309.     {
  310.         return $this->getRemunerationDueBySY($schoolyear)-$this->getRemunerationRegledBySY($schoolyear);
  311.     }
  312.     public function getHourlyByMonth($month)
  313.     {
  314.         $hourly=0;
  315.         foreach($this->getAttributions() as $attribution){
  316.             $hourly+=$attribution->getHourelyWorkedByMonth($month);
  317.         }
  318.         return $hourly;
  319.     }
  320.     public function getHourlyByMonthOnStr($month)
  321.     {
  322.         $h=floor($this->getHourlyByMonth($month));
  323.         $m=floor(($this->getHourlyByMonth($month)-$h)*60);
  324.         return $h.'h'.$m.'min';
  325.     }
  326.     public function getRemunerationDueByMonth($month)
  327.     {
  328.         if ($this->getTypePay()=='Salary') return $this->pcPay;
  329.         $m=0;
  330.         foreach ($this->getAttributions() as $attribution){
  331.             $m+=$attribution->getRemunerationByMonth($month);
  332.         }
  333.         return $m;
  334.     }
  335.     public function getRegulationDetails(Schoolyear $schoolyear)
  336.     {
  337.         $details=[];
  338.         $total=$this->getRemunerationRegledBySY($schoolyear);
  339.         foreach ($schoolyear->getMonths('m-y') as $month){
  340.             $details[$month]=min($total,$this->getRemunerationDueByMonth($month));
  341.             $total=max($total-$this->getRemunerationDueByMonth($month),0);
  342.         }
  343.         $details['av']=$total;
  344.         return $details;
  345.     }
  346.     public function getRegulationByMonth(Schoolyear $schoolyear$month)
  347.     {
  348.         if(in_array($month$schoolyear->getMonths('m-y'))){
  349.             return $this->getRegulationDetails($schoolyear)[$month];
  350.         }
  351.         return 0;
  352.     }
  353.     public function getResteByMonth(Schoolyear $schoolyear$month)
  354.     {
  355.         return max($this->getRemunerationDueByMonth($month)-$this->getRegulationByMonth($schoolyear$month),0);
  356.     }
  357.     public function getAvanceBySY(Schoolyear $schoolyear)
  358.     {
  359.         return $this->getRegulationDetails($schoolyear)['av'];
  360.     }
  361. }