src/Entity/Formation/Cost.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\CostRepository;
  5. use App\Traits\Actions;
  6. use App\Entity\Formation\Apayline;
  7. use App\Entity\Formation\Participant;
  8. use DateTime;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassCostRepository::class)]
  13. #[ORM\Table(name'hs_tc_formation_cost')]
  14. #[ApiResource]
  15. class Cost
  16. {
  17.     use Actions;
  18.     #[ORM\ManyToOne(targetEntityParticipant::class, inversedBy"costs")]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?Participant $participant null;
  21.     #[ORM\Column(name"montant"type"float"nullabletrue)]
  22.     private ?float $montant null;
  23.     #[ORM\Column(name"initial_amount"type"float"nullabletrue)]
  24.     private ?float $initialAmount null;
  25.     #[ORM\Column(name"displayed_amount"type"float"nullabletrue)]
  26.     private ?float $displayedAmount null;
  27.     #[ORM\Column(name"discount"type"boolean")]
  28.     private bool $exempt=false;
  29.     #[ORM\Column(name"type"type"string"length255nullabletrue)]
  30.     private ?string $type null;
  31.     #[ORM\Column(name"activity_year"type"string"length255nullabletrue)]
  32.     private ?string $activityYear null;
  33.     #[ORM\Column(name"name"type"string"length255nullabletrue)]
  34.     private ?string $name null;
  35.     #[ORM\Column(name"date_paie"type"datetime")]
  36.     private ?\DateTime $datePaie null;
  37.     #[ORM\Column(name"term"type"datetime")]
  38.     private ?\DateTime $term null;
  39.     #[ORM\OneToMany(mappedBy"cost"targetEntityApayline::class, cascade: ["all"], orphanRemovalfalse)]
  40.     private Collection $items;
  41.     public function __construct()
  42.     {
  43.         // date_default_timezone_set('Africa/Casablanca');
  44.         $this->createAt=new \DateTime('now');
  45.         $this->published=false;
  46.         $this->items=new ArrayCollection();
  47.     }
  48.     /**
  49.      * @return float
  50.      */
  51.     public function getMontant(): ?float
  52.     {
  53.         return $this->montant;
  54.     }
  55.     /**
  56.      * @param float $montant
  57.      */
  58.     public function setMontant(?float $montant): Cost
  59.     {
  60.         $this->montant $montant;
  61.         return $this;
  62.     }
  63.     public function getInitialAmount(): ?float
  64.     {
  65.         return $this->initialAmount;
  66.     }
  67.     public function setInitialAmount(?float $initialAmount): Cost
  68.     {
  69.         $this->initialAmount $initialAmount;
  70.         return $this;
  71.     }
  72.     public function getDisplayedAmount(): ?float
  73.     {
  74.         return $this->displayedAmount;
  75.     }
  76.     public function setDisplayedAmount(?float $displayedAmount): Cost
  77.     {
  78.         $this->displayedAmount $displayedAmount;
  79.         return $this;
  80.     }
  81.     public function isExempt(): bool
  82.     {
  83.         return $this->exempt;
  84.     }
  85.     public function setExempt(bool $exempt): Cost
  86.     {
  87.         $this->exempt $exempt;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Participant
  92.      */
  93.     public function getParticipant(): ?Participant
  94.     {
  95.         return $this->participant;
  96.     }
  97.     /**
  98.      * @param Participant $participant
  99.      */
  100.     public function setParticipant(?Participant $participant): Cost
  101.     {
  102.         $this->participant $participant;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return string
  107.      */
  108.     public function getType(): ?string
  109.     {
  110.         return $this->type;
  111.     }
  112.     /**
  113.      * @param string $type
  114.      */
  115.     public function setType(?string $type): Cost
  116.     {
  117.         $this->type $type;
  118.         return $this;
  119.     }
  120.     public function getDisplayType(){
  121.         return match ($this->type) {
  122.             'monthlyPayment' => 'Frais de formation',
  123.             'registerCosts' => 'Frais d\'inscription',
  124.             'examCosts' => 'Frais d\'examen',
  125.             'diplomaCosts' => 'Frais de diplĂ´me',
  126.             'otherCosts' => 'Autre frais',
  127.             default => '',
  128.         };
  129.     }
  130.     /**
  131.      * @return string
  132.      */
  133.     public function getName(): ?string
  134.     {
  135.         return $this->name;
  136.     }
  137.     /**
  138.      * @param string $name
  139.      */
  140.     public function setName(?string $name): Cost
  141.     {
  142.         $this->name $name;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return DateTime
  147.      */
  148.     public function getDatePaie(): ?DateTime
  149.     {
  150.         return $this->datePaie;
  151.     }
  152.     /**
  153.      * @param DateTime $datePaie
  154.      */
  155.     public function setDatePaie(?DateTime $datePaie): Cost
  156.     {
  157.         $this->datePaie $datePaie;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return DateTime
  162.      */
  163.     public function getTerm(): ?DateTime
  164.     {
  165.         return $this->term;
  166.     }
  167.     /**
  168.      * @param DateTime $term
  169.      */
  170.     public function setTerm(?DateTime $term): Cost
  171.     {
  172.         $this->term $term;
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return string
  177.      */
  178.     public function getActivityYear(): ?string
  179.     {
  180.         return $this->activityYear;
  181.     }
  182.     /**
  183.      * @param string $activityYear
  184.      */
  185.     public function setActivityYear(?string $activityYear): Cost
  186.     {
  187.         $this->activityYear $activityYear;
  188.         return $this;
  189.     }
  190.     /**
  191.      * Add item
  192.      *
  193.      *
  194.      * @return Cost
  195.      */
  196.     public function addItem(Apayline $item)
  197.     {
  198.         $item->setCost($this);
  199.         $this->items[] = $item;
  200.         return $this;
  201.     }
  202.     /**
  203.      * Remove item
  204.      */
  205.     public function removeItem(Apayline $item)
  206.     {
  207.         $this->items->removeElement($item);
  208.     }
  209.     /**
  210.      * Get items
  211.      *
  212.      * @return Collection
  213.      */
  214.     public function getItems()
  215.     {
  216.         return $this->items;
  217.     }
  218.     public function isNotAbandoned(){
  219.         if($this->participant->getStatus()=='AbandonnĂ©' && $this->datePaie>$this->participant->getStatusAt()) return false;
  220.         return true;
  221.     }
  222.     public function isCounted(){
  223.         // date_default_timezone_set('Africa/Casablanca');
  224.         $now=new \DateTime('now');
  225.         if($this->datePaie<=$now && $this->isNotAbandoned()) return true;
  226.         return false;
  227.     }
  228.     public function isExpired(){
  229.         // date_default_timezone_set('Africa/Casablanca');
  230.         $now=new \DateTime('now');
  231.         if($this->term<$now && $this->isNotAbandoned()) return true;
  232.         return false;
  233.     }
  234.     public function amountPaied(){
  235.         $m=0;
  236.         /** @var Apayline $item */
  237.         foreach ($this->items as $item){
  238.             $m+=$item->getAmount();
  239.         }
  240.         return $m;
  241.     }
  242.     public function restToPay(){
  243.         return max($this->getMontant()-$this->amountPaied(),0);
  244.     }
  245.     public function advance(){
  246.         return max($this->amountPaied()-$this->getMontant(),0);
  247.     }
  248.     public function isPaied(){
  249.         if($this->getMontant()<=$this->amountPaied()) return true;
  250.         return false;
  251.     }
  252.     public function isInProgress(){
  253.         // date_default_timezone_set('Africa/Casablanca');
  254.         $now=new \DateTime('now');
  255.         if($this->datePaie<$now) return true;
  256.         return false;
  257.     }
  258.     public function getPcPay(){
  259.         if($this->getMontant()!=0)
  260.             return round($this->amountPaied()/$this->getMontant()*100,0);
  261.         else
  262.             return -1;
  263.     }
  264.     public function getSchoolyear(){
  265.         foreach ($this->getParticipant()->getClasse()->getActivityYears() as $schoolyear){
  266.             if($this->getParticipant()->getClasse()->getActivityYear($schoolyear)==$this->getActivityYear()) return $schoolyear;
  267.         }
  268.         return null;
  269.     }
  270.     public function getRegularAmount(){
  271.         return match ($this->type) {
  272.             'monthlyPayment' => $this->getParticipant()->getClasse()->getMonthlyPayment(),
  273.             'registerCosts' => $this->getParticipant()->getClasse()->getRegisterCosts(),
  274.             default => 0,
  275.         };
  276.     }
  277.     public function isDiscount(){
  278.         if($this->montant<$this->getRegularAmount()) return true;
  279.         return false;
  280.     }
  281.     public function getPrinterAmount(){
  282.         if($this->getDisplayType()=='Frais de formation') {
  283.             if ($this->participant->isDiscount()) {
  284.                 return $this->montant;
  285.             } else {
  286.                 return $this->participant->getClasse()->getActivity()->getMonthlyPayment();
  287.             }
  288.         }
  289.         else return $this->montant;
  290.     }
  291. }