<?php
namespace App\Entity;
use App\Repository\RecurringDonationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RecurringDonationRepository::class)]
class RecurringDonation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $frequency;
#[ORM\Column(type: 'datetime', nullable: true)]
private $nextPaymentDate;
#[ORM\Column(type: 'integer', nullable: true)]
private $currentPaymentCount;
#[ORM\Column(type: 'integer', nullable: true)]
private $totalPaymentCount;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cardId;
#[ORM\OneToMany(mappedBy: 'recurringDonation', targetEntity: Donation::class)]
private $donations;
#[ORM\Column(nullable: true)]
private ?bool $isCancel = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startPaymentDate = null;
public function __construct()
{
$this->orderDetails = new ArrayCollection();
$this->donations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFrequency(): ?string
{
return $this->frequency;
}
public function setFrequency(?string $frequency): self
{
$this->frequency = $frequency;
return $this;
}
public function getNextPaymentDate(): ?\DateTimeInterface
{
return $this->nextPaymentDate;
}
public function setNextPaymentDate(?\DateTimeInterface $nextPaymentDate): self
{
$this->nextPaymentDate = $nextPaymentDate;
return $this;
}
public function getCurrentPaymentCount(): ?int
{
return $this->currentPaymentCount;
}
public function setCurrentPaymentCount(?int $currentPaymentCount): self
{
$this->currentPaymentCount = $currentPaymentCount;
return $this;
}
public function getTotalPaymentCount(): ?int
{
return $this->totalPaymentCount;
}
public function setTotalPaymentCount(?int $totalPaymentCount): self
{
$this->totalPaymentCount = $totalPaymentCount;
return $this;
}
public function getCardId(): ?string
{
return $this->cardId;
}
public function setCardId(?string $cardId): self
{
$this->cardId = $cardId;
return $this;
}
/**
* @return Collection<int, Donation>
*/
public function getDonations(): Collection
{
return $this->donations;
}
public function addDonation(Donation $donation): self
{
if (!$this->donations->contains($donation)) {
$this->donations[] = $donation;
$donation->setRecurringDonation($this);
}
return $this;
}
public function removeDonation(Donation $donation): self
{
if ($this->donations->removeElement($donation)) {
// set the owning side to null (unless already changed)
if ($donation->getRecurringDonation() === $this) {
$donation->setRecurringDonation(null);
}
}
return $this;
}
public function getFirstDonation()
{
$firstDonation = null;
if ($this->donations) {
$firstDonation = $this->donations[0];
}
return $firstDonation;
}
public function getLastDonation()
{
$firstDonation = null;
if ($this->donations) {
$firstDonation = $this->donations[0];
}
return $firstDonation;
}
public function getEndDate()
{
$endDate = null;
if ($this->donations) {
$firstDonation = $this->donations[0];
$startDate = null;
if (!$firstDonation) {
$startDate = $this->startPaymentDate;
} else {
$startDate = \DateTime::createFromInterface($firstDonation->getModifiedAt());
}
$incrementString = '+'. ($this->totalPaymentCount - 1) .' Months';
$endDate = $startDate->modify($incrementString);
// $endDate = date('Y-m-d', strtotime($incrementString, $startDate));
}
return $endDate;
}
public function getPaymentCount()
{
return $this->currentPaymentCount .'/'. $this->totalPaymentCount;
}
public function isIsCancel(): ?bool
{
return $this->isCancel;
}
public function setIsCancel(?bool $isCancel): static
{
$this->isCancel = $isCancel;
return $this;
}
public function getStartPaymentDate(): ?\DateTimeInterface
{
return $this->startPaymentDate;
}
public function setStartPaymentDate(?\DateTimeInterface $startPaymentDate): static
{
$this->startPaymentDate = $startPaymentDate;
return $this;
}
}