src/Entity/Formation/Apayline.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\Apayment;
  7. use App\Traits\Actions;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassApaylineRepository::class)]
  10. #[ORM\Table(name'hs_tc_formation_apayline')]
  11. #[ApiResource]
  12. class Apayline
  13. {
  14.     use Actions;
  15.     #[ORM\ManyToOne(targetEntityApayment::class, inversedBy"items")]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private Apayment $payment;
  18.     #[ORM\ManyToOne(targetEntity"Cost"inversedBy"items")]
  19.     #[ORM\JoinColumn(nullabletrue)]
  20.     private Cost $cost;
  21.     #[ORM\Column(name"amount"type"float")]
  22.     private float $amount;
  23.     public function __construct()
  24.     {
  25.         // date_default_timezone_set('Africa/Casablanca');
  26.         $this->createAt=new \DateTime('now');
  27.         $this->published=false;
  28.     }
  29.     /**
  30.      * @return Apayment
  31.      */
  32.     public function getPayment(): ?Apayment
  33.     {
  34.         return $this->payment;
  35.     }
  36.     /**
  37.      * @param Apayment $payment
  38.      */
  39.     public function setPayment(?Apayment $payment): Apayline
  40.     {
  41.         $this->payment $payment;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return Cost
  46.      */
  47.     public function getCost(): ?Cost
  48.     {
  49.         return $this->cost;
  50.     }
  51.     /**
  52.      * @param Cost $cost
  53.      */
  54.     public function setCost(?Cost $cost): Apayline
  55.     {
  56.         $this->cost $cost;
  57.         return $this;
  58.     }
  59.     /**
  60.      * Set amount
  61.      *
  62.      * @param float $amount
  63.      *
  64.      * @return Apayline
  65.      */
  66.     public function setAmount($amount)
  67.     {
  68.         $this->amount $amount;
  69.         return $this;
  70.     }
  71.     /**
  72.      * Get amount
  73.      *
  74.      * @return float
  75.      */
  76.     public function getAmount()
  77.     {
  78.         return $this->amount;
  79.     }
  80.     public function getPrinterAmount(){
  81.         if($this->getPayment()->getParticipant()->isDiscount() || !$this->cost->isDiscount()) return $this->amount;
  82.         else{
  83.             return $this->amount*$this->cost->getRegularAmount()/$this->cost->getMontant();
  84.         }
  85.     }
  86.     public function getLabel()
  87.     {
  88.         if($this->getCost()->getDatePaie()>$this->getPayment()->getPublishedAt()){
  89.             return "<span class='label label-success' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>";
  90.         }
  91.         elseif($this->getCost()->getTerm()<$this->getPayment()->getPublishedAt()){
  92.             return "<span class='label label-danger' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>";
  93.         }
  94.         else{
  95.             return "<span class='label label-info' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>";
  96.         }
  97.     }
  98. }