src/Entity/AggregatedTrueUp.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AggregatedTrueUpRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. #[ORM\Entity(repositoryClassAggregatedTrueUpRepository::class)]
  10. class AggregatedTrueUp
  11. {
  12.     use TimestampableEntity;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\OneToMany(mappedBy'aggregatedTrueUp'targetEntityTrueUp::class)]
  18.     private Collection $trueUps;
  19.     #[ORM\OneToOne(inversedBy'aggregatedTrueUp'cascade: ['persist''remove'])]
  20.     private ?ManualPayment $manualPayment null;
  21.     #[ORM\ManyToOne(inversedBy'aggregatedTrueUps')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?User $user null;
  24.     public function __construct()
  25.     {
  26.         $this->trueUps = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getUser(): ?User
  33.     {
  34.         return $this->user;
  35.     }
  36.     public function setUser(?User $user): self
  37.     {
  38.         $this->user $user;
  39.         return $this;
  40.     }
  41.     public function getAmtInPennies(): ?int
  42.     {
  43.         return array_sum(array_map(fn($x) => round($x->getAmtInPennies(), 2), $this->trueUps->toArray()));
  44.     }
  45.     /**
  46.      * @return Collection<int, TrueUp>
  47.      */
  48.     public function getTrueUps(): Collection
  49.     {
  50.         return $this->trueUps;
  51.     }
  52.     public function addTrueUp(TrueUp $trueUp): self
  53.     {
  54.         if (!$this->trueUps->contains($trueUp)) {
  55.             $this->trueUps->add($trueUp);
  56.             $trueUp->setAggregatedTrueUp($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeTrueUp(TrueUp $trueUp): self
  61.     {
  62.         if ($this->trueUps->removeElement($trueUp)) {
  63.             // set the owning side to null (unless already changed)
  64.             if ($trueUp->getAggregatedTrueUp() === $this) {
  65.                 $trueUp->setAggregatedTrueUp(null);
  66.             }
  67.         }
  68.         return $this;
  69.     }
  70.     public function getManualPayment(): ?ManualPayment
  71.     {
  72.         return $this->manualPayment;
  73.     }
  74.     public function setManualPayment(?ManualPayment $manualPayment): self
  75.     {
  76.         $this->manualPayment $manualPayment;
  77.         return $this;
  78.     }
  79.     public function __toString()
  80.     {
  81.         return $this->user->getFullName() . ' - ' round(($this->getAmtInPennies() - (float) $this->getManualPayment()?->getAmtInPennies()) / 100.002);
  82.     }
  83. }