src/Entity/Tutoring/Spayment.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Tutoring;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Tutoring\Rowscourse;
  5. use App\Entity\User;
  6. use App\Repository\Tutoring\SpaymentRepository;
  7. use App\Traits\Actions;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12.  * Spayment
  13.  */
  14. #[ORM\Entity(repositoryClassSpaymentRepository::class)]
  15. #[ORM\Table(name'hs_tc_tutoring_spayment')]
  16. #[ApiResource]
  17. class Spayment implements \Stringable
  18. {
  19.     use Actions;
  20.     #[ORM\ManyToOne(targetEntityRowscourse::class, inversedBy'payments')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?Rowscourse $rowscourse null;
  23.     #[ORM\ManyToOne(targetEntityUser::class)]
  24.     #[ORM\JoinColumn(nullabletrue)]
  25.     private ?User $initie null;
  26.     /**
  27.      * @var string
  28.      */
  29.     #[ORM\Column(name'way'type'string'length255)]
  30.     private $way;
  31.     /**
  32.      * @var float
  33.      */
  34.     #[ORM\Column(name'amount'type'float')]
  35.     private $amount;
  36.     #[ORM\Column(type'string'length255)]
  37.     private string $moyen;
  38.     #[ORM\Column(name'doc_number'type'string'length255)]
  39.     private string $docNumber '---';
  40.     #[ORM\Column(name'receipt'type'string'length255nullabletrue)]
  41.     private ?string $receipt null;
  42.     #[ORM\Column(name'cached'type'boolean')]
  43.     private bool $cached false;
  44.     #[ORM\OneToMany(mappedBy"payment"targetEntitySpayline::class, cascade: ["all"], orphanRemovaltrue)]
  45.     private Collection $items;
  46.     /**
  47.      * Spayment constructor.
  48.      */
  49.     public function __construct()
  50.     {
  51.         
  52.         $this->publishedAt=new \DateTime('now');
  53.         $this->published=true;
  54.         $this->items=new ArrayCollection();
  55.     }
  56.     /**
  57.      * Get id
  58.      *
  59.      * @return int
  60.      */
  61.     public function getId()
  62.     {
  63.         return $this->id;
  64.     }
  65.     /**
  66.      * Set way
  67.      *
  68.      * @param string $way
  69.      *
  70.      * @return Spayment
  71.      */
  72.     public function setWay($way)
  73.     {
  74.         $this->way $way;
  75.         return $this;
  76.     }
  77.     /**
  78.      * Get way
  79.      *
  80.      * @return string
  81.      */
  82.     public function getWay()
  83.     {
  84.         return $this->way;
  85.     }
  86.     /**
  87.      * Set amount
  88.      *
  89.      * @param float $amount
  90.      *
  91.      * @return Spayment
  92.      */
  93.     public function setAmount($amount)
  94.     {
  95.         $this->amount $amount;
  96.         return $this;
  97.     }
  98.     /**
  99.      * Get amount
  100.      *
  101.      * @return float
  102.      */
  103.     public function getAmount()
  104.     {
  105.         return $this->amount;
  106.     }
  107.     public function getMoyen(): string
  108.     {
  109.         return $this->moyen;
  110.     }
  111.     public function setMoyen(string $moyen): Spayment
  112.     {
  113.         $this->moyen $moyen;
  114.         return $this;
  115.     }
  116.     /**
  117.      * Set docNumber
  118.      *
  119.      * @param string $docNumber
  120.      *
  121.      * @return Spayment
  122.      */
  123.     public function setDocNumber($docNumber)
  124.     {
  125.         $this->docNumber $docNumber;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Get docNumber
  130.      *
  131.      * @return string
  132.      */
  133.     public function getDocNumber()
  134.     {
  135.         return $this->docNumber;
  136.     }
  137.     public function getReceipt(): ?string
  138.     {
  139.         return $this->receipt;
  140.     }
  141.     public function setReceipt(?string $receipt): void
  142.     {
  143.         $this->receipt $receipt;
  144.     }
  145.     /**
  146.      * Set cached
  147.      *
  148.      *
  149.      * @return Spayment
  150.      */
  151.     public function setCached($cached)
  152.     {
  153.         $this->cached $cached;
  154.         return $this;
  155.     }
  156.     /**
  157.      * Get cached
  158.      *
  159.      * @return bool
  160.      */
  161.     public function getCached()
  162.     {
  163.         return $this->cached;
  164.     }
  165.     public function isCached()
  166.     {
  167.         return $this->cached;
  168.     }
  169.     /**
  170.      * Set rowscourse
  171.      *
  172.      *
  173.      * @return Spayment
  174.      */
  175.     public function setRowscourse(Rowscourse $rowscourse)
  176.     {
  177.         $this->rowscourse $rowscourse;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get rowscourse
  182.      *
  183.      * @return Rowscourse
  184.      */
  185.     public function getRowscourse()
  186.     {
  187.         return $this->rowscourse;
  188.     }
  189.     /**
  190.      * Set initie
  191.      *
  192.      *
  193.      * @return Spayment
  194.      */
  195.     public function setInitie(User $initie)
  196.     {
  197.         $this->initie $initie;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Get initie
  202.      *
  203.      * @return User
  204.      */
  205.     public function getInitie()
  206.     {
  207.         return $this->initie;
  208.     }
  209.     public function getPrevious(){
  210.         $items=[];
  211.         /** @var Spayment $payment */
  212.         foreach ($this->getRowscourse()->getPayments() as $payment){
  213.             if($payment->getCreateAt()<=$this->getCreateAt() && $payment->getId()<$this->getId()){
  214.                 $items[]=$payment;
  215.             }
  216.         }
  217.         return $items;
  218.     }
  219.     public function getSumPrevious(){
  220.         $s=0;
  221.         /** @var Spayment $pay */
  222.         foreach ($this->getPrevious() as $pay){
  223.             $s+=$pay->getAmount();
  224.         }
  225.         return $s;
  226.     }
  227.     public function getMonths(){
  228.         return $this->way;
  229.     }
  230.     public function __toString(): string
  231.     {
  232.         $rason=$this->rowscourse->getCourse()==null?$this->rowscourse->getSubject():$this->rowscourse->getCourse();
  233.         return
  234.             'Id:'.$this->id.'<br>'.
  235.             'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
  236.             'Eleve: '.$this->rowscourse->getStudent()->getNameComplet().'<br>'.
  237.             'Raison:'.$rason.'<br>'.
  238.             'Montant: '.$this->getAmount().' DH<br>'
  239.             ;
  240.     }
  241.     public function setCreateAt2(\DateTime $dateTime): Spayment
  242.     {
  243.         $this->createAt=$dateTime;
  244.         return $this;
  245.     }
  246.     /**
  247.      * Add item
  248.      *
  249.      *
  250.      * @return Spayment
  251.      */
  252.     public function addItem(Spayline $item)
  253.     {
  254.         $item->setPayment($this);
  255.         $this->items->add($item);
  256.         return $this;
  257.     }
  258.     /**
  259.      * Remove item
  260.      */
  261.     public function removeItem(Spayline $item)
  262.     {
  263.         $this->items->removeElement($item);
  264.     }
  265.     /**
  266.      * Get items
  267.      *
  268.      * @return Collection
  269.      */
  270.     public function getItems()
  271.     {
  272.         return $this->items;
  273.     }
  274. }