src/Entity/RecurringDonation.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RecurringDonationRepository;
  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. #[ORM\Entity(repositoryClassRecurringDonationRepository::class)]
  9. class RecurringDonation
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[ORM\Column(type'string'length255nullabletrue)]
  16.     private $frequency;
  17.     #[ORM\Column(type'datetime'nullabletrue)]
  18.     private $nextPaymentDate;
  19.     #[ORM\Column(type'integer'nullabletrue)]
  20.     private $currentPaymentCount;
  21.     #[ORM\Column(type'integer'nullabletrue)]
  22.     private $totalPaymentCount;
  23.     #[ORM\Column(type'string'length255nullabletrue)]
  24.     private $cardId;
  25.     #[ORM\OneToMany(mappedBy'recurringDonation'targetEntityDonation::class)]
  26.     private $donations;
  27.     #[ORM\Column(nullabletrue)]
  28.     private ?bool $isCancel null;
  29.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  30.     private ?\DateTimeInterface $startPaymentDate null;
  31.     public function __construct()
  32.     {
  33.         $this->orderDetails = new ArrayCollection();
  34.         $this->donations = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getFrequency(): ?string
  41.     {
  42.         return $this->frequency;
  43.     }
  44.     public function setFrequency(?string $frequency): self
  45.     {
  46.         $this->frequency $frequency;
  47.         return $this;
  48.     }
  49.     public function getNextPaymentDate(): ?\DateTimeInterface
  50.     {
  51.         return $this->nextPaymentDate;
  52.     }
  53.     public function setNextPaymentDate(?\DateTimeInterface $nextPaymentDate): self
  54.     {
  55.         $this->nextPaymentDate $nextPaymentDate;
  56.         return $this;
  57.     }
  58.     public function getCurrentPaymentCount(): ?int
  59.     {
  60.         return $this->currentPaymentCount;
  61.     }
  62.     public function setCurrentPaymentCount(?int $currentPaymentCount): self
  63.     {
  64.         $this->currentPaymentCount $currentPaymentCount;
  65.         return $this;
  66.     }
  67.     public function getTotalPaymentCount(): ?int
  68.     {
  69.         return $this->totalPaymentCount;
  70.     }
  71.     public function setTotalPaymentCount(?int $totalPaymentCount): self
  72.     {
  73.         $this->totalPaymentCount $totalPaymentCount;
  74.         return $this;
  75.     }
  76.     public function getCardId(): ?string
  77.     {
  78.         return $this->cardId;
  79.     }
  80.     public function setCardId(?string $cardId): self
  81.     {
  82.         $this->cardId $cardId;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection<int, Donation>
  87.      */
  88.     public function getDonations(): Collection
  89.     {
  90.         return $this->donations;
  91.     }
  92.     public function addDonation(Donation $donation): self
  93.     {
  94.         if (!$this->donations->contains($donation)) {
  95.             $this->donations[] = $donation;
  96.             $donation->setRecurringDonation($this);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeDonation(Donation $donation): self
  101.     {
  102.         if ($this->donations->removeElement($donation)) {
  103.             // set the owning side to null (unless already changed)
  104.             if ($donation->getRecurringDonation() === $this) {
  105.                 $donation->setRecurringDonation(null);
  106.             }
  107.         }
  108.         return $this;
  109.     }
  110.     public function getFirstDonation()
  111.     {
  112.         $firstDonation null;
  113.         if ($this->donations) {
  114.             $firstDonation $this->donations[0];
  115.         }
  116.         return $firstDonation;
  117.     }
  118.     public function getLastDonation()
  119.     {
  120.         $firstDonation null;
  121.         if ($this->donations) {
  122.             $firstDonation $this->donations[0];
  123.         }
  124.         return $firstDonation;
  125.     }
  126.     
  127.     public function getEndDate()
  128.     {
  129.         $endDate null;
  130.         if ($this->donations) {
  131.             $firstDonation $this->donations[0];
  132.             $startDate null;
  133.             if (!$firstDonation) {
  134.                 $startDate $this->startPaymentDate;
  135.             } else {
  136.                 $startDate \DateTime::createFromInterface($firstDonation->getModifiedAt());
  137.             }
  138.             $incrementString '+'. ($this->totalPaymentCount 1) .' Months';
  139.             $endDate $startDate->modify($incrementString);
  140.             // $endDate = date('Y-m-d', strtotime($incrementString, $startDate));
  141.         }
  142.         return $endDate;
  143.     }
  144.     public function getPaymentCount()
  145.     {
  146.         return $this->currentPaymentCount .'/'$this->totalPaymentCount;
  147.     }
  148.     public function isIsCancel(): ?bool
  149.     {
  150.         return $this->isCancel;
  151.     }
  152.     public function setIsCancel(?bool $isCancel): static
  153.     {
  154.         $this->isCancel $isCancel;
  155.         return $this;
  156.     }
  157.     public function getStartPaymentDate(): ?\DateTimeInterface
  158.     {
  159.         return $this->startPaymentDate;
  160.     }
  161.     public function setStartPaymentDate(?\DateTimeInterface $startPaymentDate): static
  162.     {
  163.         $this->startPaymentDate $startPaymentDate;
  164.         return $this;
  165.     }
  166. }