diff --git a/.env b/.env index 93c7877..21b1313 100644 --- a/.env +++ b/.env @@ -49,6 +49,7 @@ DIRECTADMIN_PASSWORD=pass # Socialisten and ROOD specific variables ORGANIZATION_NAME='ROOD, Socialistische Jongeren' +ORGANIZATION_ID='rood' ORGANIZATION_EMAIL='info@roodjongeren.nl' NOREPLY_ADDRESS='noreply@roodjongeren.nl' HOMEPAGE='roodjongeren.nl' diff --git a/config/instances/ds.yaml b/config/instances/ds.yaml new file mode 100644 index 0000000..246f642 --- /dev/null +++ b/config/instances/ds.yaml @@ -0,0 +1,6 @@ +contribution: + tiers: + - amount: 900 + description: Studenten en werklozen + - amount: null + description: "Werkenden: 0,5% van het netto inkomen (minimaal €15 per kwartaal)" diff --git a/config/instances/rood.yaml b/config/instances/rood.yaml new file mode 100644 index 0000000..493492c --- /dev/null +++ b/config/instances/rood.yaml @@ -0,0 +1,10 @@ +contribution: + tiers: + - amount: 750 + description: Tot en met €2000 bruto + - amount: 1500 + description: €2000-€3499 bruto + - amount: 2250 + description: €3500 bruto en daarboven + - amount: null + description: ik betaal een hogere contributie, namelijk: diff --git a/config/services.yaml b/config/services.yaml index ec17c51..3b3725a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -7,6 +7,7 @@ parameters: documents_directory: '%kernel.project_dir%/var/documents' mollie_payment_description: 'Contributiebetaling %env(ORGANIZATION_NAME)%' app.organizationName: '%env(ORGANIZATION_NAME)%' + app.organizationID: '%env(ORGANIZATION_ID)%' app.noReplyAddress: '%env(NOREPLY_ADDRESS)%' app.homepageUrl: '%env(HOMEPAGE)%' app.orgLogo: '%env(ORG_LOGO)%' diff --git a/src/Controller/ContributionController.php b/src/Controller/ContributionController.php index cc221c7..f7f7ca9 100644 --- a/src/Controller/ContributionController.php +++ b/src/Controller/ContributionController.php @@ -15,6 +15,7 @@ use DateTime; use DateInterval; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Yaml\Yaml; class ContributionController extends AbstractController { @@ -154,8 +155,12 @@ public function webhook(Request $request, MollieApiClient $mollieApiClient): Res * @Route("/automatische-incasso", name="member_contribution_automatic_collection") */ public function automaticCollection(Request $request, LoggerInterface $logger): Response { - $form = $this->createForm(ContributionIncomeType::class); - $form->setData(750); + $projectRoot = $this->getParameter('kernel.project_dir'); + $org_config = Yaml::parseFile($projectRoot . '/config/instances/' . $this->getParameter('app.organizationID') . '.yaml'); + + $form = $this->createForm(ContributionIncomeType::class, null, [ + 'contribution' => $org_config['contribution'] + ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -170,7 +175,8 @@ public function automaticCollection(Request $request, LoggerInterface $logger): return $this->render('user/contribution/automatic-collection.html.twig', [ 'success' => false, - 'form' => $form->createView() + 'form' => $form->createView(), + 'contribution' => $org_config['contribution'] ]); } diff --git a/src/Controller/MemberController.php b/src/Controller/MemberController.php index 340ec6f..4ebeeaa 100644 --- a/src/Controller/MemberController.php +++ b/src/Controller/MemberController.php @@ -19,6 +19,7 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Validator\Constraints\IsTrue; use Symfony\Component\Form\FormError; +use Symfony\Component\Yaml\Yaml; use DateTime; use DateInterval; @@ -86,13 +87,17 @@ public function home(Request $request): Response { * @Route("/aanmelden", name="member_apply") */ public function apply(Request $request): Response { + $projectRoot = $this->getParameter('kernel.project_dir'); + $org_config = Yaml::parseFile($projectRoot . '/config/instances/' . $this->getParameter('app.organizationID') . '.yaml'); + $membershipApplication = new MembershipApplication(); $membershipApplication->setRegistrationTime(new \DateTime()); $membershipApplication->setContributionPeriod(Member::PERIOD_QUARTERLY); $form = $this->createForm(MembershipApplicationType::class, $membershipApplication, [ 'use_middle_name' => $this->getParameter('app.useMiddleName'), 'privacy_policy_url' => $this->getParameter('app.privacyPolicyUrl'), - 'organization_name' => $this->getParameter('app.organizationName') + 'organization_name' => $this->getParameter('app.organizationName'), + 'contribution' => $org_config['contribution'] ]); $form->handleRequest($request); diff --git a/src/Form/Contribution/ContributionIncomeType.php b/src/Form/Contribution/ContributionIncomeType.php index 9afa248..7dd9276 100644 --- a/src/Form/Contribution/ContributionIncomeType.php +++ b/src/Form/Contribution/ContributionIncomeType.php @@ -7,21 +7,32 @@ use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Form\Extension\Core\Type\{ ChoiceType, MoneyType }; +use Symfony\Component\OptionsResolver\OptionsResolver; class ContributionIncomeType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { + $choices = []; + $max_amount = 0; + foreach ($options['contribution']['tiers'] as $tier) { + if ($tier['amount'] === null) { + $choices[$tier['description']] = 0; + } else { + $description = $tier['description'] . ' (ik betaal €' . number_format($tier['amount'] / 100, 2, ',') . ' contributie per kwartaal)'; + $choices[$description] = $tier['amount']; + } + + if ($tier['amount'] > $max_amount) { + $max_amount = $tier['amount']; + } + } + $builder ->add('contributionAmount', ChoiceType::class, [ 'error_bubbling' => true, 'label' => 'Maandinkomen', - 'choices' => [ - 'Tot en met €2000 (ik betaal €7,50 contributie per kwartaal)' => 750, - '€2000-€3499 (ik betaal €15,00 contributie per kwartaal)' => 1500, - '€3500 en daarboven (ik betaal €22,50 contributie per kwartaal)' => 2250, - 'ik betaal een hogere contributie, namelijk:' => 0, - ], + 'choices' => $choices, 'expanded' => true ]) ->add('otherAmount', MoneyType::class, [ @@ -31,21 +42,27 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'divisor' => 100, 'required' => false, 'attr' => [ - 'min' => 2250 + 'min' => $max_amount / 100 ], 'constraints' => new Assert\GreaterThan([ - 'value' => 22.50, - 'message' => 'Als je een hoger bedrag selecteert, moet dit hoger dan {{ compared_value }} zijn' + 'value' => $max_amount, + 'message' => 'Als je een hoger bedrag selecteert, moet dit hoger dan €' . number_format($max_amount / 100, 2, ',') . ' zijn.' ]) ]); $builder->addModelTransformer(new CallbackTransformer( fn($model) => [ - 'contributionAmount' => $model > 2250 ? null : $model, - 'otherAmount' => $model > 2250 ? $model : null + 'contributionAmount' => $model > $max_amount ? null : $model, + 'otherAmount' => $model > $max_amount ? $model : null ], fn($norm) => $norm['contributionAmount'] === 0 ? $norm['otherAmount'] : $norm['contributionAmount'] )); } + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setRequired([ + 'contribution' + ]); + } } diff --git a/src/Form/MembershipApplicationType.php b/src/Form/MembershipApplicationType.php index a094d2c..a17c079 100644 --- a/src/Form/MembershipApplicationType.php +++ b/src/Form/MembershipApplicationType.php @@ -48,7 +48,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add('contributionPerPeriodInCents', ContributionIncomeType::class, [ 'label' => 'Contributiebedrag', - 'error_bubbling' => true + 'error_bubbling' => true, + 'contribution' => $options['contribution'] ]) ->add('accept', CheckboxType::class, [ 'label' => 'Ik heb het privacybeleid gelezen en ik ga daarmee akkoord.', @@ -78,5 +79,9 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setRequired([ 'organization_name' ]); + + $resolver->setRequired([ + 'contribution' + ]); } } diff --git a/templates/user/contribution/automatic-collection.html.twig b/templates/user/contribution/automatic-collection.html.twig index 3a0f62b..52c5c9f 100644 --- a/templates/user/contribution/automatic-collection.html.twig +++ b/templates/user/contribution/automatic-collection.html.twig @@ -3,15 +3,28 @@ {% block scripts %} {{ parent() }} {% endblock %} @@ -30,8 +43,10 @@ {% else %}

