<?phpnamespace App\Entity\Tutoring;use ApiPlatform\Core\Annotation\ApiResource;use App\Repository\Tutoring\OweRepository;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;/** * Owe */#[ORM\Entity(repositoryClass: OweRepository::class)]#[ORM\Table(name: 'hs_tc_tutoring_owe')]#[ApiResource]class Owe{ use Actions; #[ORM\ManyToOne(targetEntity: Month::class, cascade: ['persist'], inversedBy: 'owes')] private $month; #[ORM\ManyToOne(targetEntity: Rowscourse::class, inversedBy: 'owes')] #[ORM\JoinColumn(nullable: false)] private ?Rowscourse $rowscourse = null; /** * @var float */ #[ORM\Column(name: 'price', type: 'float', nullable: true)] private $price; /** * @var integer */ #[ORM\Column(name: 'position', type: 'integer')] private $position; #[ORM\OneToMany(mappedBy: "owe", targetEntity: Spayline::class, cascade: ["all"], orphanRemoval: false)] private Collection $items; public function __construct() { $this->createAt=new \DateTime('now'); $this->published=true; $this->items=new ArrayCollection(); } /** * @return int */ public function getPosition() { return $this->position; } /** * @param int $position * @return Owe */ public function setPosition($position) { $this->position = $position; return $this; } /** * @return float */ public function getPrice() { return $this->price; } /** * @param float $price * @return Owe */ public function setPrice($price) { $this->price = $price; return $this; } /** * @return mixed */ public function getMonth() { return $this->month; } /** * @return Owe */ public function setMonth(mixed $month) { $this->month = $month; return $this; } /** * @return Rowscourse */ public function getRowscourse(): ?Rowscourse { return $this->rowscourse; } /** * @param Rowscourse $rowscourse */ public function setRowscourse(?Rowscourse $rowscourse): Owe { $this->rowscourse = $rowscourse; return $this; } public function addItem(Spayline $item) { $item->setOwe($this); $this->items[] = $item; return $this; } /** * Remove item */ public function removeItem(Spayline $item) { $this->items->removeElement($item); } /** * Get items * * @return Collection */ public function getItems(): ArrayCollection|Collection { return $this->items; } public function amountPaied(){ $m=0; /** @var Spayline $item */ foreach ($this->items as $item){ $m+=$item->getAmount(); } return $m; } public function restToPay(){ return $this->getPrice()-$this->amountPaied(); } public function isPaied(){ if($this->getPrice()<=$this->amountPaied() && $this->isCounted()) return true; return false; } public function getClassInput(){ if($this->isPaied()) return 'input-success'; elseif ($this->amountPaied()>0) return 'input-warning'; elseif($this->isCounted()) return 'input-danger'; else return 'input-default'; } public function isCounted() { if($this->getMonth()->isPassed() && $this->getRowscourse()->getCourse()->isStillInMonth($this->getMonth()) && $this->getRowscourse()->isStillInMonth($this->getMonth())) return true; return false; }}