<?php
namespace App\Entity\Tutoring;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Schoolyear;
use App\Repository\Tutoring\StudentRepository;
use App\Traits\Actions;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
/**
* Student
*/
#[ORM\Entity(repositoryClass: StudentRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_student')]
#[ApiResource]
class Student implements \Stringable
{
use Actions;
/**
* @ORM\OneToOne(targetEntity="\App\Entity\User", cascade={"persist", "remove"}, inversedBy="student")
*/
#[ORM\JoinColumn(nullable: true)]
private $user;
/**
* @var string
*/
#[ORM\Column(name: 'first_name', type: 'string', length: 255)]
private $firstName;
/**
* @var string
*/
#[ORM\Column(name: 'last_name', type: 'string', length: 255)]
private $lastName;
/**
* @var string
*/
#[ORM\Column(name: 'phone', type: 'string', length: 255)]
private $phone;
#[ORM\Column(name: 'wp', type: 'string', length: 255, nullable: true)]
private ?string $wp = null;
/**
* @var string
*/
#[ORM\Column(name: 'parent_phone', type: 'string', length: 255, nullable: true)]
private $parentPhone;
/**
* @var string
*/
#[ORM\Column(name: 'parent_job', type: 'string', length: 255, nullable: true)]
private $parentJob;
/**
* @var string
*/
#[ORM\Column(name: 'email', type: 'string', length: 255, nullable: true)]
private $email;
/**
* @var string
*/
#[ORM\Column(name: 'adress', type: 'string', length: 255)]
private $adress;
/**
* @var string
*/
#[ORM\Column(name: 'establ', type: 'string', length: 255, nullable: true)]
private $establ;
#[ORM\Column(name: 'slug', type: 'string', length: 255)]
private string $slug;
/**
* @var string
*/
#[ORM\Column(name: 'pass', type: 'string', length: 255, nullable: true)]
private $pass;
#[ORM\ManyToOne(targetEntity: 'Level', cascade: ['persist'])]
private $level;
/**
* @var float
*/
#[ORM\Column(name: 'fees', type: 'float', nullable: true)]
private $fees;
/**
* @var float
*/
#[ORM\Column(name: 'fees_paid', type: 'float', nullable: true)]
private $feesPaid;
#[ORM\OneToMany(mappedBy: 'student', targetEntity: Rowscourse::class, cascade: ['all'], orphanRemoval: true)]
private ?Collection $rowscourses = null;
/**
* Constructor
*/
public function __construct()
{
$this->createAt=new \DateTime('now');
$this->published=false;
$this->slug=uniqid('IMAPIME_',true);
$this->wp="212";
}
/**
* Set phone
*
* @param string $phone
*
* @return Student
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
public function getWp(): ?string
{
return $this->wp;
}
public function setWp(?string $wp): void
{
$this->wp = $wp;
}
/**
* Set email
*
* @param string $email
*
* @return Student
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set adress
*
* @param string $adress
*
* @return Student
*/
public function setAdress($adress)
{
$this->adress = $adress;
return $this;
}
/**
* Get adress
*
* @return string
*/
public function getAdress()
{
return $this->adress;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
* @return Student
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param string $lastName
* @return Student
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* @return string
*/
public function getEstabl()
{
return $this->establ;
}
/**
* @param string $establ
*/
public function setEstabl($establ)
{
$this->establ = $establ;
}
/**
* @return string
*/
public function getPass()
{
return $this->pass;
}
/**
* @param string $pass
* @return Student
*/
public function setPass($pass)
{
$this->pass = $pass;
return $this;
}
/**
* @return string
*/
public function getParentPhone()
{
return $this->parentPhone;
}
/**
* @param string $parentPhone
* @return Student
*/
public function setParentPhone($parentPhone)
{
$this->parentPhone = $parentPhone;
return $this;
}
/**
* @return string
*/
public function getParentJob()
{
return $this->parentJob;
}
/**
* @param string $parentJob
* @return Student
*/
public function setParentJob($parentJob)
{
$this->parentJob = $parentJob;
return $this;
}
/**
* @return mixed
*/
public function getLevel()
{
return $this->level;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
* @return Student
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* @return Student
*/
public function setLevel(mixed $level)
{
$this->level = $level;
return $this;
}
/**
* @return float
*/
public function getFees()
{
return $this->fees;
}
/**
* @param float $fees
* @return Student
*/
public function setFees($fees)
{
$this->fees = $fees;
return $this;
}
/**
* @return float
*/
public function getFeesPaid()
{
return $this->feesPaid;
}
/**
* @param float $feesPaid
* @return Student
*/
public function setFeesPaid($feesPaid)
{
$this->feesPaid = $feesPaid;
return $this;
}
/**
* @return mixed
*/
public function getUser()
{
return $this->user;
}
/**
* @return Student
*/
public function setUser(mixed $user)
{
$this->user = $user;
return $this;
}
/**
* Add rowscourse
*
*
* @return Student
*/
public function addRowscourse(Rowscourse $rowscourse)
{
$rowscourse->setStudent($this);
$this->rowscourses[] = $rowscourse;
return $this;
}
/**
* Remove rowscourse
*/
public function removeRowscourse(Rowscourse $rowscourse)
{
$this->rowscourses->removeElement($rowscourse);
}
/**
* Get rowscourses
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRowscourses()
{
return $this->rowscourses;
}
public function getNumRegister(){
return $this->getCreateAt()->format('Y').'/'.$this->level->getId().'-'.$this->id;
}
public function getSchoolyear(){
if($this->getRowscourses()->isEmpty()){
foreach ($this->getRowscourses() as $rowscours){
if($rowscours->getCourse()!=null) return $rowscours->getCourse()->getSchoolyear();
}
}
return false;
}
public function __toString(): string
{
return $this->firstName." ".$this->lastName;
}
public function getSumToPaid(){
$s=0;
/** @var Rowscourse $rowscours */
foreach ($this->rowscourses as $rowscours){
$s+=$rowscours->getSumToPaid();
}
return $s;
}
public function getSumOutDate(){
$s=0;
/** @var Rowscourse $rowscours */
foreach ($this->rowscourses as $rowscours){
$s+=$rowscours->getOutDate();
}
return $s;
}
public function getSumPaid(){
$s=0;
/** @var Rowscourse $rowscours */
foreach ($this->rowscourses as $rowscours){
$s+=$rowscours->getSumPaid();
}
return $s;
}
public function getRest(){
$s=0;
/** @var Rowscourse $rowscours */
foreach ($this->rowscourses as $rowscours){
$s+=$rowscours->getRest();
}
return $s;
}
public function getAdvance(){
$s=0;
/** @var Rowscourse $rowscours */
foreach ($this->rowscourses as $rowscours){
$s+=$rowscours->getAdvance();
}
return $s;
}
public function getLatePaid(){
return $this->getSumOutDate()-$this->getSumPaid();
}
public function getPcPay(){
if($this->getSumToPaid()!=0)
return round($this->getSumPaid()/$this->getSumToPaid()*100,0);
else
return 0;
}
public function getNameComplet(){
return $this->getFirstName().' '.$this->getLastName();
}
public function getRowCourse(Course $course): ?Rowscourse
{
/** @var Rowscourse $rowscours */
foreach ($this->getRowscourses() as $rowscours){
if ($course===$rowscours->getCourse()) return $rowscours;
}
return null;
}
public function getPayMonth(Course $course, $month): ArrayCollection
{
$items= new ArrayCollection();
if($this->getRowCourse($course)!=null){
/** @var Spayment $payment */
foreach ($this->getRowCourse($course)->getPayments() as $payment){
if($payment->getMonths()==$month) $items->add($payment);
}
}
return $items;
}
public function getTotalPayMonth(Course $course, $month){
$m=0;
/** @var Spayment $item */
foreach ($this->getPayMonth($course, $month) as $item){
$m+=$item->getAmount();
}
return $m;
}
public function getScoolYear(){
/** @var Rowscourse $rowscours */
foreach ($this->getRowscourses() as $rowscours){
if($rowscours->getCourse()!=null && $rowscours->getCourse()->getSchoolyear()!=null)
return $rowscours->getCourse()->getSchoolyear();
}
return null;
}
}