mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
household address: add condition for minimum value for vaildFrom date
This commit is contained in:
parent
3a3eb68288
commit
ddce7603ad
@ -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
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -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) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user