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

209 convert member to support member #222

Merged
merged 3 commits into from
Jan 26, 2025
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/Version20250126150401.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 Version20250126150401 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_support_member ADD original_id INT DEFAULT 0 NOT NULL, ADD original_registration_time DATE DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE admin_support_member DROP original_id, DROP original_registration_time');
}
}
66 changes: 62 additions & 4 deletions src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Controller\Admin;

use App\Entity\Member;
use App\Entity\SupportMember;
use App\Form\Admin\ContributionPaymentType;
use App\Form\Contribution\ContributionPeriodType;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;

use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
Expand All @@ -17,7 +19,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Field\{ Field, IdField, BooleanField, FormField, DateField, DateTimeField, CollectionField, ChoiceField, TextField, EmailField, AssociationField, MoneyField };
use EasyCorp\Bundle\EasyAdminBundle\Config\{ Crud, Filters, Actions, Action };
use EasyCorp\Bundle\EasyAdminBundle\Filter\{ EntityFilter };
use EasyCorp\Bundle\EasyAdminBundle\Filter\{ DateTimeFilter, EntityFilter };
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -53,15 +55,16 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular('lid')
->setEntityLabelInPlural('Leden')
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode', 'currentMembershipStatus.name'])
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode', 'currentMembershipStatus.name', 'dateOfBirth'])
;
}

public function configureFilters(Filters $filters): Filters
{
return $filters
->add(EntityFilter::new('division', 'Afdeling'))
->add(EntityFilter::new('currentMembershipStatus', 'Lidmaatschapstype'));
->add(EntityFilter::new('currentMembershipStatus', 'Lidmaatschapstype'))
->add(DateTimeFilter::new('dateOfBirth', 'GeboorteDatum'));
}

public function configureActions(Actions $actions): Actions {
Expand All @@ -78,6 +81,10 @@ public function configureActions(Actions $actions): Actions {
->setCssClass('btn btn-secondary');
$actions->add(Crud::PAGE_EDIT, $actionCancelMollie);
}
$actionConvertMember = Action::new('convert', 'Lid omzetten naar steunlid', 'fa fa-exchange-alt')
->linkToCrudAction('convertMemberToSupportMember');
$actions
->add(Crud::PAGE_EDIT, $actionConvertMember);
return $actions;
}

Expand Down Expand Up @@ -107,6 +114,57 @@ public function cancelMembership(AdminContext $adminContext,
return $this->redirect($redirectUrl);
}

public function convertMemberToSupportMember(AdminContext $adminContext, AdminUrlGenerator $adminUrlGenerator, EntityManagerInterface $entityManager): Response
{
/**
* @var Member
*/
$member = $adminContext->getEntity()->getInstance();

// check if current user is allowed and the selected member is allowed to be removed and converted
$redirectUrl = $adminUrlGenerator
->setController(self::class)
->setAction(Crud::PAGE_EDIT)
->setEntityId($member->getId())
->generateUrl();

$supportMember = new SupportMember();
$supportMember->setOriginalId($member->getId());
$supportMember->setFirstName($member->getFirstName());
$supportMember->setLastName($member->getLastName());
$supportMember->setEmail($member->getEmail());
$supportMember->setPhone($member->getPhone());
$supportMember->setIban($member->getIban());
$supportMember->setAddress($member->getAddress());
$supportMember->setCity($member->getCity());
$supportMember->setPostCode($member->getPostCode());
$supportMember->setCountry($member->getCountry());
$supportMember->setDateOfBirth($member->getDateOfBirth());
$supportMember->setRegistrationTime(new DateTime());
$supportMember->setOriginalRegistrationTime($member->getRegistrationTime());

// Should this become a new one, because i assume message is different, don't know where it is set
Copy link
Member

Choose a reason for hiding this comment

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

Goede vraag, steunleden betalen vaak andere contributie en ik weet niet zeker of we het bedrag kunnen aanpassen zonder opnieuw mandaat te vragen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Een mollie subscription heeft een methode om het bedrag te updaten. zie:

$subscription->update();

Maar ik weet niet of het zomaar mag

$supportMember->setMollieCustomerId($member->getMollieCustomerId());
$supportMember->setMollieSubscriptionId($member->getMollieSubscriptionId());
$supportMember->setContributionPeriod($member->getContributionPeriod());
$supportMember->setContributionPerPeriodInCents($member->getContributionPerPeriodInCents());

$entityManager->persist($supportMember);

// remove/deactivate member
$entityManager->remove($member);
$entityManager->flush();

// The highlight stays on the member tab.
$redirectUrl = $adminUrlGenerator
->setController(SupportMemberCrud::class)
->setAction(Crud::PAGE_EDIT)
->setEntityId($supportMember->getId())
->generateUrl();

return $this->redirect($redirectUrl);
}

