src/Entity/Tutoring/Student.php line 20

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\Repository\Tutoring\StudentRepository;
  6. use App\Traits\Actions;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Doctrine\ORM\Mapping\OrderBy;
  11. /**
  12.  * Student
  13.  */
  14. #[ORM\Entity(repositoryClassStudentRepository::class)]
  15. #[ORM\Table(name'hs_tc_tutoring_student')]
  16. #[ApiResource]
  17. class Student implements \Stringable
  18. {
  19.     use Actions;
  20.     /**
  21.      * @ORM\OneToOne(targetEntity="\App\Entity\User", cascade={"persist", "remove"}, inversedBy="student")
  22.      */
  23.     #[ORM\JoinColumn(nullabletrue)]
  24.     private $user;
  25.     /**
  26.      * @var string
  27.      */
  28.     #[ORM\Column(name'first_name'type'string'length255)]
  29.     private $firstName;
  30.     /**
  31.      * @var string
  32.      */
  33.     #[ORM\Column(name'last_name'type'string'length255)]
  34.     private $lastName;
  35.     /**
  36.      * @var string
  37.      */
  38.     #[ORM\Column(name'phone'type'string'length255)]
  39.     private $phone;
  40.     #[ORM\Column(name'wp'type'string'length255nullabletrue)]
  41.     private ?string $wp null;
  42.     /**
  43.      * @var string
  44.      */
  45.     #[ORM\Column(name'parent_phone'type'string'length255nullabletrue)]
  46.     private $parentPhone;
  47.     /**
  48.      * @var string
  49.      */
  50.     #[ORM\Column(name'parent_job'type'string'length255nullabletrue)]
  51.     private $parentJob;
  52.     /**
  53.      * @var string
  54.      */
  55.     #[ORM\Column(name'email'type'string'length255nullabletrue)]
  56.     private $email;
  57.     /**
  58.      * @var string
  59.      */
  60.     #[ORM\Column(name'adress'type'string'length255)]
  61.     private $adress;
  62.     /**
  63.      * @var string
  64.      */
  65.     #[ORM\Column(name'establ'type'string'length255nullabletrue)]
  66.     private $establ;
  67.     #[ORM\Column(name'slug'type'string'length255)]
  68.     private string $slug;
  69.     /**
  70.      * @var string
  71.      */
  72.     #[ORM\Column(name'pass'type'string'length255nullabletrue)]
  73.     private $pass;
  74.     #[ORM\ManyToOne(targetEntity'Level'cascade: ['persist'])]
  75.     private $level;
  76.     /**
  77.      * @var float
  78.      */
  79.     #[ORM\Column(name'fees'type'float'nullabletrue)]
  80.     private $fees;
  81.     /**
  82.      * @var float
  83.      */
  84.     #[ORM\Column(name'fees_paid'type'float'nullabletrue)]
  85.     private $feesPaid;
  86.     #[ORM\OneToMany(mappedBy'student'targetEntityRowscourse::class, cascade: ['all'], orphanRemovaltrue)]
  87.     private ?Collection $rowscourses null;
  88.     /**
  89.      * Constructor
  90.      */
  91.     public function __construct()
  92.     {
  93.         
  94.         $this->createAt=new \DateTime('now');
  95.         $this->published=false;
  96.         $this->slug=uniqid('IMAPIME_',true);
  97.         $this->wp="212";
  98.     }
  99.     /**
  100.      * Set phone
  101.      *
  102.      * @param string $phone
  103.      *
  104.      * @return Student
  105.      */
  106.     public function setPhone($phone)
  107.     {
  108.         $this->phone $phone;
  109.         return $this;
  110.     }
  111.     /**
  112.      * Get phone
  113.      *
  114.      * @return string
  115.      */
  116.     public function getPhone()
  117.     {
  118.         return $this->phone;
  119.     }
  120.     public function getWp(): ?string
  121.     {
  122.         return $this->wp;
  123.     }
  124.     public function setWp(?string $wp): void
  125.     {
  126.         $this->wp $wp;
  127.     }
  128.     /**
  129.      * Set email
  130.      *
  131.      * @param string $email
  132.      *
  133.      * @return Student
  134.      */
  135.     public function setEmail($email)
  136.     {
  137.         $this->email $email;
  138.         return $this;
  139.     }
  140.     /**
  141.      * Get email
  142.      *
  143.      * @return string
  144.      */
  145.     public function getEmail()
  146.     {
  147.         return $this->email;
  148.     }
  149.     /**
  150.      * Set adress
  151.      *
  152.      * @param string $adress
  153.      *
  154.      * @return Student
  155.      */
  156.     public function setAdress($adress)
  157.     {
  158.         $this->adress $adress;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Get adress
  163.      *
  164.      * @return string
  165.      */
  166.     public function getAdress()
  167.     {
  168.         return $this->adress;
  169.     }
  170.     /**
  171.      * @return string
  172.      */
  173.     public function getFirstName()
  174.     {
  175.         return $this->firstName;
  176.     }
  177.     /**
  178.      * @param string $firstName
  179.      * @return Student
  180.      */
  181.     public function setFirstName($firstName)
  182.     {
  183.         $this->firstName $firstName;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return string
  188.      */
  189.     public function getLastName()
  190.     {
  191.         return $this->lastName;
  192.     }
  193.     /**
  194.      * @param string $lastName
  195.      * @return Student
  196.      */
  197.     public function setLastName($lastName)
  198.     {
  199.         $this->lastName $lastName;
  200.         return $this;
  201.     }
  202.     /**
  203.      * @return string
  204.      */
  205.     public function getEstabl()
  206.     {
  207.         return $this->establ;
  208.     }
  209.     /**
  210.      * @param string $establ
  211.      */
  212.     public function setEstabl($establ)
  213.     {
  214.         $this->establ $establ;
  215.     }
  216.     /**
  217.      * @return string
  218.      */
  219.     public function getPass()
  220.     {
  221.         return $this->pass;
  222.     }
  223.     /**
  224.      * @param string $pass
  225.      * @return Student
  226.      */
  227.     public function setPass($pass)
  228.     {
  229.         $this->pass $pass;
  230.         return $this;
  231.     }
  232.     /**
  233.      * @return string
  234.      */
  235.     public function getParentPhone()
  236.     {
  237.         return $this->parentPhone;
  238.     }
  239.     /**
  240.      * @param string $parentPhone
  241.      * @return Student
  242.      */
  243.     public function setParentPhone($parentPhone)
  244.     {
  245.         $this->parentPhone $parentPhone;
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return string
  250.      */
  251.     public function getParentJob()
  252.     {
  253.         return $this->parentJob;
  254.     }
  255.     /**
  256.      * @param string $parentJob
  257.      * @return Student
  258.      */
  259.     public function setParentJob($parentJob)
  260.     {
  261.         $this->parentJob $parentJob;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return mixed
  266.      */
  267.     public function getLevel()
  268.     {
  269.         return $this->level;
  270.     }
  271.     /**
  272.      * @return string
  273.      */
  274.     public function getSlug()
  275.     {
  276.         return $this->slug;
  277.     }
  278.     /**
  279.      * @param string $slug
  280.      * @return Student
  281.      */
  282.     public function setSlug($slug)
  283.     {
  284.         $this->slug $slug;
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return Student
  289.      */
  290.     public function setLevel(mixed $level)
  291.     {
  292.         $this->level $level;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return float
  297.      */
  298.     public function getFees()
  299.     {
  300.         return $this->fees;
  301.     }
  302.     /**
  303.      * @param float $fees
  304.      * @return Student
  305.      */
  306.     public function setFees($fees)
  307.     {
  308.         $this->fees $fees;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return float
  313.      */
  314.     public function getFeesPaid()
  315.     {
  316.         return $this->feesPaid;
  317.     }
  318.     /**
  319.      * @param float $feesPaid
  320.      * @return Student
  321.      */
  322.     public function setFeesPaid($feesPaid)
  323.     {
  324.         $this->feesPaid $feesPaid;
  325.         return $this;
  326.     }
  327.     /**
  328.      * @return mixed
  329.      */
  330.     public function getUser()
  331.     {
  332.         return $this->user;
  333.     }
  334.     /**
  335.      * @return Student
  336.      */
  337.     public function setUser(mixed $user)
  338.     {
  339.         $this->user $user;
  340.         return $this;
  341.     }
  342.     /**
  343.      * Add rowscourse
  344.      *
  345.      *
  346.      * @return Student
  347.      */
  348.     public function addRowscourse(Rowscourse $rowscourse)
  349.     {
  350.         $rowscourse->setStudent($this);
  351.         $this->rowscourses[] = $rowscourse;
  352.         return $this;
  353.     }
  354.     /**
  355.      * Remove rowscourse
  356.      */
  357.     public function removeRowscourse(Rowscourse $rowscourse)
  358.     {
  359.         $this->rowscourses->removeElement($rowscourse);
  360.     }
  361.     /**
  362.      * Get rowscourses
  363.      *
  364.      * @return \Doctrine\Common\Collections\Collection
  365.      */
  366.     public function getRowscourses()
  367.     {
  368.         return $this->rowscourses;
  369.     }
  370.     public function getNumRegister(){
  371.         return $this->getCreateAt()->format('Y').'/'.$this->level->getId().'-'.$this->id;
  372.     }
  373.     public function getSchoolyear(){
  374.         if($this->getRowscourses()->isEmpty()){
  375.             foreach ($this->getRowscourses() as $rowscours){
  376.                 if($rowscours->getCourse()!=null) return $rowscours->getCourse()->getSchoolyear();
  377.             }
  378.         }
  379.         return false;
  380.     }
  381.     public function __toString(): string
  382.     {
  383.         return $this->firstName." ".$this->lastName;
  384.     }
  385.     public function getSumToPaid(){
  386.         $s=0;
  387.         /** @var Rowscourse $rowscours */
  388.         foreach ($this->rowscourses as $rowscours){
  389.             $s+=$rowscours->getSumToPaid();
  390.         }
  391.         return $s;
  392.     }
  393.     public function getSumOutDate(){
  394.         $s=0;
  395.         /** @var Rowscourse $rowscours */
  396.         foreach ($this->rowscourses as $rowscours){
  397.             $s+=$rowscours->getOutDate();
  398.         }
  399.         return $s;
  400.     }
  401.     public function getSumPaid(){
  402.         $s=0;
  403.         /** @var Rowscourse $rowscours */
  404.         foreach ($this->rowscourses as $rowscours){
  405.             $s+=$rowscours->getSumPaid();
  406.         }
  407.         return $s;
  408.     }
  409.     public function getRest(){
  410.         $s=0;
  411.         /** @var Rowscourse $rowscours */
  412.         foreach ($this->rowscourses as $rowscours){
  413.             $s+=$rowscours->getRest();
  414.         }
  415.         return $s;
  416.     }
  417.     public function getAdvance(){
  418.         $s=0;
  419.         /** @var Rowscourse $rowscours */
  420.         foreach ($this->rowscourses as $rowscours){
  421.             $s+=$rowscours->getAdvance();
  422.         }
  423.         return $s;
  424.     }
  425.     public function getLatePaid(){
  426.         return $this->getSumOutDate()-$this->getSumPaid();
  427.     }
  428.     public function getPcPay(){
  429.         if($this->getSumToPaid()!=0)
  430.             return round($this->getSumPaid()/$this->getSumToPaid()*100,0);
  431.         else
  432.             return 0;
  433.     }
  434.     public function getNameComplet(){
  435.         return $this->getFirstName().' '.$this->getLastName();
  436.     }
  437.     public function getRowCourse(Course $course): ?Rowscourse
  438.     {
  439.         /** @var Rowscourse $rowscours */
  440.         foreach ($this->getRowscourses() as $rowscours){
  441.             if ($course===$rowscours->getCourse()) return $rowscours;
  442.         }
  443.         return null;
  444.     }
  445.     public function getPayMonth(Course $course$month): ArrayCollection
  446.     {
  447.         $items= new ArrayCollection();
  448.         if($this->getRowCourse($course)!=null){
  449.             /** @var Spayment $payment */
  450.             foreach ($this->getRowCourse($course)->getPayments() as $payment){
  451.                 if($payment->getMonths()==$month$items->add($payment);
  452.             }
  453.         }
  454.         return $items;
  455.     }
  456.     public function getTotalPayMonth(Course $course$month){
  457.         $m=0;
  458.         /** @var Spayment $item */
  459.         foreach ($this->getPayMonth($course$month) as $item){
  460.             $m+=$item->getAmount();
  461.         }
  462.         return $m;
  463.     }
  464.     public function getScoolYear(){
  465.         /** @var Rowscourse $rowscours */
  466.         foreach ($this->getRowscourses() as $rowscours){
  467.             if($rowscours->getCourse()!=null && $rowscours->getCourse()->getSchoolyear()!=null)
  468.                 return $rowscours->getCourse()->getSchoolyear();
  469.         }
  470.         return null;
  471.     }
  472. }