Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member.php: also properly resolve monthly and yearly payments #212

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
27 changes: 27 additions & 0 deletions src/Controller/Admin/MembershipApplicationCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Service\SubscriptionSetupService;
use Doctrine\ORM\QueryBuilder;

use App\Entity\ContributionPayment;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
Expand Down Expand Up @@ -101,6 +102,32 @@ public function acceptApplication(AdminContext $context)
$member = $application->createMember(null);
$member->generateNewPasswordToken();
$em = $this->getDoctrine()->getManager();

if ($application->getPaid()) {
$init_payment = new ContributionPayment();
$init_payment->setMember($member);
$init_payment->setStatus(1);
$init_payment->setPaymentTime($member->getRegistrationTime());
$init_payment->setPeriodYear($member->getRegistrationTime()->format('Y'));
$init_payment->setPeriodMonthStart($member->getRegistrationTime()->format('n'));
switch ($member->getContributionPeriod()) {
case $member::PERIOD_MONTHLY:
$init_payment->setPeriodMonthEnd($member->getRegistrationTime()->modify('+1 month')->format('n'));
break;
case $member::PERIOD_QUARTERLY:
$init_payment->setPeriodMonthEnd($member->getRegistrationTime()->modify('+3 month')->format('n'));
break;
case $member::PERIOD_ANNUALLY:
$init_payment->setPeriodMonthEnd($member->getRegistrationTime()->modify('+12 month')->format('n'));
Comment on lines +115 to +121
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik denk dat $member->getRegistrationTime()->modify('+12 month') in place muteert, waardoor dit #217 veroorzaakt.

break;
default:
throw new \Exception('Period must be PERIOD_MONTHLY, PERIOD_QUARTERLY or PERIOD_ANNUALLY');
}
$init_payment->setAmountInCents($member->getContributionPerPeriodInCents());
$init_payment->setAmountInEuros($member->getContributionPerPeriodInEuros());
$em->persist($init_payment);
}

$em->persist($member);
$em->flush();

Expand Down
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 @@ -271,20 +271,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
Loading