household address: add max date for changing the validFrom date

This commit is contained in:
nobohan 2022-04-06 15:31:17 +02:00
parent 017b7bca87
commit 6a4edd000f
2 changed files with 18 additions and 4 deletions

View File

@ -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
]
);
}

View File

@ -13,10 +13,16 @@
<div>
{% 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 %}
</div>
<div hidden>