diff --git a/migrations/Version20241117160044.php b/migrations/Version20241117160044.php new file mode 100644 index 0000000..73b047f --- /dev/null +++ b/migrations/Version20241117160044.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE admin_member CHANGE contribution_period contribution_period INT DEFAULT 1 NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE admin_member CHANGE contribution_period contribution_period INT DEFAULT 2 NOT NULL'); + } +} diff --git a/src/Entity/Member.php b/src/Entity/Member.php index 65108a8..507ecc6 100644 --- a/src/Entity/Member.php +++ b/src/Entity/Member.php @@ -123,9 +123,9 @@ class Member implements UserInterface { private bool $createSubscriptionAfterPayment = false; /** - * @ORM\Column(type="integer", options={"default": 2}) + * @ORM\Column(type="integer", options={"default": 1}) */ - private int $contributionPeriod = self::PERIOD_ANNUALLY; + private int $contributionPeriod = self::PERIOD_QUARTERLY; /** * @ORM\Column(type="integer", options={"default": 500}) @@ -264,20 +264,20 @@ public function setIsAdmin(bool $isAdmin): void { } public function isContributionCompleted(DateTime $when) { - $year = $when->format('Y'); - $month = $when->format('n'); switch ($this->getContributionPeriod()) { case self::PERIOD_MONTHLY: - $payments = $this->contributionPayments->filter(fn($payment) => $payment->getPeriodYear() == $year && $payment->getPeriodMonthStart() == $month); + $when->modify('-1 month'); break; case self::PERIOD_QUARTERLY: $when->modify('-3 months'); - $payments = $this->contributionPayments->filter(fn($payment) => $payment->getPaymentTime() >= $when); break; case self::PERIOD_ANNUALLY: - $payments = $this->contributionPayments->filter(fn($payment) => $payment->getPeriodYear() == $year); + $when->modify('-12 months'); break; + default; + throw new \Exception('Period must be PERIOD_MONTHLY, PERIOD_QUARTERLY or PERIOD_ANNUALLY'); } + $payments = $this->contributionPayments->filter(fn($payment) => $payment->getPaymentTime() >= $when); $payments = $payments->filter(fn($payment) => $payment->getStatus() == ContributionPayment::STATUS_PAID); return count($payments) > 0; } diff --git a/src/Entity/MembershipApplication.php b/src/Entity/MembershipApplication.php index d75a38a..e4b72a7 100644 --- a/src/Entity/MembershipApplication.php +++ b/src/Entity/MembershipApplication.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Entity\ContributionPayment; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\{ ArrayCollection, Collection }; use Symfony\Component\Validator\Constraints as Assert; @@ -144,6 +145,12 @@ public function createMember(?string $mollieSubscriptionId): Member { $member->setDivision($this->getPreferredDivision()); $member->setMollieCustomerId($this->getMollieCustomerId()); $member->setMollieSubscriptionId($mollieSubscriptionId); + if ($this->getPaid()) { + $init_payment = new ContributionPayment(); + $init_payment->setStatus('STATUS_PAID'); + $init_payment->setPaymentTime(new DateTime('now')); + $init_payment->setMember($member); + } return $member; }