Commit 261e7f4f by Yvon

in adherent admin, add column showing balance vs ceiling and withdraw btn for super admin and siege

parent b9d2a992
...@@ -253,7 +253,7 @@ services: ...@@ -253,7 +253,7 @@ services:
admin.adherent.gerer: admin.adherent.gerer:
class: App\Admin\AdherentAdmin class: App\Admin\AdherentAdmin
# arguments: [~, App\Entity\OBJECT, 'PixSortableBehaviorBundle:SortableAdmin'] # arguments: [~, App\Entity\OBJECT, 'PixSortableBehaviorBundle:SortableAdmin']
arguments: [~, App\Entity\Adherent, 'App\Controller\CRUD\CRUDController'] arguments: [~, App\Entity\Adherent, 'App\Controller\AdherentAdminController']
tags: tags:
- name: sonata.admin - name: sonata.admin
manager_type: orm manager_type: orm
......
...@@ -583,6 +583,7 @@ class AdherentAdmin extends AbstractAdmin ...@@ -583,6 +583,7 @@ class AdherentAdmin extends AbstractAdmin
->addIdentifier('user.email', null, ['label' => 'Email']) ->addIdentifier('user.email', null, ['label' => 'Email'])
; ;
$actions = ['edit' => []];
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) { if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper $listMapper
->add( ->add(
...@@ -603,6 +604,21 @@ class AdherentAdmin extends AbstractAdmin ...@@ -603,6 +604,21 @@ class AdherentAdmin extends AbstractAdmin
'template' => '@kohinos/tav/list_user_tav_cotisation.html.twig', 'template' => '@kohinos/tav/list_user_tav_cotisation.html.twig',
] ]
); );
if($this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance')
&& $this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMIN_SIEGE')) {
$listMapper
->add(
'ceiling',
null,
[
'label' => 'Solde & plafond',
'template' => '@kohinos/tav/list_user_ssa_ceiling.html.twig',
]
);
$actions['withdrawDownToTheCeiling'] = [
'template' => '@kohinos/tav/adherent_action_withdraw_down_to_the_ceiling.html.twig'
];
}
} }
$listMapper $listMapper
...@@ -625,7 +641,7 @@ class AdherentAdmin extends AbstractAdmin ...@@ -625,7 +641,7 @@ class AdherentAdmin extends AbstractAdmin
'label' => 'Mis à jour le', 'label' => 'Mis à jour le',
]) ])
->add('_action', null, [ ->add('_action', null, [
'actions' => ['edit' => []], 'actions' => $actions,
]) ])
; ;
} }
...@@ -633,7 +649,9 @@ class AdherentAdmin extends AbstractAdmin ...@@ -633,7 +649,9 @@ class AdherentAdmin extends AbstractAdmin
protected function configureRoutes(RouteCollection $collection) protected function configureRoutes(RouteCollection $collection)
{ {
parent::configureRoutes($collection); parent::configureRoutes($collection);
$collection->remove('delete'); $collection
->remove('delete')
->add('withdrawDownToTheCeiling', $this->getRouterIdParameter() . '/withdrawDownToTheCeiling');
} }
public function getBatchActions() public function getBatchActions()
......
<?php
namespace App\Controller;
use App\Utils\CustomEntityManager;
use App\Utils\TAVCotisationUtils;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Security;
class AdherentAdminController extends CRUDController
{
protected $em;
protected $security;
protected $tavCotisationUtils;
public function __construct(CustomEntityManager $em, Security $security, TAVCotisationUtils $tavCotisationUtils)
{
$this->em = $em;
$this->security = $security;
$this->tavCotisationUtils = $tavCotisationUtils;
}
/**
* Prélèvement d'un adhérent pour ramener son solde sous son plafond.
*
* @param Request $request
* @param Uuid $id Id du prestataire
* @IsGranted({"ROLE_SUPER_ADMIN", "ROLE_ADMIN_SIEGE"})
* @return Response
*/
public function withdrawDownToTheCeilingAction(Request $request, $id): Response
{
$adherent = $this->admin->getSubject();
if (!$adherent) {
throw new NotFoundHttpException(sprintf('Impossible de trouver l\'adhérent avec l\'id: %s', $id));
}
$amountDiff = $this->tavCotisationUtils->withdrawDownToTheCeiling($adherent);
$this->em->flush();
$this->addFlash(
'sonata_flash_success',
'Prélèvement de ' . $amountDiff . ' MonA' . ' effectué.'
);
return new RedirectResponse(
$this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])
);
}
}
...@@ -446,4 +446,10 @@ class Adherent extends AccountableObject implements AccountableInterface ...@@ -446,4 +446,10 @@ class Adherent extends AccountableObject implements AccountableInterface
return $this; return $this;
} }
public function getCeiling()
{
//This formula has been configured for ssa gironde project
return 2 * $this->allocationAmount;
}
} }
...@@ -10,6 +10,8 @@ use Doctrine\ORM\Mapping as ORM; ...@@ -10,6 +10,8 @@ use Doctrine\ORM\Mapping as ORM;
* Dans les cas suivants : * Dans les cas suivants :
* - [Profil de Cotisation] La taux est inférieur à 1 * - [Profil de Cotisation] La taux est inférieur à 1
* - [Allocation selon foyer] Le montant reçu calculé est inférieur au montant payé * - [Allocation selon foyer] Le montant reçu calculé est inférieur au montant payé
* - [Allocation selon foyer] Un administrateur effectue une opération manuelle de prélèvement de l'adhérent
* pour ramener son solde au niveau de son plafond.
* *
* L'adhérent•e reçoit moins d'emlc que ce qu'elle•il paye en €, * L'adhérent•e reçoit moins d'emlc que ce qu'elle•il paye en €,
* un second flux est créé pour prélever le complément de la cotisation. * un second flux est créé pour prélever le complément de la cotisation.
......
...@@ -184,6 +184,37 @@ class TAVCotisationUtils ...@@ -184,6 +184,37 @@ class TAVCotisationUtils
$this->em->persist($fluxCotis); $this->em->persist($fluxCotis);
$this->operationUtils->executeOperations($fluxCotis); $this->operationUtils->executeOperations($fluxCotis);
} }
/**
* Method called to create Flux based on allowance amount (for household based allowance).
*/
public function withdrawDownToTheCeiling(Adherent $adherent)
{
$balance = $adherent->getEmlcAccount()->getBalance();
$ceiling = $adherent->getCeiling();
$siege = $this->em->getRepository(Siege::class)->getTheOne();
// get the amount we want to withdraw
$amountDiff = $ceiling - $balance;
if ($amountDiff >= 0) {
throw new \Exception("Impossible de prélèver : le solde de l'adhérent est inférieur ou égal au plafond.");
}
$flux = new CotisationTavPrelevement();
$flux->setExpediteur($adherent);
$flux->setDestinataire($siege);
$flux->setMontant(-$amountDiff);
$flux->setReference("Prélèvement pour ramener le solde de " . $balance . "MonA sous le plafond de " . $ceiling . " MonA.");
$flux->setOperateur($this->security->getUser());
$flux->setRole($this->security->getUser()->getGroups()[0]->__toString());
$flux->setMoyen(MoyenEnum::MOYEN_EMLC);
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
return $amountDiff;
}
/** /**
* Get the last cotisation of an adhérent * Get the last cotisation of an adhérent
* *
......
{% set balance = object.user.adherent.emlcAccount.balance %}
{% set ceiling = object.user.adherent.ceiling %}
{% if balance and ceiling and balance > ceiling %}
<a class="btn btn-sm btn-default" href="{{ admin.generateObjectUrl('withdrawDownToTheCeiling', object) }}">
Prélever
</a>
{% endif %}
{% extends admin.getTemplate('base_list_field') %}
{% block field %}
{%- spaceless %}
{% set balance = object.user.adherent.emlcAccount.balance %}
{% set ceiling = object.user.adherent.ceiling %}
{% if balance and ceiling and balance > ceiling %}
{% set class = 'label label-danger' %}
{% set text = balance ~ ' > ' ~ ceiling %}
{% else %}
{% set class = 'label label-success' %}
{% set text = balance ~ " &leq; " ~ ceiling %}
{% endif %}
<span class="{{ class }}">{{ text|raw }}</span>
{% endspaceless -%}
{% endblock %}
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