src/Entity/Formation/Trashapayment.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Formation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Formation\ApaymentRepository;
  5. use App\Repository\Formation\TrashapaymentRepository;
  6. use App\Traits\Actions;
  7. use App\Entity\User;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\EntityNotFoundException;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassTrashapaymentRepository::class)]
  13. #[ORM\Table(name'hs_tc_formation_trashapayment')]
  14. #[ApiResource]
  15. class Trashapayment implements \Stringable
  16. {
  17.     use Actions;
  18.     #[ORM\Column]
  19.     private ?int $participantId null;
  20.     #[ORM\Column]
  21.     private ?int $classeId null;
  22.     #[ORM\Column]
  23.     private ?string $classeName null;
  24.     #[ORM\Column]
  25.     private ?string $participantFirstName null;
  26.     #[ORM\Column]
  27.     private ?string $participantLastName null;
  28.     #[ORM\ManyToOne(targetEntityUser::class)]
  29.     #[ORM\JoinColumn(nullabletrue)]
  30.     private User $initie;
  31.     #[ORM\ManyToOne(targetEntityUser::class)]
  32.     #[ORM\JoinColumn(nullabletrue)]
  33.     private User $suppressor;
  34.     #[ORM\Column(name"costs"type"string"length255)]
  35.     private string $costs;
  36.     #[ORM\Column(name"way"type"string"length255nullabletrue)]
  37.     private ?string $way;
  38.     #[ORM\Column(name"amount"type"float")]
  39.     private float $amount;
  40.     #[ORM\Column(name"doc_number"type"string"length255)]
  41.     private string $docNumber '11';
  42. //    #[ORM\Column(name: "cached", type: "boolean")]
  43. //    private bool $cached;
  44.     #[ORM\Column(type'string'length255)]
  45.     private string $moyen;
  46.     #[ORM\OneToMany(mappedBy"payment"targetEntityTrashapayline::class, cascade: ["all"], orphanRemovaltrue)]
  47.     private Collection $items;
  48.     #[ORM\Column(type'datetime'nullabletrue)]
  49.     private ?\DateTime $trashedAt null;
  50.     public function __construct(Apayment $apayment)
  51.     {
  52.         // date_default_timezone_set('Africa/Casablanca');
  53.         $this->way $apayment->getWay();
  54.         $this->amount $apayment->getAmount();
  55.         $this->costs $apayment->getCosts();
  56.         $this->initie $apayment->getInitie();
  57.         $this->createAt=$apayment->getCreateAt();
  58.         $this->publishedAt=$apayment->getPublishedAt();
  59.         $this->published=$apayment->isPublished();
  60.         $this->participantId=$apayment->getParticipant()->getId();
  61.         $this->participantFirstName=$apayment->getParticipant()->getFirstName();
  62.         $this->participantLastName=$apayment->getParticipant()->getLastName();
  63.         $this->classeId=$apayment->getParticipant()->getClasse()->getId();
  64.         $this->classeName=$apayment->getParticipant()->getClasse();
  65.         $this->moyen=$apayment->getMoyen();
  66.         $this->trashedAt=new \DateTime('now');
  67.         $this->items = new ArrayCollection();
  68.         foreach ($apayment->getItems() as $apayline) {
  69.             $item=new Trashapayline($apayline);
  70.             $item->setPayment($this);
  71.             $this->items->add($item);
  72.         }
  73.     }
  74.     public function restore(Participant $participant, array $costs)
  75.     {
  76.         $apayment = new Apayment();
  77.         // date_default_timezone_set('Africa/Casablanca');
  78.         $apayment->setWay($this->getWay());
  79.         $apayment->setAmount($this->getAmount());
  80.         $apayment->setCosts($this->getCosts());
  81.         $apayment->setInitie($this->getInitie());
  82.         $apayment->setCreateAt2($this->getCreateAt());
  83.         $apayment->setPublishedAt($this->publishedAt);
  84.         $apayment->setPublished($this->isPublished());
  85.         $apayment->setParticipant($participant);
  86.         $apayment->setMoyen($this->getMoyen());
  87.         foreach ($costs as $costItem) {
  88.             $apayline $costItem['trashapayline']->restore($costItem['cost']);
  89.             $apayment->addItem($apayline);
  90.         }
  91.         return $apayment;
  92.     }
  93.     /**
  94.      * @return string
  95.      */
  96.     public function getCosts(): ?string
  97.     {
  98.         return $this->costs;
  99.     }
  100.     /**
  101.      * @param string $costs
  102.      */
  103.     public function setCosts(?string $costs): Trashapayment
  104.     {
  105.         $this->costs $costs;
  106.         return $this;
  107.     }
  108.     /**
  109.      * Set way
  110.      *
  111.      * @param string $way
  112.      *
  113.      * @return Trashapayment
  114.      */
  115.     public function setWay($way)
  116.     {
  117.         $this->way $way;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Get way
  122.      *
  123.      * @return string
  124.      */
  125.     public function getWay()
  126.     {
  127.         return $this->way;
  128.     }
  129.     public function getMoyen(): string
  130.     {
  131.         return $this->moyen;
  132.     }
  133.     public function setMoyen(string $moyen): Trashapayment
  134.     {
  135.         $this->moyen $moyen;
  136.         return $this;
  137.     }
  138.     /**
  139.      * Set amount
  140.      *
  141.      * @param float $amount
  142.      *
  143.      * @return Trashapayment
  144.      */
  145.     public function setAmount($amount)
  146.     {
  147.         $this->amount $amount;
  148.         return $this;
  149.     }
  150.     /**
  151.      * Get amount
  152.      *
  153.      * @return float
  154.      */
  155.     public function getAmount()
  156.     {
  157.         return $this->amount;
  158.     }
  159.     /**
  160.      * Set docNumber
  161.      *
  162.      * @param string $docNumber
  163.      *
  164.      * @return Trashapayment
  165.      */
  166.     public function setDocNumber($docNumber)
  167.     {
  168.         $this->docNumber $docNumber;
  169.         return $this;
  170.     }
  171.     /**
  172.      * Get docNumber
  173.      *
  174.      * @return string
  175.      */
  176.     public function getDocNumber()
  177.     {
  178.         return $this->docNumber;
  179.     }
  180.     public function getParticipantId(): ?int
  181.     {
  182.         return $this->participantId;
  183.     }
  184.     public function setParticipantId(?int $participantId): void
  185.     {
  186.         $this->participantId $participantId;
  187.     }
  188.     public function getClasseId(): ?int
  189.     {
  190.         return $this->classeId;
  191.     }
  192.     public function setClasseId(?int $classeId): void
  193.     {
  194.         $this->classeId $classeId;
  195.     }
  196.     public function getClasseName(): ?string
  197.     {
  198.         return $this->classeName;
  199.     }
  200.     public function setClasseName(?string $classeName): void
  201.     {
  202.         $this->classeName $classeName;
  203.     }
  204.     public function getParticipantFirstName(): ?string
  205.     {
  206.         return $this->participantFirstName;
  207.     }
  208.     public function setParticipantFirstName(?string $participantFirstName): void
  209.     {
  210.         $this->participantFirstName $participantFirstName;
  211.     }
  212.     public function getParticipantLastName(): ?string
  213.     {
  214.         return $this->participantLastName;
  215.     }
  216.     public function setParticipantLastName(?string $participantLastName): void
  217.     {
  218.         $this->participantLastName $participantLastName;
  219.     }
  220.     /**
  221.      * Set initie
  222.      *
  223.      *
  224.      * @return Trashapayment
  225.      */
  226.     public function setInitie(User $initie)
  227.     {
  228.         $this->initie $initie;
  229.         return $this;
  230.     }
  231.     /**
  232.      * Get initie
  233.      *
  234.      * @return User
  235.      */
  236.     public function getInitie()
  237.     {
  238.         return $this->initie;
  239.     }
  240.     /**
  241.      * Add item
  242.      *
  243.      *
  244.      * @return Trashapayment
  245.      */
  246.     public function addItem(Trashapayline $item)
  247.     {
  248.         $item->setPayment($this);
  249.         $this->items->add($item);
  250.         return $this;
  251.     }
  252.     /**
  253.      * Remove item
  254.      */
  255.     public function removeItem(Trashapayline $item)
  256.     {
  257.         $this->items->removeElement($item);
  258.     }
  259.     /**
  260.      * Get items
  261.      *
  262.      * @return Collection
  263.      */
  264.     public function getItems()
  265.     {
  266.         return $this->items;
  267.     }
  268.     public function getMonths(){
  269.         return $this->way;
  270.     }
  271.     public function __toString(): string
  272.     {
  273.         return
  274.             'Id:'.$this->id.'<br>'.
  275.             'Date:'.$this->getCreateAt()->format('d-m-Y').'<br>'.
  276.             'Stagiaire: '.$this->participant->getCompletName().'<br>'.
  277.             'Raison:'.'<br>'.
  278.             'Montant: '.$this->getAmount().' DH<br>'
  279.             ;
  280.     }
  281.     public function getSuppressor(): User
  282.     {
  283.         return $this->suppressor;
  284.     }
  285.     public function setSuppressor(User $suppressor): Trashapayment
  286.     {
  287.         $this->suppressor $suppressor;
  288.         return $this;
  289.     }
  290.     public function getTrashedAt(): ?\DateTime
  291.     {
  292.         return $this->trashedAt;
  293.     }
  294.     public function setTrashedAt(?\DateTime $trashedAt): Trashapayment
  295.     {
  296.         $this->trashedAt $trashedAt;
  297.         return $this;
  298.     }
  299.     public function setCreateAt2(\DateTime $dateTime): Trashapayment
  300.     {
  301.         $this->createAt=$dateTime;
  302.         return $this;
  303.     }
  304.     public function getParticipantName(): ?string
  305.     {
  306.         return $this->getParticipantLastName().' '.$this->getParticipantFirstName();
  307.     }
  308. }