Skip to content

Commit

Permalink
Member.php: also properly resolve monthly and yearly payments
Browse files Browse the repository at this point in the history
Closes: #203
Signed-off-by: Nowa Ammerlaan <[email protected]>
  • Loading branch information
Nowa-Ammerlaan committed Nov 17, 2024
1 parent 4c31fe0 commit 40a0c7e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
31 changes: 31 additions & 0 deletions migrations/Version20241117160044.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241117160044 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
14 changes: 7 additions & 7 deletions src/Entity/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Entity/MembershipApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,15 @@ 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(1);
$init_payment->setPaymentTime(new DateTime('now'));
$init_payment->setMember($member);
$em = $this->getDoctrine()->getManager();
$em->persist($init_payment);
$em->flush();
}
return $member;
}

Expand Down

0 comments on commit 40a0c7e

Please sign in to comment.