src/Entity/Tutoring/Tutor.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tutoring;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Schoolyear;
  5. use App\Entity\User;
  6. use App\Repository\Tutoring\TutorRepository;
  7. use App\Traits\Actions;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. use Doctrine\ORM\Event\LifecycleEventArgs;
  13. /**
  14.  * Tutor
  15.  *
  16.  * @ORM\HasLifecycleCallbacks()
  17.  */
  18. #[ORM\Entity(repositoryClassTutorRepository::class)]
  19. #[ORM\Table(name'hs_tc_tutoring_tutor')]
  20. #[ApiResource]
  21. class Tutor implements \Stringable
  22. {
  23.     use Actions;
  24.     #[ORM\Column(name'first_name'type'string'length255)]
  25.     private ?string $firstName null;
  26.     #[ORM\Column(name'last_name'type'string'length255)]
  27.     private ?string $lastName null;
  28.     /**
  29.      * @var string
  30.      */
  31.     #[ORM\Column(name'email'type'string'length255nullabletrue)]
  32.     private $email;
  33.     /**
  34.      * @var string
  35.      */
  36.     #[ORM\Column(name'phone'type'string'length255nullabletrue)]
  37.     private $phone;
  38.     #[ORM\Column(name'wp'type'string'length255nullabletrue)]
  39.     private ?string $wp null;
  40.     #[ORM\Column(name'type_pay'type'string'length255nullabletrue)]
  41.     private ?string $typePay null;
  42.     #[ORM\Column(name'pc_pay'type'float'nullabletrue)]
  43.     private ?float $pcPay null;
  44.     #[ORM\Column(name'min_pay'type'float'nullabletrue)]
  45.     private ?float $minPay null;
  46.     /**
  47.      * @var string
  48.      */
  49.     #[ORM\Column(name'specialty'type'string'length255nullabletrue)]
  50.     private $specialty;
  51.     #[ORM\OneToOne(inversedBy"tutor"targetEntityUser::class, cascade: ["persist""remove"])]
  52.     #[ORM\JoinColumn(nullabletrue)]
  53.     private $user;
  54.     #[ORM\OneToMany(mappedBy'tutor'targetEntityCourse::class)]
  55.     private ?Collection $courses null;
  56.     /**
  57.      * Tutor constructor.
  58.      */
  59.     public function __construct()
  60.     {
  61.         
  62.         $this->createAt=new \DateTime('now');
  63.         $this->published=false;
  64.         $this->wp="212";
  65.     }
  66.     /**
  67.      * @return string
  68.      */
  69.     public function getFirstName(): ?string
  70.     {
  71.         return $this->firstName;
  72.     }
  73.     /**
  74.      * @param string $firstName
  75.      */
  76.     public function setFirstName(?string $firstName): Tutor
  77.     {
  78.         $this->firstName $firstName;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return string
  83.      */
  84.     public function getLastName(): ?string
  85.     {
  86.         return $this->lastName;
  87.     }
  88.     /**
  89.      * @param string $lastName
  90.      */
  91.     public function setLastName(?string $lastName): Tutor
  92.     {
  93.         $this->lastName $lastName;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return string
  98.      */
  99.     public function getEmail()
  100.     {
  101.         return $this->email;
  102.     }
  103.     /**
  104.      * @param string $email
  105.      * @return Tutor
  106.      */
  107.     public function setEmail($email)
  108.     {
  109.         $this->email $email;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return string
  114.      */
  115.     public function getPhone()
  116.     {
  117.         return $this->phone;
  118.     }
  119.     /**
  120.      * @param string $phone
  121.      * @return Tutor
  122.      */
  123.     public function setPhone($phone)
  124.     {
  125.         $this->phone $phone;
  126.         return $this;
  127.     }
  128.     public function getWp(): ?string
  129.     {
  130.         return $this->wp;
  131.     }
  132.     public function setWp(?string $wp): void
  133.     {
  134.         $this->wp $wp;
  135.     }
  136.     /**
  137.      * @return string
  138.      */
  139.     public function getSpecialty()
  140.     {
  141.         return $this->specialty;
  142.     }
  143.     /**
  144.      * @param string $specialty
  145.      * @return Tutor
  146.      */
  147.     public function setSpecialty($specialty)
  148.     {
  149.         $this->specialty $specialty;
  150.         return $this;
  151.     }
  152.     /**
  153.      * @return string
  154.      */
  155.     public function getTypePay(): ?string
  156.     {
  157.         return $this->typePay;
  158.     }
  159.     /**
  160.      * @param string $typePay
  161.      */
  162.     public function setTypePay(?string $typePay): Tutor
  163.     {
  164.         $this->typePay $typePay;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return float
  169.      */
  170.     public function getPcPay(): ?float
  171.     {
  172.         return $this->pcPay;
  173.     }
  174.     /**
  175.      * @param float $pcPay
  176.      */
  177.     public function setPcPay(?float $pcPay): Tutor
  178.     {
  179.         $this->pcPay $pcPay;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return float
  184.      */
  185.     public function getMinPay(): ?float
  186.     {
  187.         return $this->minPay;
  188.     }
  189.     /**
  190.      * @param float $minPay
  191.      */
  192.     public function setMinPay(?float $minPay): Tutor
  193.     {
  194.         $this->minPay $minPay;
  195.         return $this;
  196.     }
  197.     public function __toString(): string
  198.     {
  199.         return $this->lastName.' '.$this->firstName;
  200.     }
  201.     /**
  202.      * @return mixed
  203.      */
  204.     public function getUser()
  205.     {
  206.         return $this->user;
  207.     }
  208.     /**
  209.      * @return Tutor
  210.      */
  211.     public function setUser(mixed $user)
  212.     {
  213.         $this->user $user;
  214.         return $this;
  215.     }
  216.     /**
  217.      * Add course
  218.      *
  219.      *
  220.      * @return Tutor
  221.      */
  222.     public function addCourse(Course $course)
  223.     {
  224.         $course->setTutor($this);
  225.         $this->courses[] = $course;
  226.         return $this;
  227.     }
  228.     /**
  229.      * Remove course
  230.      */
  231.     public function removeCourse(Course $course)
  232.     {
  233.         $this->courses->removeElement($course);
  234.     }
  235.     /**
  236.      * Get courses
  237.      *
  238.      * @return ArrayCollection
  239.      */
  240.     public function getCourses()
  241.     {
  242.         return $this->courses;
  243.     }
  244.     public function getCoursesByYear(Schoolyear $schoolyear)
  245.     {
  246.         $items=[];
  247.         foreach ($this->getCourses() as $course) {
  248.             if ($course->getSchoolyear() == $schoolyear) {
  249.                 $items[] = $course;
  250.             }
  251.         }
  252.         return $items;
  253.     }
  254.     public function getRevenue(Schoolyear $schoolyear){
  255.         $r=0;
  256.         /** @var Course $cours */
  257.         foreach ($this->getCoursesByYear($schoolyear) as $cours){
  258.             $r+=$cours->getSumToPaid();
  259.         }
  260.         return $r;
  261.     }
  262.     public function getTotalFees(Schoolyear $schoolyear){
  263.         $f=0;
  264.         /** @var Course $cours */
  265.         foreach ($this->getCoursesByYear($schoolyear) as $cours){
  266.             $f+=$cours->getSumPaidForTutor();
  267.         }
  268.         return round($f*$this->pcPay/100,2);
  269.     }
  270.     public function getFeesByMonth($month){
  271.         $f=0;
  272.         /** @var Course $cours */
  273.         foreach ($this->getCourses() as $cours){
  274.             if('FI'==$month) continue;
  275.             $f+=$cours->getFeesByMonths($month);
  276.         }
  277.         return $f;
  278.     }
  279.     public function getRegulationByMonth($month){
  280.         $sum=0;
  281.         /** @var Course $cours */
  282.         foreach ($this->getCourses() as $cours){
  283.             $sum+=$cours->getRegulationByMonth($month);
  284.         }
  285.         return $sum;
  286.     }
  287.     public function getRestByMonth($month)
  288.     {
  289.         $sum=0;
  290.         foreach ($this->getCourses() as $cours){
  291.             $sum+=$cours->getRestByMonth($month);
  292.         }
  293.         return $sum;
  294.     }
  295.     public function getTotalRegulations(Schoolyear $schoolyear){
  296.         $t=0;
  297.         /** @var Course $cours */
  298.         foreach ($this->getCoursesByYear($schoolyear) as $cours){
  299.             $t+=$cours->getTotalRegulations();
  300.         }
  301.         return $t;
  302.     }
  303.     public function getRestRegulation(Schoolyear $schoolyear){
  304.         return max($this->getTotalFees($schoolyear)-$this->getTotalRegulations($schoolyear),0);
  305.     }
  306.     public function getAvanceBySY(Schoolyear $schoolyear){
  307.         return min($this->getTotalFees($schoolyear)-$this->getTotalRegulations($schoolyear),0);
  308.     }
  309.     public function getSituationBeforeYear(Schoolyear $schoolyear){
  310.         if($schoolyear->getPrevious()!=null){
  311.             return $this->getSituationBeforeYear($schoolyear->getPrevious())+ $this->getRestRegulation($schoolyear->getPrevious())-$this->getAvanceBySY($schoolyear->getPrevious());
  312.         }
  313.         else
  314.         return 0;
  315.     }
  316.     public function getSituationAfterYear(Schoolyear $schoolyear){
  317.         return $this->getSituationBeforeYear($schoolyear)+$this->getRevenue($schoolyear);
  318.     }
  319. }