<?phpnamespace App\Entity\Tutoring;use ApiPlatform\Core\Annotation\ApiResource;use App\Entity\Tutoring\Course;use App\Entity\User;use App\Repository\Tutoring\RegulationRepository;use App\Traits\Actions;use Doctrine\ORM\Mapping as ORM;/** * Regulation */#[ORM\Entity(repositoryClass: RegulationRepository::class)]#[ORM\Table(name: 'hs_tc_tutoring_regulation')]#[ApiResource]class Regulation implements \Stringable{ use Actions; #[ORM\ManyToOne(targetEntity: 'Course', inversedBy: 'regulations')] #[ORM\JoinColumn(nullable: false)] private ?Course $course = null; #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: true)] private ?User $initie = null; /** * @var string */ #[ORM\Column(name: 'way', type: 'string', length: 255)] private $way; /** * @var float */ #[ORM\Column(name: 'amount', type: 'float')] private $amount; #[ORM\Column(name: 'doc_number', type: 'string', length: 255)] private string $docNumber = '11'; #[ORM\Column(name: 'cached', type: 'boolean')] private bool $cached = false; /** * Regulation constructor. */ public function __construct() { $this->publishedAt=new \DateTime('now'); $this->published=false; } /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set way * * @param string $way * * @return Regulation */ public function setWay($way) { $this->way = $way; return $this; } /** * Get way * * @return string */ public function getWay() { return $this->way; } /** * Set amount * * @param float $amount * * @return Regulation */ public function setAmount($amount) { $this->amount = $amount; return $this; } /** * Get amount * * @return float */ public function getAmount() { return $this->amount; } /** * Set docNumber * * @param string $docNumber * * @return Regulation */ public function setDocNumber($docNumber) { $this->docNumber = $docNumber; return $this; } /** * Get docNumber * * @return string */ public function getDocNumber() { return $this->docNumber; } /** * Set cached * * * @return Regulation */ public function setCached($cached) { $this->cached = $cached; return $this; } /** * Get cached * * @return bool */ public function getCached() { return $this->cached; } /** * Set course * * * @return Regulation */ public function setCourse(Course $course) { $this->course = $course; return $this; } /** * Get course * * @return Course */ public function getCourse() { return $this->course; } /** * Set initie * * * @return Regulation */ public function setInitie(User $initie) { $this->initie = $initie; return $this; } /** * Get initie * * @return User */ public function getInitie() { return $this->initie; } public function getPrevious(){ $items=[]; /** @var Regulation $payment */ foreach ($this->getCourse()->getPayments() as $payment){ if($payment->getCreateAt()<=$this->getCreateAt() && $payment->getId()<$this->getId()){ $items[]=$payment; } } return $items; } public function getSumPrevious(){ $s=0; /** @var Regulation $pay */ foreach ($this->getPrevious() as $pay){ $s+=$pay->getAmount(); } return $s; } public function getMonths(){ return $this->way; } public function __toString(): string { $rason=$this->getCourse()." (".$this->way.")"; return 'Id:'.$this->id.'<br>'. 'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'. 'Tuteur: '.$this->course->getTutor().'<br>'. 'Raison:'.$rason.'<br>'. 'Montant: '.$this->getAmount().' DH<br>' ; }}