Contributie zal elk kwartaal automatisch van je rekening afgeschreven worden via automatisch incasso. - Hoeveel je hierbij betaalt hangt af van je inkomen: + Hoeveel je hierbij betaalt hangt af van je inkomen.

+ + {% if contribution.tiers|length > 2 %} @@ -40,20 +55,17 @@ - - - - - - - - - - - - + {% for tier in contribution.tiers %} + {% if tier.amount is not same as(null) %} + + + + + {% endif %} + {% endfor %}
Tot en met €2000€7,50 per kwartaal (€2,50 per maand)
€2000-€3499€15,00 per kwartaal (€5 per maand)
€3500 en daarboven€22,50 per kwartaal (€7,50 per maand)
{{ tier.description }}€{{ (tier.amount / 100)|number_format(2, ',') }} per kwartaal (€{{ (tier.amount / 100 / 3)|number_format(2, ',') }} per maand)
+ {% endif %} {% if form.vars.submitted and not form.vars.valid %}
diff --git a/templates/user/member/apply.html.twig b/templates/user/member/apply.html.twig index 21b5a26..71368a3 100644 --- a/templates/user/member/apply.html.twig +++ b/templates/user/member/apply.html.twig @@ -32,10 +32,10 @@ {% block body %}
- + - Inschrijven bij ROOD + Inschrijven bij {{ orgnaamkort }} {% if form.vars.submitted and not form.vars.valid %} @@ -67,7 +67,7 @@ {{ form_row(form.preferredDivision, { attr: { class: 'text-input' } }) }}

- Selecteer wat er voor jou van toepassing is: + Bij {{ orgnaamkort }} hebben we contributie op basis van je bruto maandinkomen. Selecteer wat er voor jou van toepassing is:

{% for option in form.contributionPerPeriodInCents.contributionAmount %}