Commit 4ac38f0c by Damien Moulard

add button in adherents admin to recalculate household allowance & move verifs

parent 0c6901dd
...@@ -165,7 +165,7 @@ class AdherentAdmin extends AbstractAdmin ...@@ -165,7 +165,7 @@ class AdherentAdmin extends AbstractAdmin
$tav_env = $this->getConfigurationPool()->getContainer()->getParameter('tav_env'); $tav_env = $this->getConfigurationPool()->getContainer()->getParameter('tav_env');
$household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance'); $household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance');
$simplified_household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('simplified_household_based_allowance'); $simplified_household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('simplified_household_based_allowance');
// && !$simplified_household_based_allowance
$formMapper $formMapper
->tab('General') ->tab('General')
->with('Identité', ['class' => 'col-md-7']) ->with('Identité', ['class' => 'col-md-7'])
...@@ -893,7 +893,8 @@ class AdherentAdmin extends AbstractAdmin ...@@ -893,7 +893,8 @@ class AdherentAdmin extends AbstractAdmin
parent::configureRoutes($collection); parent::configureRoutes($collection);
$collection $collection
->remove('delete') ->remove('delete')
->add('withdrawDownToTheCeiling', $this->getRouterIdParameter() . '/withdrawDownToTheCeiling'); ->add('withdrawDownToTheCeiling', $this->getRouterIdParameter() . '/withdrawDownToTheCeiling')
->add('recalculateHouseholdAllocations', 'recalculateHouseholdAllocations');
} }
public function getBatchActions() public function getBatchActions()
...@@ -983,5 +984,19 @@ class AdherentAdmin extends AbstractAdmin ...@@ -983,5 +984,19 @@ class AdherentAdmin extends AbstractAdmin
} }
return $res; return $res;
} }
public function configureActionButtons($action, $object = null)
{
$list = parent::configureActionButtons($action, $object);
$household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance');
$simplified_household_based_allowance = $this->getConfigurationPool()->getContainer()->getParameter('simplified_household_based_allowance');
if ($household_based_allowance || $simplified_household_based_allowance) {
$list['test']['template'] = '@kohinos/tav/block/admin_recalculate_allocations.html.twig';
}
return $list;
}
} }
...@@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request; ...@@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Adherent;
class AdherentAdminController extends CRUDController class AdherentAdminController extends CRUDController
{ {
...@@ -54,4 +56,52 @@ class AdherentAdminController extends CRUDController ...@@ -54,4 +56,52 @@ class AdherentAdminController extends CRUDController
$this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()]) $this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])
); );
} }
/**
* Recalculate household allocation in case of switching between household allocation methods.
*
* @param Request $request
* @IsGranted({"ROLE_SUPER_ADMIN", "ROLE_ADMIN_SIEGE", "ROLE_TRESORIER"})
* @return Response
*/
public function recalculateHouseholdAllocationsAction(Request $request): Response
{
$qb = $this->em->getRepository(Adherent::class)->createQueryBuilder('a');
if ($this->getParameter('simplified_household_based_allowance')) {
$adherents = $qb->where($qb->expr()->isNotNull("a.householdCount"))
->andWhere($qb->expr()->isNotNull("a.cotisationAmount"))
->getQuery()
->getResult();
;
foreach ($adherents as $adherent) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($adherent);
$this->em->persist($adherent);
}
} else if ($this->getParameter('household_based_allowance')) {
$adherents = $qb->where($qb->expr()->isNotNull("a.householdAdultCount"))
->andWhere($qb->expr()->isNotNull("a.cotisationAmount"))
->getQuery()
->getResult();
;
foreach ($adherents as $adherent) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHousehold($adherent);
$this->em->persist($adherent);
}
}
$this->em->flush();
$this->addFlash(
'sonata_flash_success',
'Allocation recalculées avec succès'
);
return new RedirectResponse(
$this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])
);
}
} }
...@@ -233,11 +233,6 @@ class UserComptoirController extends FluxController ...@@ -233,11 +233,6 @@ class UserComptoirController extends FluxController
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
} }
if (is_null($destinataire->getAllocationAmount())) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($destinataire);
$this->em->persist($destinataire);
}
$flux->setMontant($cotisationAmount); $flux->setMontant($cotisationAmount);
$this->em->persist($flux); $this->em->persist($flux);
$this->operationUtils->executeOperations($flux); $this->operationUtils->executeOperations($flux);
......
...@@ -255,6 +255,17 @@ class TAVCotisationUtils ...@@ -255,6 +255,17 @@ class TAVCotisationUtils
// get the mlc amount the user is supposed to receive // get the mlc amount the user is supposed to receive
$mlcAllowanceAmount = $adherent->getAllocationAmount(); $mlcAllowanceAmount = $adherent->getAllocationAmount();
// if allocation amount is null (as a security but should not occur), calculate here before applying & creating flux
if (is_null($mlcAllowanceAmount)) {
if ($this->container->getParameter('simplified_household_based_allowance')) {
$this->calculateAllowanceAccordingToHouseholdSimplified($adherent);
} else {
$this->calculateAllowanceAccordingToHousehold($adherent);
}
$this->em->persist($adherent);
$mlcAllowanceAmount = $adherent->getAllocationAmount();
}
// get the difference between what the user paid and what he•she's supposed to receive // get the difference between what the user paid and what he•she's supposed to receive
$amountDiff = $mlcAllowanceAmount - $cotisationAmount; $amountDiff = $mlcAllowanceAmount - $cotisationAmount;
......
<li>
<a class="sonata-action-element" href="{{ admin.generateUrl('recalculateHouseholdAllocations') }}">
<i class="fa fa-calculator"></i> {{ 'Recalculer les allocations en fonction du foyer'|trans() }}
</a>
</li>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment