src/Entity/Formation/Trashapayline.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Formation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Formation\ApaylineRepository;
  5. use App\Entity\Formation\Cost;
  6. use App\Entity\Formation\Trashapayment;
  7. use App\Traits\Actions;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassApaylineRepository::class)]
  10. #[ORM\Table(name'hs_tc_formation_trashapayline')]
  11. #[ApiResource]
  12. class Trashapayline
  13. {
  14.     use Actions;
  15.     #[ORM\ManyToOne(targetEntityTrashapayment::class, inversedBy"items")]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private Trashapayment $payment;
  18.     #[ORM\Column]
  19.     private ?int $costId=null;
  20.     #[ORM\Column(name"amount"type"float")]
  21.     private float $amount;
  22.     public function __construct(Apayline $apayline)
  23.     {
  24.         $this->costId $apayline->getCost()->getId();
  25.         $this->amount $apayline->getAmount();
  26.         $this->published=$apayline->isPublished();
  27.     }
  28.     /**
  29.      * @return Trashapayment
  30.      */
  31.     public function getPayment(): ?Trashapayment
  32.     {
  33.         return $this->payment;
  34.     }
  35.     /**
  36.      * @param Trashapayment $payment
  37.      */
  38.     public function setPayment(?Trashapayment $payment): Trashapayline
  39.     {
  40.         $this->payment $payment;
  41.         return $this;
  42.     }
  43.     public function getCostId(): ?int
  44.     {
  45.         return $this->costId;
  46.     }
  47.     public function setCostId(?int $costId): void
  48.     {
  49.         $this->costId $costId;
  50.     }
  51.     /**
  52.      * Set amount
  53.      *
  54.      * @param float $amount
  55.      *
  56.      * @return Apayline
  57.      */
  58.     public function setAmount($amount)
  59.     {
  60.         $this->amount $amount;
  61.         return $this;
  62.     }
  63.     /**
  64.      * Get amount
  65.      *
  66.      * @return float
  67.      */
  68.     public function getAmount()
  69.     {
  70.         return $this->amount;
  71.     }
  72.     public function getPrinterAmount(){
  73.         if($this->getPayment()->getParticipant()->isDiscount() || !$this->cost->isDiscount()) return $this->amount;
  74.         else{
  75.             return $this->amount*$this->cost->getRegularAmount()/$this->cost->getMontant();
  76.         }
  77.     }
  78.     public function restore(Cost $cost) : Apayline
  79.     {
  80.         $apayline = new Apayline();
  81.         $apayline->setCost($cost);
  82.         $apayline->setAmount($this->getAmount());
  83.         $apayline->setPublished($this->isPublished());
  84.         return $apayline;
  85.     }
  86. }