<?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\Repository\Tutoring\TrashspaymentRepository;
use App\Traits\Actions;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Spayment
*/
#[ORM\Entity(repositoryClass: TrashspaymentRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_trashspayment')]
#[ApiResource]
class Trashspayment implements \Stringable
{
use Actions;
#[ORM\Column]
private ?int $rowsCoursId = null;
#[ORM\Column]
private ?int $coursId = null;
#[ORM\Column]
private ?int $studentId = null;
#[ORM\Column]
private ?float $rowsCoursPrice = null;
#[ORM\Column]
private ?string $coursName = null;
#[ORM\Column]
private ?string $studentFirstName = null;
#[ORM\Column]
private ?string $studentLastName = null;
#[ORM\Column]
private ?string $studentLevel = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true)]
private ?User $initie = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true)]
private User $suppressor;
/**
* @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 = '11';
#[ORM\Column(name: 'cached', type: 'boolean')]
private bool $cached = false;
#[ORM\OneToMany(mappedBy: "payment", targetEntity: Trashspayline::class, cascade: ["all"], orphanRemoval: true)]
private Collection $items;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $trashedAt = null;
/**
* Spayment constructor.
*/
public function __construct(Spayment $spayment)
{
$this->rowsCoursId=$spayment->getRowscourse()->getId();
$this->coursId=$spayment->getRowscourse()->getCourse()->getId(); //this
$this->studentId=$spayment->getRowscourse()->getStudent()->getId();
$this->rowsCoursPrice=$spayment->getRowscourse()->getPrice();
$this->coursName=$spayment->getRowscourse()->getCourse()->getName();
$this->studentFirstName=$spayment->getRowscourse()->getStudent()->getFirstName();
$this->studentLastName=$spayment->getRowscourse()->getStudent()->getLastName();
$this->studentLevel=$spayment->getRowscourse()->getStudent()->getLevel();
$this->publishedAt=$spayment->getPublishedAt();
$this->published=$spayment->isPublished();
$this->createAt=$spayment->getCreateAt();
$this->initie=$spayment->getInitie();
$this->way=$spayment->getWay();
$this->amount=$spayment->getAmount();
$this->docNumber=$spayment->getDocNumber();
$this->cached=$spayment->isCached();
$this->moyen=$spayment->getMoyen();
$this->trashedAt=new \DateTime('now');
$this->items = new ArrayCollection();
foreach ($spayment->getItems() as $spayline) {
$item=new Trashspayline($spayline);
$item->setPayment($this);
$this->items->add($item);
}
}
public function restore(Rowscourse $rowscourse, array $owes)
{
$spayment = new Spayment();
$spayment->setPublishedAt($this->publishedAt);
$spayment->setCreateAt2($this->createAt);
$spayment->setPublished($this->published);
$spayment->setRowscourse($rowscourse);
$spayment->setInitie($this->initie);
$spayment->setWay($this->way);
$spayment->setAmount($this->amount);
$spayment->setDocNumber($this->docNumber);
$spayment->setCached($this->cached);
$spayment->setMoyen($this->moyen);
foreach ($owes as $oweItem) {
$fpayline = $oweItem['trashspayline']->restore($oweItem['owe']);
$spayment->addItem($fpayline);
}
return $spayment;
}
public function setWay($way)
{
$this->way = $way;
return $this;
}
/**
* Get way
*
* @return string
*/
public function getWay()
{
return $this->way;
}
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
public function setDocNumber($docNumber)
{
$this->docNumber = $docNumber;
return $this;
}
/**
* Get docNumber
*
* @return string
*/
public function getDocNumber()
{
return $this->docNumber;
}
public function getMoyen(): string
{
return $this->moyen;
}
public function setMoyen(string $moyen): Trashspayment
{
$this->moyen = $moyen;
return $this;
}
public function setCached($cached)
{
$this->cached = $cached;
return $this;
}
/**
* Get cached
*
* @return bool
*/
public function getCached()
{
return $this->cached;
}
public function getRowsCoursId(): ?int
{
return $this->rowsCoursId;
}
public function setRowsCoursId(?int $rowsCoursId): void
{
$this->rowsCoursId = $rowsCoursId;
}
public function getCoursId(): ?int
{
return $this->coursId;
}
public function setCoursId(?int $coursId): void
{
$this->coursId = $coursId;
}
public function getStudentId(): ?int
{
return $this->studentId;
}
public function setStudentId(?int $studentId): void
{
$this->studentId = $studentId;
}
public function getRowsCoursPrice(): ?float
{
return $this->rowsCoursPrice;
}
public function setRowsCoursPrice(?float $rowsCoursPrice): void
{
$this->rowsCoursPrice = $rowsCoursPrice;
}
public function getCoursName(): ?string
{
return $this->coursName;
}
public function setCoursName(?string $coursName): void
{
$this->coursName = $coursName;
}
public function getStudentFirstName(): ?string
{
return $this->studentFirstName;
}
public function setStudentFirstName(?string $studentFirstName): void
{
$this->studentFirstName = $studentFirstName;
}
public function getStudentLastName(): ?string
{
return $this->studentLastName;
}
public function setStudentLastName(?string $studentLastName): void
{
$this->studentLastName = $studentLastName;
}
public function getStudentLevel(): ?string
{
return $this->studentLevel;
}
public function setStudentLevel(?string $studentLevel): void
{
$this->studentLevel = $studentLevel;
}
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 getTrashedAt(): ?\DateTime
{
return $this->trashedAt;
}
public function setTrashedAt(?\DateTime $trashedAt): Trashspayment
{
$this->trashedAt = $trashedAt;
return $this;
}
public function getSuppressor(): User
{
return $this->suppressor;
}
public function setSuppressor(User $suppressor): Trashspayment
{
$this->suppressor = $suppressor;
return $this;
}
public function addItem(Trashspayline $item)
{
$item->setPayment($this);
$this->items->add($item);
return $this;
}
/**
* Remove item
*/
public function removeItem(Trashspayline $item)
{
$this->items->removeElement($item);
}
/**
* Get items
*
* @return Collection
*/
public function getItems()
{
return $this->items;
}
}