<?php
namespace App\Entity\Training;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\Training\FpaymentRepository;
use App\Repository\Training\TrashfpaymentRepository;
use App\Traits\Actions;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TrashfpaymentRepository::class)]
#[ORM\Table(name: 'hs_tc_training_trashfpayment')]
#[ApiResource]
class Trashfpayment implements \Stringable
{
use Actions;
#[ORM\Column]
private ?int $traineeId = null;
#[ORM\Column]
private ?int $groupeId = null;
#[ORM\Column]
private ?string $groupeName = null;
#[ORM\Column]
private ?string $traineeFirstName = null;
#[ORM\Column]
private ?string $traineeLastName = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true)]
private User $initie;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true)]
private User $suppressor;
#[ORM\Column(name: "fees", type: "string", length: 255)]
private string $fees;
#[ORM\Column(name: "way", type: "string", length: 255, nullable: true)]
private ?string $way;
#[ORM\Column(name: "amount", type: "float")]
private float $amount;
#[ORM\Column(name: "doc_number", type: "string", length: 255)]
private string $docNumber = '11';
// #[ORM\Column(name: "cached", type: "boolean")]
// private bool $cached;
#[ORM\Column(type: 'string', length: 255)]
private string $moyen;
#[ORM\OneToMany(mappedBy: "payment", targetEntity: Trashfpayline::class, cascade: ["all"], orphanRemoval: true)]
private Collection $items;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $trashedAt = null;
public function __construct(Fpayment $fpayment)
{
// date_default_timezone_set('Africa/Casablanca');
$this->way = $fpayment->getWay();
$this->amount = $fpayment->getAmount();
$this->fees = $fpayment->getFees();
$this->initie = $fpayment->getInitie();
$this->createAt=$fpayment->getCreateAt();
$this->publishedAt=$fpayment->getPublishedAt();
$this->published=$fpayment->isPublished();
$this->traineeId=$fpayment->getTrainee()->getId();
$this->traineeFirstName=$fpayment->getTrainee()->getFirstName();
$this->traineeLastName=$fpayment->getTrainee()->getLastName();
$this->groupeId=$fpayment->getTrainee()->getGroupe()->getId();
$this->groupeName=$fpayment->getTrainee()->getGroupe();
$this->moyen=$fpayment->getMoyen();
$this->trashedAt=new \DateTime('now');
$this->items = new ArrayCollection();
foreach ($fpayment->getItems() as $fpayline) {
$item=new Trashfpayline($fpayline);
$item->setPayment($this);
$this->items->add($item);
}
}
public function restore(Trainee $trainee, array $fees)
{
$fpayment = new Fpayment();
// date_default_timezone_set('Africa/Casablanca');
$fpayment->setWay($this->getWay());
$fpayment->setAmount($this->getAmount());
$fpayment->setFees($this->getFees());
$fpayment->setInitie($this->getInitie());
$fpayment->setCreateAt2($this->getCreateAt());
$fpayment->setPublishedAt($this->publishedAt);
$fpayment->setPublished($this->isPublished());
$fpayment->setTrainee($trainee);
$fpayment->setMoyen($this->getMoyen());
foreach ($fees as $feeItem) {
$fpayline = $feeItem['trashfpayline']->restore($feeItem['fee']);
$fpayment->addItem($fpayline);
}
return $fpayment;
}
/**
* @return string
*/
public function getFees(): ?string
{
return $this->fees;
}
/**
* @param string $fees
*/
public function setFees(?string $fees): Trashfpayment
{
$this->fees = $fees;
return $this;
}
/**
* Set way
*
* @param string $way
*
* @return Trashfpayment
*/
public function setWay($way)
{
$this->way = $way;
return $this;
}
/**
* Get way
*
* @return string
*/
public function getWay()
{
return $this->way;
}
public function getMoyen(): string
{
return $this->moyen;
}
public function setMoyen(string $moyen): Trashfpayment
{
$this->moyen = $moyen;
return $this;
}
/**
* Set amount
*
* @param float $amount
*
* @return Trashfpayment
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* Set docNumber
*
* @param string $docNumber
*
* @return Trashfpayment
*/
public function setDocNumber($docNumber)
{
$this->docNumber = $docNumber;
return $this;
}
/**
* Get docNumber
*
* @return string
*/
public function getDocNumber()
{
return $this->docNumber;
}
public function getTraineeId(): ?int
{
return $this->traineeId;
}
public function setTraineeId(?int $traineeId): void
{
$this->traineeId = $traineeId;
}
public function getGroupeId(): ?int
{
return $this->groupeId;
}
public function setGroupeId(?int $groupeId): void
{
$this->groupeId = $groupeId;
}
public function getGroupeName(): ?string
{
return $this->groupeName;
}
public function setGroupeName(?string $groupeName): void
{
$this->groupeName = $groupeName;
}
public function getTraineeFirstName(): ?string
{
return $this->traineeFirstName;
}
public function setTraineeFirstName(?string $traineeFirstName): void
{
$this->traineeFirstName = $traineeFirstName;
}
public function getTraineeLastName(): ?string
{
return $this->traineeLastName;
}
public function setTraineeLastName(?string $traineeLastName): void
{
$this->traineeLastName = $traineeLastName;
}
/**
* Set initie
*
*
* @return Trashfpayment
*/
public function setInitie(User $initie)
{
$this->initie = $initie;
return $this;
}
/**
* Get initie
*
* @return User
*/
public function getInitie()
{
return $this->initie;
}
/**
* Add item
*
*
* @return Trashfpayment
*/
public function addItem(Trashfpayline $item)
{
$item->setPayment($this);
$this->items->add($item);
return $this;
}
/**
* Remove item
*/
public function removeItem(Trashfpayline $item)
{
$this->items->removeElement($item);
}
/**
* Get items
*
* @return Collection
*/
public function getItems()
{
return $this->items;
}
public function getMonths(){
return $this->way;
}
public function __toString(): string
{
return
'Id:'.$this->id.'<br>'.
'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
'Stagiaire: '.$this->trainee->getCompletName().'<br>'.
'Raison:'.'<br>'.
'Montant: '.$this->getAmount().' DH<br>'
;
}
public function getSuppressor(): User
{
return $this->suppressor;
}
public function setSuppressor(User $suppressor): Trashfpayment
{
$this->suppressor = $suppressor;
return $this;
}
public function getTrashedAt(): ?\DateTime
{
return $this->trashedAt;
}
public function setTrashedAt(?\DateTime $trashedAt): Trashfpayment
{
$this->trashedAt = $trashedAt;
return $this;
}
public function setCreateAt2(\DateTime $dateTime): Trashfpayment
{
$this->createAt=$dateTime;
return $this;
}
}