From 6a4edd000fee5216658dd38dafe2b2b0232436b3 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 6 Apr 2022 15:31:17 +0200 Subject: [PATCH] household address: add max date for changing the validFrom date --- .../Controller/HouseholdController.php | 10 +++++++++- .../Household/address_valid_from_edit.html.twig | 12 +++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index 311d2eaad..c8f14ba21 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -172,6 +172,13 @@ class HouseholdController extends AbstractController $minValidFrom = null; } + if (count($addresses) > 1 && count($addresses) > $currentValueIndex + 1) { + $nextAddress = $addresses[$currentValueIndex + 1]; + $maxValidFrom = $nextAddress->getValidFrom(); + } else { + $maxValidFrom = null; + } + if ($form->isSubmitted() && $form->isValid()) { $this->getDoctrine()->getManager()->persist($address); $this->getDoctrine()->getManager()->flush(); @@ -186,7 +193,8 @@ class HouseholdController extends AbstractController 'household' => $household, 'address' => $address, 'form' => $form->createView(), - 'minValidFrom' => $minValidFrom + 'minValidFrom' => $minValidFrom, + 'maxValidFrom' => $maxValidFrom ] ); } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/address_valid_from_edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/address_valid_from_edit.html.twig index 9f0a438fb..a2b8753f5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/address_valid_from_edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/address_valid_from_edit.html.twig @@ -13,10 +13,16 @@
- {% if minValidFrom is not null %} - {{ form_row(form.validFrom, {'attr': {'min': minValidFrom|date('Y-m-d') }}) }} + {% if minValidFrom is not null and maxValidFrom is not null %} + {{ form_row(form.validFrom, {'attr': {'min': minValidFrom|date('Y-m-d'), 'max': maxValidFrom|date('Y-m-d') }}) }} {% else %} - {{ form_row(form.validFrom) }} + {% if minValidFrom is not null %} + {{ form_row(form.validFrom, {'attr': {'min': minValidFrom|date('Y-m-d')}}) }} + {% elseif maxValidFrom is not null %} + {{ form_row(form.validFrom, {'attr': {'max': maxValidFrom|date('Y-m-d')}}) }} + {% else %} + {{ form_row(form.validFrom) }} + {% endif %} {% endif %}