src/Entity/Tutoring/Regulation.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tutoring;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Tutoring\Course;
  5. use App\Entity\User;
  6. use App\Repository\Tutoring\RegulationRepository;
  7. use App\Traits\Actions;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * Regulation
  11.  */
  12. #[ORM\Entity(repositoryClassRegulationRepository::class)]
  13. #[ORM\Table(name'hs_tc_tutoring_regulation')]
  14. #[ApiResource]
  15. class Regulation implements \Stringable
  16. {
  17.     use Actions;
  18.     #[ORM\ManyToOne(targetEntity'Course'inversedBy'regulations')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?Course $course null;
  21.     #[ORM\ManyToOne(targetEntityUser::class)]
  22.     #[ORM\JoinColumn(nullabletrue)]
  23.     private ?User $initie null;
  24.     /**
  25.      * @var string
  26.      */
  27.     #[ORM\Column(name'way'type'string'length255)]
  28.     private $way;
  29.     /**
  30.      * @var float
  31.      */
  32.     #[ORM\Column(name'amount'type'float')]
  33.     private $amount;
  34.     #[ORM\Column(name'doc_number'type'string'length255)]
  35.     private string $docNumber '11';
  36.     #[ORM\Column(name'cached'type'boolean')]
  37.     private bool $cached false;
  38.     /**
  39.      * Regulation constructor.
  40.      */
  41.     public function __construct()
  42.     {
  43.         
  44.         $this->publishedAt=new \DateTime('now');
  45.         $this->published=false;
  46.     }
  47.     /**
  48.      * Get id
  49.      *
  50.      * @return int
  51.      */
  52.     public function getId()
  53.     {
  54.         return $this->id;
  55.     }
  56.     /**
  57.      * Set way
  58.      *
  59.      * @param string $way
  60.      *
  61.      * @return Regulation
  62.      */
  63.     public function setWay($way)
  64.     {
  65.         $this->way $way;
  66.         return $this;
  67.     }
  68.     /**
  69.      * Get way
  70.      *
  71.      * @return string
  72.      */
  73.     public function getWay()
  74.     {
  75.         return $this->way;
  76.     }
  77.     /**
  78.      * Set amount
  79.      *
  80.      * @param float $amount
  81.      *
  82.      * @return Regulation
  83.      */
  84.     public function setAmount($amount)
  85.     {
  86.         $this->amount $amount;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Get amount
  91.      *
  92.      * @return float
  93.      */
  94.     public function getAmount()
  95.     {
  96.         return $this->amount;
  97.     }
  98.     /**
  99.      * Set docNumber
  100.      *
  101.      * @param string $docNumber
  102.      *
  103.      * @return Regulation
  104.      */
  105.     public function setDocNumber($docNumber)
  106.     {
  107.         $this->docNumber $docNumber;
  108.         return $this;
  109.     }
  110.     /**
  111.      * Get docNumber
  112.      *
  113.      * @return string
  114.      */
  115.     public function getDocNumber()
  116.     {
  117.         return $this->docNumber;
  118.     }
  119.     /**
  120.      * Set cached
  121.      *
  122.      *
  123.      * @return Regulation
  124.      */
  125.     public function setCached($cached)
  126.     {
  127.         $this->cached $cached;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get cached
  132.      *
  133.      * @return bool
  134.      */
  135.     public function getCached()
  136.     {
  137.         return $this->cached;
  138.     }
  139.     /**
  140.      * Set course
  141.      *
  142.      *
  143.      * @return Regulation
  144.      */
  145.     public function setCourse(Course $course)
  146.     {
  147.         $this->course $course;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get course
  152.      *
  153.      * @return Course
  154.      */
  155.     public function getCourse()
  156.     {
  157.         return $this->course;
  158.     }
  159.     /**
  160.      * Set initie
  161.      *
  162.      *
  163.      * @return Regulation
  164.      */
  165.     public function setInitie(User $initie)
  166.     {
  167.         $this->initie $initie;
  168.         return $this;
  169.     }
  170.     /**
  171.      * Get initie
  172.      *
  173.      * @return User
  174.      */
  175.     public function getInitie()
  176.     {
  177.         return $this->initie;
  178.     }
  179.     public function getPrevious(){
  180.         $items=[];
  181.         /** @var Regulation $payment */
  182.         foreach ($this->getCourse()->getPayments() as $payment){
  183.             if($payment->getCreateAt()<=$this->getCreateAt() && $payment->getId()<$this->getId()){
  184.                 $items[]=$payment;
  185.             }
  186.         }
  187.         return $items;
  188.     }
  189.     public function getSumPrevious(){
  190.         $s=0;
  191.         /** @var Regulation $pay */
  192.         foreach ($this->getPrevious() as $pay){
  193.             $s+=$pay->getAmount();
  194.         }
  195.         return $s;
  196.     }
  197.     public function getMonths(){
  198.         return $this->way;
  199.     }
  200.     public function __toString(): string
  201.     {
  202.         $rason=$this->getCourse()." (".$this->way.")";
  203.         return
  204.             'Id:'.$this->id.'<br>'.
  205.             'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
  206.             'Tuteur: '.$this->course->getTutor().'<br>'.
  207.             'Raison:'.$rason.'<br>'.
  208.             'Montant: '.$this->getAmount().' DH<br>'
  209.             ;
  210.     }
  211. }