public function export(AdminContext $adminContext): BinaryFileResponse
{
$spreadsheet = new Spreadsheet();
Expand Down Expand Up @@ -225,7 +283,7 @@ public function configureFields(string $pageName): iterable

array_push($fields,
TextField::new('lastName', 'Achternaam')->setDisabled(!$isAdmin),
DateField::new('dateOfBirth', 'Geboortedatum')->setDisabled(!$isAdmin)->hideOnIndex(),
DateField::new('dateOfBirth', 'Geboortedatum'),
DateField::new('registrationTime', 'Inschrijfdatum')
->setFormat(DateTimeField::FORMAT_SHORT)
->hideOnIndex(),
Expand Down
6 changes: 6 additions & 0 deletions src/Controller/Admin/SupportMemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public function configureFields(string $pageName): iterable
IdField::new('id', 'Lidnummer')
->setRequired(false)
->setFormTypeOptions(['attr' => ['placeholder' => 'Wordt automatisch bepaald']]),
IdField::new('originalId', 'Origineel Lidnummer')
->setRequired(false)
->setFormTypeOptions(['attr' => ['placeholder' => 'Wordt automatisch bepaald']]),

TextField::new('firstName', 'Voornaam'),
TextField::new('lastName', 'Achternaam'),
Expand All @@ -150,6 +153,9 @@ public function configureFields(string $pageName): iterable
DateField::new('registrationTime', 'Inschrijfdatum')
->setFormat(DateTimeField::FORMAT_SHORT)
->hideOnIndex(),
DateField::new('originalRegistrationTime', 'Originele Inschrijfdatum')
->setFormat(DateTimeField::FORMAT_SHORT)
->hideOnIndex(),

FormField::addPanel('Contactinformatie'),
EmailField::new('email', 'E-mailadres'),
Expand Down
16 changes: 16 additions & 0 deletions src/Entity/SupportMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ class SupportMember
*/
private int $contributionPerPeriodInCents;

/**
* @ORM\Column(type="integer", options={"default": 0})
*/
private int $originalId;

/**
* @ORM\Column(type="date", nullable=true)
*/
private ?DateTime $originalRegistrationTime = null;

// /**
// * @ORM\OneToMany(targetEntity="SupportMemberDetailsRevision", mappedBy="member")
// */
Expand Down Expand Up @@ -179,6 +189,12 @@ public function setContributionPeriod(int $contributionPeriod): void {
$this->contributionPeriod = $contributionPeriod;
}

public function getOriginalId(): ?int { return $this->originalId; }
public function setOriginalId(int $originalId): void { $this->originalId = $originalId; }

public function getOriginalRegistrationTime(): ?DateTime { return $this->originalRegistrationTime; }
public function setOriginalRegistrationTime(?DateTime $originalRegistrationTime): void { $this->originalRegistrationTime = $originalRegistrationTime; }

// public function getDetailRevisions(): Collection { return $this->detailRevisions; }
// public function getLastDetailRevision(): ?SupportMemberDetailsRevision {
// return $this->detailRevisions->getIterator()->uasort(function(SupportMemberDetailsRevision $a, SupportMemberDetailsRevision $b) {
Expand Down
Loading