src/Entity/Tutoring/Trashspayment.php line 21

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\Repository\Tutoring\TrashspaymentRepository;
  8. use App\Traits\Actions;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * Spayment
  14.  */
  15. #[ORM\Entity(repositoryClassTrashspaymentRepository::class)]
  16. #[ORM\Table(name'hs_tc_tutoring_trashspayment')]
  17. #[ApiResource]
  18. class Trashspayment implements \Stringable
  19. {
  20.     use Actions;
  21.     #[ORM\Column]
  22.     private ?int $rowsCoursId null;
  23.     #[ORM\Column]
  24.     private ?int $coursId null;
  25.     #[ORM\Column]
  26.     private ?int $studentId null;
  27.     #[ORM\Column]
  28.     private ?float $rowsCoursPrice null;
  29.     #[ORM\Column]
  30.     private ?string $coursName null;
  31.     #[ORM\Column]
  32.     private ?string $studentFirstName null;
  33.     #[ORM\Column]
  34.     private ?string $studentLastName null;
  35.     #[ORM\Column]
  36.     private ?string $studentLevel null;
  37.     #[ORM\ManyToOne(targetEntityUser::class)]
  38.     #[ORM\JoinColumn(nullabletrue)]
  39.     private ?User $initie null;
  40.     #[ORM\ManyToOne(targetEntityUser::class)]
  41.     #[ORM\JoinColumn(nullabletrue)]
  42.     private User $suppressor;
  43.     /**
  44.      * @var string
  45.      */
  46.     #[ORM\Column(name'way'type'string'length255)]
  47.     private $way;
  48.     /**
  49.      * @var float
  50.      */
  51.     #[ORM\Column(name'amount'type'float')]
  52.     private $amount;
  53.     #[ORM\Column(type'string'length255)]
  54.     private string $moyen;
  55.     #[ORM\Column(name'doc_number'type'string'length255)]
  56.     private string $docNumber '11';
  57.     #[ORM\Column(name'cached'type'boolean')]
  58.     private bool $cached false;
  59.     #[ORM\OneToMany(mappedBy"payment"targetEntityTrashspayline::class, cascade: ["all"], orphanRemovaltrue)]
  60.     private Collection $items;
  61.     #[ORM\Column(type'datetime'nullabletrue)]
  62.     private ?\DateTime $trashedAt null;
  63.     /**
  64.      * Spayment constructor.
  65.      */
  66.     public function __construct(Spayment $spayment)
  67.     {
  68.         
  69.         $this->rowsCoursId=$spayment->getRowscourse()->getId();
  70.         $this->coursId=$spayment->getRowscourse()->getCourse()->getId(); //this
  71.         $this->studentId=$spayment->getRowscourse()->getStudent()->getId();
  72.         $this->rowsCoursPrice=$spayment->getRowscourse()->getPrice();
  73.         $this->coursName=$spayment->getRowscourse()->getCourse()->getName();
  74.         $this->studentFirstName=$spayment->getRowscourse()->getStudent()->getFirstName();
  75.         $this->studentLastName=$spayment->getRowscourse()->getStudent()->getLastName();
  76.         $this->studentLevel=$spayment->getRowscourse()->getStudent()->getLevel();
  77.         $this->publishedAt=$spayment->getPublishedAt();
  78.         $this->published=$spayment->isPublished();
  79.         $this->createAt=$spayment->getCreateAt();
  80.         $this->initie=$spayment->getInitie();
  81.         $this->way=$spayment->getWay();
  82.         $this->amount=$spayment->getAmount();
  83.         $this->docNumber=$spayment->getDocNumber();
  84.         $this->cached=$spayment->isCached();
  85.         $this->moyen=$spayment->getMoyen();
  86.         $this->trashedAt=new \DateTime('now');
  87.         $this->items = new ArrayCollection();
  88.         foreach ($spayment->getItems() as $spayline) {
  89.             $item=new Trashspayline($spayline);
  90.             $item->setPayment($this);
  91.             $this->items->add($item);
  92.         }
  93.     }
  94.     public function restore(Rowscourse $rowscourse, array $owes)
  95.     {
  96.         $spayment = new Spayment();
  97.         $spayment->setPublishedAt($this->publishedAt);
  98.         $spayment->setCreateAt2($this->createAt);
  99.         $spayment->setPublished($this->published);
  100.         $spayment->setRowscourse($rowscourse);
  101.         $spayment->setInitie($this->initie);
  102.         $spayment->setWay($this->way);
  103.         $spayment->setAmount($this->amount);
  104.         $spayment->setDocNumber($this->docNumber);
  105.         $spayment->setCached($this->cached);
  106.         $spayment->setMoyen($this->moyen);
  107.         foreach ($owes as $oweItem) {
  108.             $fpayline $oweItem['trashspayline']->restore($oweItem['owe']);
  109.             $spayment->addItem($fpayline);
  110.         }
  111.         return $spayment;
  112.     }
  113.     public function setWay($way)
  114.     {
  115.         $this->way $way;
  116.         return $this;
  117.     }
  118.     /**
  119.      * Get way
  120.      *
  121.      * @return string
  122.      */
  123.     public function getWay()
  124.     {
  125.         return $this->way;
  126.     }
  127.     public function setAmount($amount)
  128.     {
  129.         $this->amount $amount;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Get amount
  134.      *
  135.      * @return float
  136.      */
  137.     public function getAmount()
  138.     {
  139.         return $this->amount;
  140.     }
  141.     public function setDocNumber($docNumber)
  142.     {
  143.         $this->docNumber $docNumber;
  144.         return $this;
  145.     }
  146.     /**
  147.      * Get docNumber
  148.      *
  149.      * @return string
  150.      */
  151.     public function getDocNumber()
  152.     {
  153.         return $this->docNumber;
  154.     }
  155.     public function getMoyen(): string
  156.     {
  157.         return $this->moyen;
  158.     }
  159.     public function setMoyen(string $moyen): Trashspayment
  160.     {
  161.         $this->moyen $moyen;
  162.         return $this;
  163.     }
  164.     public function setCached($cached)
  165.     {
  166.         $this->cached $cached;
  167.         return $this;
  168.     }
  169.     /**
  170.      * Get cached
  171.      *
  172.      * @return bool
  173.      */
  174.     public function getCached()
  175.     {
  176.         return $this->cached;
  177.     }
  178.     public function getRowsCoursId(): ?int
  179.     {
  180.         return $this->rowsCoursId;
  181.     }
  182.     public function setRowsCoursId(?int $rowsCoursId): void
  183.     {
  184.         $this->rowsCoursId $rowsCoursId;
  185.     }
  186.     public function getCoursId(): ?int
  187.     {
  188.         return $this->coursId;
  189.     }
  190.     public function setCoursId(?int $coursId): void
  191.     {
  192.         $this->coursId $coursId;
  193.     }
  194.     public function getStudentId(): ?int
  195.     {
  196.         return $this->studentId;
  197.     }
  198.     public function setStudentId(?int $studentId): void
  199.     {
  200.         $this->studentId $studentId;
  201.     }
  202.     public function getRowsCoursPrice(): ?float
  203.     {
  204.         return $this->rowsCoursPrice;
  205.     }
  206.     public function setRowsCoursPrice(?float $rowsCoursPrice): void
  207.     {
  208.         $this->rowsCoursPrice $rowsCoursPrice;
  209.     }
  210.     public function getCoursName(): ?string
  211.     {
  212.         return $this->coursName;
  213.     }
  214.     public function setCoursName(?string $coursName): void
  215.     {
  216.         $this->coursName $coursName;
  217.     }
  218.     public function getStudentFirstName(): ?string
  219.     {
  220.         return $this->studentFirstName;
  221.     }
  222.     public function setStudentFirstName(?string $studentFirstName): void
  223.     {
  224.         $this->studentFirstName $studentFirstName;
  225.     }
  226.     public function getStudentLastName(): ?string
  227.     {
  228.         return $this->studentLastName;
  229.     }
  230.     public function setStudentLastName(?string $studentLastName): void
  231.     {
  232.         $this->studentLastName $studentLastName;
  233.     }
  234.     public function getStudentLevel(): ?string
  235.     {
  236.         return $this->studentLevel;
  237.     }
  238.     public function setStudentLevel(?string $studentLevel): void
  239.     {
  240.         $this->studentLevel $studentLevel;
  241.     }
  242.     public function setInitie(User $initie)
  243.     {
  244.         $this->initie $initie;
  245.         return $this;
  246.     }
  247.     /**
  248.      * Get initie
  249.      *
  250.      * @return User
  251.      */
  252.     public function getInitie()
  253.     {
  254.         return $this->initie;
  255.     }
  256.     public function getPrevious(){
  257.         $items=[];
  258.         /** @var Spayment $payment */
  259.         foreach ($this->getRowscourse()->getPayments() as $payment){
  260.             if($payment->getCreateAt()<=$this->getCreateAt() && $payment->getId()<$this->getId()){
  261.                 $items[]=$payment;
  262.             }
  263.         }
  264.         return $items;
  265.     }
  266.     public function getSumPrevious(){
  267.         $s=0;
  268.         /** @var Spayment $pay */
  269.         foreach ($this->getPrevious() as $pay){
  270.             $s+=$pay->getAmount();
  271.         }
  272.         return $s;
  273.     }
  274.     public function getMonths(){
  275.         return $this->way;
  276.     }
  277.     public function __toString(): string
  278.     {
  279.         $rason=$this->rowscourse->getCourse()==null?$this->rowscourse->getSubject():$this->rowscourse->getCourse();
  280.         return
  281.             'Id:'.$this->id.'<br>'.
  282.             'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
  283.             'Eleve: '.$this->rowscourse->getStudent()->getNameComplet().'<br>'.
  284.             'Raison:'.$rason.'<br>'.
  285.             'Montant: '.$this->getAmount().' DH<br>'
  286.             ;
  287.     }
  288.     public function getTrashedAt(): ?\DateTime
  289.     {
  290.         return $this->trashedAt;
  291.     }
  292.     public function setTrashedAt(?\DateTime $trashedAt): Trashspayment
  293.     {
  294.         $this->trashedAt $trashedAt;
  295.         return $this;
  296.     }
  297.     public function getSuppressor(): User
  298.     {
  299.         return $this->suppressor;
  300.     }
  301.     public function setSuppressor(User $suppressor): Trashspayment
  302.     {
  303.         $this->suppressor $suppressor;
  304.         return $this;
  305.     }
  306.     public function addItem(Trashspayline $item)
  307.     {
  308.         $item->setPayment($this);
  309.         $this->items->add($item);
  310.         return $this;
  311.     }
  312.     /**
  313.      * Remove item
  314.      */
  315.     public function removeItem(Trashspayline $item)
  316.     {
  317.         $this->items->removeElement($item);
  318.     }
  319.     /**
  320.      * Get items
  321.      *
  322.      * @return Collection
  323.      */
  324.     public function getItems()
  325.     {
  326.         return $this->items;
  327.     }
  328. }