<?phpnamespace App\Entity\Formation;use ApiPlatform\Core\Annotation\ApiResource;use App\Repository\Formation\ApaylineRepository;use App\Entity\Formation\Cost;use App\Entity\Formation\Apayment;use App\Traits\Actions;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: ApaylineRepository::class)]#[ORM\Table(name: 'hs_tc_formation_apayline')]#[ApiResource]class Apayline{ use Actions; #[ORM\ManyToOne(targetEntity: Apayment::class, inversedBy: "items")] #[ORM\JoinColumn(nullable: false)] private Apayment $payment; #[ORM\ManyToOne(targetEntity: "Cost", inversedBy: "items")] #[ORM\JoinColumn(nullable: true)] private Cost $cost; #[ORM\Column(name: "amount", type: "float")] private float $amount; public function __construct() { // date_default_timezone_set('Africa/Casablanca'); $this->createAt=new \DateTime('now'); $this->published=false; } /** * @return Apayment */ public function getPayment(): ?Apayment { return $this->payment; } /** * @param Apayment $payment */ public function setPayment(?Apayment $payment): Apayline { $this->payment = $payment; return $this; } /** * @return Cost */ public function getCost(): ?Cost { return $this->cost; } /** * @param Cost $cost */ public function setCost(?Cost $cost): Apayline { $this->cost = $cost; return $this; } /** * Set amount * * @param float $amount * * @return Apayline */ public function setAmount($amount) { $this->amount = $amount; return $this; } /** * Get amount * * @return float */ public function getAmount() { return $this->amount; } public function getPrinterAmount(){ if($this->getPayment()->getParticipant()->isDiscount() || !$this->cost->isDiscount()) return $this->amount; else{ return $this->amount*$this->cost->getRegularAmount()/$this->cost->getMontant(); } } public function getLabel() { if($this->getCost()->getDatePaie()>$this->getPayment()->getPublishedAt()){ return "<span class='label label-success' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>"; } elseif($this->getCost()->getTerm()<$this->getPayment()->getPublishedAt()){ return "<span class='label label-danger' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>"; } else{ return "<span class='label label-info' style='margin-left: 5px;'>".$this->getCost()->getDisplayType()." : ".$this->getCost()->getName()." (".number_format($this->getAmount(),2)." DH)"."</span>"; } }}