<?php
namespace App\Entity\Tutoring;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Tutoring\Rowscourse;
use App\Entity\User;
use App\Repository\Tutoring\SpaymentRepository;
use App\Traits\Actions;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Spayment
*/
#[ORM\Entity(repositoryClass: SpaymentRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_spayment')]
#[ApiResource]
class Spayment implements \Stringable
{
use Actions;
#[ORM\ManyToOne(targetEntity: Rowscourse::class, inversedBy: 'payments')]
#[ORM\JoinColumn(nullable: false)]
private ?Rowscourse $rowscourse = 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(type: 'string', length: 255)]
private string $moyen;
#[ORM\Column(name: 'doc_number', type: 'string', length: 255)]
private string $docNumber = '---';
#[ORM\Column(name: 'receipt', type: 'string', length: 255, nullable: true)]
private ?string $receipt = null;
#[ORM\Column(name: 'cached', type: 'boolean')]
private bool $cached = false;
#[ORM\OneToMany(mappedBy: "payment", targetEntity: Spayline::class, cascade: ["all"], orphanRemoval: true)]
private Collection $items;
/**
* Spayment constructor.
*/
public function __construct()
{
$this->publishedAt=new \DateTime('now');
$this->published=true;
$this->items=new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set way
*
* @param string $way
*
* @return Spayment
*/
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 Spayment
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
public function getMoyen(): string
{
return $this->moyen;
}
public function setMoyen(string $moyen): Spayment
{
$this->moyen = $moyen;
return $this;
}
/**
* Set docNumber
*
* @param string $docNumber
*
* @return Spayment
*/
public function setDocNumber($docNumber)
{
$this->docNumber = $docNumber;
return $this;
}
/**
* Get docNumber
*
* @return string
*/
public function getDocNumber()
{
return $this->docNumber;
}
public function getReceipt(): ?string
{
return $this->receipt;
}
public function setReceipt(?string $receipt): void
{
$this->receipt = $receipt;
}
/**
* Set cached
*
*
* @return Spayment
*/
public function setCached($cached)
{
$this->cached = $cached;
return $this;
}
/**
* Get cached
*
* @return bool
*/
public function getCached()
{
return $this->cached;
}
public function isCached()
{
return $this->cached;
}
/**
* Set rowscourse
*
*
* @return Spayment
*/
public function setRowscourse(Rowscourse $rowscourse)
{
$this->rowscourse = $rowscourse;
return $this;
}
/**
* Get rowscourse
*
* @return Rowscourse
*/
public function getRowscourse()
{
return $this->rowscourse;
}
/**
* Set initie
*
*
* @return Spayment
*/
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 Spayment $payment */
foreach ($this->getRowscourse()->getPayments() as $payment){
if($payment->getCreateAt()<=$this->getCreateAt() && $payment->getId()<$this->getId()){
$items[]=$payment;
}
}
return $items;
}
public function getSumPrevious(){
$s=0;
/** @var Spayment $pay */
foreach ($this->getPrevious() as $pay){
$s+=$pay->getAmount();
}
return $s;
}
public function getMonths(){
return $this->way;
}
public function __toString(): string
{
$rason=$this->rowscourse->getCourse()==null?$this->rowscourse->getSubject():$this->rowscourse->getCourse();
return
'Id:'.$this->id.'<br>'.
'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
'Eleve: '.$this->rowscourse->getStudent()->getNameComplet().'<br>'.
'Raison:'.$rason.'<br>'.
'Montant: '.$this->getAmount().' DH<br>'
;
}
public function setCreateAt2(\DateTime $dateTime): Spayment
{
$this->createAt=$dateTime;
return $this;
}
/**
* Add item
*
*
* @return Spayment
*/
public function addItem(Spayline $item)
{
$item->setPayment($this);
$this->items->add($item);
return $this;
}
/**
* Remove item
*/
public function removeItem(Spayline $item)
{
$this->items->removeElement($item);
}
/**
* Get items
*
* @return Collection
*/
public function getItems()
{
return $this->items;
}
}