src/Entity/Tutoring/Owe.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tutoring;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Tutoring\OweRepository;
  5. use App\Traits\Actions;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\ORM\Mapping\OrderBy;
  10. /**
  11.  * Owe
  12.  */
  13. #[ORM\Entity(repositoryClassOweRepository::class)]
  14. #[ORM\Table(name'hs_tc_tutoring_owe')]
  15. #[ApiResource]
  16. class Owe
  17. {
  18.     use Actions;
  19.     #[ORM\ManyToOne(targetEntityMonth::class, cascade: ['persist'], inversedBy'owes')]
  20.     private $month;
  21.     #[ORM\ManyToOne(targetEntityRowscourse::class, inversedBy'owes')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?Rowscourse $rowscourse null;
  24.     /**
  25.      * @var float
  26.      */
  27.     #[ORM\Column(name'price'type'float'nullabletrue)]
  28.     private $price;
  29.     /**
  30.      * @var integer
  31.      */
  32.     #[ORM\Column(name'position'type'integer')]
  33.     private $position;
  34.     #[ORM\OneToMany(mappedBy"owe"targetEntitySpayline::class, cascade: ["all"], orphanRemovalfalse)]
  35.     private Collection $items;
  36.     public function __construct()
  37.     {
  38.         
  39.         $this->createAt=new \DateTime('now');
  40.         $this->published=true;
  41.         $this->items=new ArrayCollection();
  42.     }
  43.     /**
  44.      * @return int
  45.      */
  46.     public function getPosition()
  47.     {
  48.         return $this->position;
  49.     }
  50.     /**
  51.      * @param int $position
  52.      * @return Owe
  53.      */
  54.     public function setPosition($position)
  55.     {
  56.         $this->position $position;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return float
  61.      */
  62.     public function getPrice()
  63.     {
  64.         return $this->price;
  65.     }
  66.     /**
  67.      * @param float $price
  68.      * @return Owe
  69.      */
  70.     public function setPrice($price)
  71.     {
  72.         $this->price $price;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return mixed
  77.      */
  78.     public function getMonth()
  79.     {
  80.         return $this->month;
  81.     }
  82.     /**
  83.      * @return Owe
  84.      */
  85.     public function setMonth(mixed $month)
  86.     {
  87.         $this->month $month;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Rowscourse
  92.      */
  93.     public function getRowscourse(): ?Rowscourse
  94.     {
  95.         return $this->rowscourse;
  96.     }
  97.     /**
  98.      * @param Rowscourse $rowscourse
  99.      */
  100.     public function setRowscourse(?Rowscourse $rowscourse): Owe
  101.     {
  102.         $this->rowscourse $rowscourse;
  103.         return $this;
  104.     }
  105.     public function addItem(Spayline $item)
  106.     {
  107.         $item->setOwe($this);
  108.         $this->items[] = $item;
  109.         return $this;
  110.     }
  111.     /**
  112.      * Remove item
  113.      */
  114.     public function removeItem(Spayline $item)
  115.     {
  116.         $this->items->removeElement($item);
  117.     }
  118.     /**
  119.      * Get items
  120.      *
  121.      * @return Collection
  122.      */
  123.     public function getItems(): ArrayCollection|Collection
  124.     {
  125.         return $this->items;
  126.     }
  127.     public function amountPaied(){
  128.         $m=0;
  129.         /** @var Spayline $item */
  130.         foreach ($this->items as $item){
  131.             $m+=$item->getAmount();
  132.         }
  133.         return $m;
  134.     }
  135.     public function restToPay(){
  136.         return $this->getPrice()-$this->amountPaied();
  137.     }
  138.     public function isPaied(){
  139.         if($this->getPrice()<=$this->amountPaied() && $this->isCounted()) return true;
  140.         return false;
  141.     }
  142.     public function getClassInput(){
  143.         if($this->isPaied()) return 'input-success';
  144.         elseif ($this->amountPaied()>0) return 'input-warning';
  145.         elseif($this->isCounted()) return 'input-danger';
  146.         else return 'input-default';
  147.     }
  148.     public  function isCounted()
  149.     {
  150.         if($this->getMonth()->isPassed() && $this->getRowscourse()->getCourse()->isStillInMonth($this->getMonth()) && $this->getRowscourse()->isStillInMonth($this->getMonth())) return true;
  151.         return false;
  152.     }
  153. }