src/Entity/Training/Fee.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Training\FeeRepository;
  5. use App\Traits\Actions;
  6. use App\Entity\Training\Fpayline;
  7. use App\Entity\Training\Trainee;
  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(repositoryClassFeeRepository::class)]
  13. #[ORM\Table(name'hs_tc_training_fee')]
  14. #[ApiResource]
  15. class Fee
  16. {
  17.     use Actions;
  18.     #[ORM\ManyToOne(targetEntityTrainee::class, inversedBy"fees")]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?Trainee $trainee 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"training_year"type"string"length255nullabletrue)]
  32.     private ?string $trainingYear 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"fee"targetEntityFpayline::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): Fee
  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): Fee
  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): Fee
  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): Fee
  86.     {
  87.         $this->exempt $exempt;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Trainee
  92.      */
  93.     public function getTrainee(): ?Trainee
  94.     {
  95.         return $this->trainee;
  96.     }
  97.     /**
  98.      * @param Trainee $trainee
  99.      */
  100.     public function setTrainee(?Trainee $trainee): Fee
  101.     {
  102.         $this->trainee $trainee;
  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): Fee
  116.     {
  117.         $this->type $type;
  118.         return $this;
  119.     }
  120.     public function getDisplayType(){
  121.         return match ($this->type) {
  122.             'monthlyPayment' => 'Frais de formation',
  123.             'registerFees' => 'Frais d\'inscription',
  124.             'examFees' => 'Frais d\'examen',
  125.             'diplomaFees' => 'Frais de diplĂ´me',
  126.             default => '',
  127.         };
  128.     }
  129.     /**
  130.      * @return string
  131.      */
  132.     public function getName(): ?string
  133.     {
  134.         return $this->name;
  135.     }
  136.     /**
  137.      * @param string $name
  138.      */
  139.     public function setName(?string $name): Fee
  140.     {
  141.         $this->name $name;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return DateTime
  146.      */
  147.     public function getDatePaie(): ?DateTime
  148.     {
  149.         return $this->datePaie;
  150.     }
  151.     /**
  152.      * @param DateTime $datePaie
  153.      */
  154.     public function setDatePaie(?DateTime $datePaie): Fee
  155.     {
  156.         $this->datePaie $datePaie;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return DateTime
  161.      */
  162.     public function getTerm(): ?DateTime
  163.     {
  164.         return $this->term;
  165.     }
  166.     /**
  167.      * @param DateTime $term
  168.      */
  169.     public function setTerm(?DateTime $term): Fee
  170.     {
  171.         $this->term $term;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return string
  176.      */
  177.     public function getTrainingYear(): ?string
  178.     {
  179.         return $this->trainingYear;
  180.     }
  181.     /**
  182.      * @param string $trainingYear
  183.      */
  184.     public function setTrainingYear(?string $trainingYear): Fee
  185.     {
  186.         $this->trainingYear $trainingYear;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Add item
  191.      *
  192.      *
  193.      * @return Fee
  194.      */
  195.     public function addItem(Fpayline $item)
  196.     {
  197.         $item->setFee($this);
  198.         $this->items[] = $item;
  199.         return $this;
  200.     }
  201.     /**
  202.      * Remove item
  203.      */
  204.     public function removeItem(Fpayline $item)
  205.     {
  206.         $this->items->removeElement($item);
  207.     }
  208.     /**
  209.      * Get items
  210.      *
  211.      * @return Collection
  212.      */
  213.     public function getItems()
  214.     {
  215.         return $this->items;
  216.     }
  217.     public function isNotAbandoned(){
  218.         if($this->trainee->getStatus()=='AbandonnĂ©' && $this->datePaie>$this->trainee->getStatusAt()) return false;
  219.         return true;
  220.     }
  221.     public function isCounted(){
  222.         date_default_timezone_set('Africa/Casablanca');
  223.         $now=new \DateTime('now');
  224.         if($this->datePaie<=$now && $this->isNotAbandoned()) return true;
  225.         return false;
  226.     }
  227.     public function isExpired(){
  228.         date_default_timezone_set('Africa/Casablanca');
  229.         $now=new \DateTime('now');
  230.         if($this->term<$now && $this->isNotAbandoned()) return true;
  231.         return false;
  232.     }
  233.     public function amountPaied(){
  234.         $m=0;
  235.         /** @var Fpayline $item */
  236.         foreach ($this->items as $item){
  237.             $m+=$item->getAmount();
  238.         }
  239.         return $m;
  240.     }
  241.     public function restToPay(){
  242.         return $this->getMontant()-$this->amountPaied();
  243.     }
  244.     public function isPaied(){
  245.         if($this->getMontant()<=$this->amountPaied()) return true;
  246.         return false;
  247.     }
  248.     public function isInProgress(){
  249.         date_default_timezone_set('Africa/Casablanca');
  250.         $now=new \DateTime('now');
  251.         if($this->datePaie<$now) return true;
  252.         return false;
  253.     }
  254.     public function getSchoolyear(){
  255.         foreach ($this->getTrainee()->getGroupe()->getTrainingYears() as $schoolyear){
  256.             if($this->getTrainee()->getGroupe()->getTrainingYear($schoolyear)==$this->getTrainingYear()) return $schoolyear;
  257.         }
  258.         return null;
  259.     }
  260.     public function getRegularAmount(){
  261.         return match ($this->type) {
  262.             'monthlyPayment' => $this->getTrainee()->getGroupe()->getTraining()->getMonthlyPayment(),
  263.             'registerFees' => $this->getTrainee()->getGroupe()->getTraining()->getRegisterFees(),
  264.             'examFees' => $this->getTrainee()->getGroupe()->getTraining()->getExamFees(),
  265.             'diplomaFees' => $this->getTrainee()->getGroupe()->getTraining()->getDiplomaFees(),
  266.             default => 0,
  267.         };
  268.     }
  269.     public function isDiscount(){
  270.         if($this->montant<$this->getRegularAmount()) return true;
  271.         return false;
  272.     }
  273.     public function getPrinterAmount(){
  274.         if($this->getDisplayType()=='Frais de formation') {
  275.             if ($this->trainee->isDiscount()) {
  276.                 return $this->montant;
  277.             } else {
  278.                 return $this->trainee->getGroupe()->getTraining()->getMonthlyPayment();
  279.             }
  280.         }
  281.         else return $this->montant;
  282.     }
  283. }