household address: add condition for minimum value for vaildFrom date

This commit is contained in:
nobohan 2022-04-02 10:53:54 +02:00
parent 3a3eb68288
commit ddce7603ad
2 changed files with 22 additions and 3 deletions

View File

@ -158,10 +158,23 @@ class HouseholdController extends AbstractController
$form->handleRequest($request);
$addresses = $household->getAddressesOrdered();
foreach($addresses as $a) {
if ($a->getId() === $address->getId()){
$currentValueIndex = array_search($a, $addresses);
}
}
if (count($addresses) > 1 && $currentValueIndex > 0) {
$previousAddress = $addresses[$currentValueIndex - 1];
$minValidFrom = $previousAddress->getValidTo();
} else {
$minValidFrom = null;
}
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->persist($address);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('chill_person_household_addresses', [
'household_id' => $household->getId()
]);
@ -172,7 +185,8 @@ class HouseholdController extends AbstractController
[
'household' => $household,
'address' => $address,
'form' => $form->createView()
'form' => $form->createView(),
'minValidFrom' => $minValidFrom
]
);
}

View File

@ -11,8 +11,13 @@
{{ form_start(form) }}
{{ form_errors(form) }}
<div>
{{ form_row(form.validFrom) }}
{% if minValidFrom is not null %}
{{ form_row(form.validFrom, {'attr': {'min': minValidFrom|date('Y-m-d') }}) }}
{% else %}
{{ form_row(form.validFrom) }}
{% endif %}
</div>
<div hidden>
{{ form_rest(form) }}