Commit 6b224702 by Damien Moulard

calculate allocation with simplified household process

parent 011398af
...@@ -131,7 +131,7 @@ services: ...@@ -131,7 +131,7 @@ services:
class: App\Utils\TAVCotisationUtils class: App\Utils\TAVCotisationUtils
autowire: false autowire: false
public: true public: true
arguments: ['@app.utils.custom_entity_manager', '@security.helper', '@app.utils.operations'] arguments: ['@app.utils.custom_entity_manager', '@security.helper', '@app.utils.operations', '@service_container']
app.utils.payment: app.utils.payment:
class: App\Utils\PaymentUtils class: App\Utils\PaymentUtils
......
...@@ -90,7 +90,7 @@ class FluxController extends AbstractController ...@@ -90,7 +90,7 @@ class FluxController extends AbstractController
SessionInterface $session, SessionInterface $session,
Environment $templating, Environment $templating,
OperationUtils $operationUtils, OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils, TAVCotisationUtils $tavCotisationUtils,
TokenGeneratorInterface $tokenGenerator, TokenGeneratorInterface $tokenGenerator,
ValidatorInterface $validator, ValidatorInterface $validator,
CsrfTokenManagerInterface $tokenManager, CsrfTokenManagerInterface $tokenManager,
...@@ -107,7 +107,7 @@ class FluxController extends AbstractController ...@@ -107,7 +107,7 @@ class FluxController extends AbstractController
$this->tokenGenerator = $tokenGenerator; $this->tokenGenerator = $tokenGenerator;
$this->validator = $validator; $this->validator = $validator;
$this->tokenManager = $tokenManager; $this->tokenManager = $tokenManager;
$this->tavCotisationsUtils = $tavCotisationsUtils; $this->tavCotisationUtils = $tavCotisationUtils;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->router = $router; $this->router = $router;
} }
......
...@@ -130,19 +130,22 @@ class UserAdherentController extends FluxController ...@@ -130,19 +130,22 @@ class UserAdherentController extends FluxController
private function paiementCotisTavValidation($flux) { private function paiementCotisTavValidation($flux) {
$destinataire = $flux->getDestinataire(); $destinataire = $flux->getDestinataire();
if($reason = $this->tavCotisationsUtils->preventCotisationDuplication($destinataire)) { if($reason = $this->tavCotisationUtils->preventCotisationDuplication($destinataire)) {
return $reason; return $reason;
} }
// Look for cotisation data depending on active process // Look for cotisation data depending on active process
if (true == $this->getParameter('household_based_allowance')) { if (true == $this->getParameter('simplified_household_based_allowance')) {
$cotisationAmount = $destinataire->getCotisationAmount(); $cotisationAmount = $destinataire->getCotisationAmount();
if ( // Use ProfilDeCotisation if set & conditions for simplified_household_based_allowance not met
is_null($cotisationAmount) if ((is_null($cotisationAmount) || is_null($destinataire->getHouseholdCount())) && is_null($destinataire->getProfilDeCotisation())) {
|| is_null($destinataire->getHouseholdAdultCount()) && !$this->getParameter('simplified_household_based_allowance') return "Opération impossible : votre profil est incomplet, informations de cotisation manquantes. Veuillez contacter un administrateur.";
|| is_null($destinataire->getHouseholdCount()) && $this->getParameter('simplified_household_based_allowance') }
) { } else if (true == $this->getParameter('household_based_allowance')) {
$cotisationAmount = $destinataire->getCotisationAmount();
if (is_null($cotisationAmount) || is_null($destinataire->getHouseholdAdultCount())) {
return "Opération impossible : votre profil est incomplet, informations de cotisation manquantes. Veuillez contacter un administrateur."; return "Opération impossible : votre profil est incomplet, informations de cotisation manquantes. Veuillez contacter un administrateur.";
} }
} else { } else {
...@@ -193,12 +196,20 @@ class UserAdherentController extends FluxController ...@@ -193,12 +196,20 @@ class UserAdherentController extends FluxController
'type' => Payment::TYPE_PAIEMENT_COTISATION_TAV 'type' => Payment::TYPE_PAIEMENT_COTISATION_TAV
]); ]);
/* For test purposes, comment redirection and uncomment following part to skip payment */ /* For test purposes, comment redirection above and uncomment following part to skip payment */
// $this->em->persist($flux); // $this->em->persist($flux);
// $this->operationUtils->executeOperations($flux); // $this->operationUtils->executeOperations($flux);
// // Apply cotisation rate, create new flux // // Apply cotisation rate, create new flux
// $this->tavCotisationsUtils->applyTauxCotisation($flux); // $destinataire = $flux->getDestinataire();
// $allocationMethod = $this->tavCotisationUtils->getAppropriateAllocationMethod($destinataire);
// // Create new flux for cotisation, depending on process
// if ($this->getParameter('household_based_allowance') || $this->getParameter('simplified_household_based_allowance')) {
// $this->tavCotisationUtils->applyHouseholdAllowance($flux);
// } else {
// $this->tavCotisationUtils->applyTauxCotisation($flux);
// }
// $this->em->flush(); // $this->em->flush();
// $this->addFlash( // $this->addFlash(
......
...@@ -205,7 +205,7 @@ class UserComptoirController extends FluxController ...@@ -205,7 +205,7 @@ class UserComptoirController extends FluxController
$flux = $form->getData(); $flux = $form->getData();
// Look for existing cotisation // Look for existing cotisation
if ($reason = $this->tavCotisationsUtils->preventCotisationDuplication($flux->getDestinataire())) { if ($reason = $this->tavCotisationUtils->preventCotisationDuplication($flux->getDestinataire())) {
$this->addFlash( $this->addFlash(
'error', 'error',
$this->translator->trans($reason) $this->translator->trans($reason)
...@@ -216,16 +216,15 @@ class UserComptoirController extends FluxController ...@@ -216,16 +216,15 @@ class UserComptoirController extends FluxController
$destinataire = $flux->getDestinataire(); $destinataire = $flux->getDestinataire();
if ($this->getParameter('household_based_allowance') == true) { $allocationMethod = $this->tavCotisationUtils->getAppropriateAllocationMethod($destinataire);
/* Process: allowance based on household */
// Some code duplication between household_based_allowance && simplified_household_based_allowance, for better readability
if ($allocationMethod == 'simplified_household_based_allowance') {
/* Process: simplified allowance based on household */
$cotisationAmount = $destinataire->getCotisationAmount(); $cotisationAmount = $destinataire->getCotisationAmount();
// Verifications // Verifications
if ( if (is_null($cotisationAmount) || is_null($destinataire->getHouseholdCount()) ) {
is_null($cotisationAmount)
|| is_null($destinataire->getHouseholdAdultCount()) && !$this->getParameter('simplified_household_based_allowance')
|| is_null($destinataire->getHouseholdCount()) && $this->getParameter('simplified_household_based_allowance')
) {
$this->addFlash( $this->addFlash(
'error', 'error',
$this->translator->trans("Opération impossible : le profil de l'habitant.e est incomplet, veuillez le compléter dans l'interface d'administration.") $this->translator->trans("Opération impossible : le profil de l'habitant.e est incomplet, veuillez le compléter dans l'interface d'administration.")
...@@ -235,12 +234,32 @@ class UserComptoirController extends FluxController ...@@ -235,12 +234,32 @@ class UserComptoirController extends FluxController
} }
if (is_null($destinataire->getAllocationAmount())) { if (is_null($destinataire->getAllocationAmount())) {
if ($this->getParameter('simplified_household_based_allowance') == true) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($destinataire); $this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($destinataire);
} else { $this->em->persist($destinataire);
$this->tavCotisationUtils->calculateAllowanceAccordingToHousehold($destinataire); }
$flux->setMontant($cotisationAmount);
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
// Create new flux based on difference with cotisation amount
$this->tavCotisationUtils->applyHouseholdAllowance($flux);
} else if ($allocationMethod == 'household_based_allowance') {
/* Process: allowance based on household */
$cotisationAmount = $destinataire->getCotisationAmount();
// Verifications
if (is_null($cotisationAmount) || is_null($destinataire->getHouseholdAdultCount()) ) {
$this->addFlash(
'error',
$this->translator->trans("Opération impossible : le profil de l'habitant.e est incomplet, veuillez le compléter dans l'interface d'administration.")
);
return $this->redirectToRoute('index');
} }
if (is_null($destinataire->getAllocationAmount())) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHousehold($destinataire);
$this->em->persist($destinataire); $this->em->persist($destinataire);
} }
...@@ -248,8 +267,8 @@ class UserComptoirController extends FluxController ...@@ -248,8 +267,8 @@ class UserComptoirController extends FluxController
$this->em->persist($flux); $this->em->persist($flux);
$this->operationUtils->executeOperations($flux); $this->operationUtils->executeOperations($flux);
// Apply cotisation rate, create new flux // Create new flux based on difference with cotisation amount
$this->tavCotisationsUtils->applyHouseholdAllowance($flux); $this->tavCotisationUtils->applyHouseholdAllowance($flux);
} else { } else {
/* Process: allowance based on cotisation profile with cotisation rate */ /* Process: allowance based on cotisation profile with cotisation rate */
$profile = $destinataire->getProfilDeCotisation(); $profile = $destinataire->getProfilDeCotisation();
...@@ -270,7 +289,7 @@ class UserComptoirController extends FluxController ...@@ -270,7 +289,7 @@ class UserComptoirController extends FluxController
$this->operationUtils->executeOperations($flux); $this->operationUtils->executeOperations($flux);
// Apply cotisation rate, create new flux // Apply cotisation rate, create new flux
$this->tavCotisationsUtils->applyTauxCotisation($flux); $this->tavCotisationUtils->applyTauxCotisation($flux);
} }
$this->em->flush(); $this->em->flush();
......
...@@ -24,7 +24,7 @@ class PaymentStatusExtension implements ExtensionInterface ...@@ -24,7 +24,7 @@ class PaymentStatusExtension implements ExtensionInterface
private $serializer; private $serializer;
private $userManager; private $userManager;
private $operationUtils; private $operationUtils;
private $tavCotisationsUtils; private $tavCotisationUtils;
private $container; private $container;
private $paymentUtils; private $paymentUtils;
...@@ -39,7 +39,7 @@ class PaymentStatusExtension implements ExtensionInterface ...@@ -39,7 +39,7 @@ class PaymentStatusExtension implements ExtensionInterface
SerializerInterface $serializer, SerializerInterface $serializer,
UserManagerInterface $userManager, UserManagerInterface $userManager,
OperationUtils $operationUtils, OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils, TAVCotisationUtils $tavCotisationUtils,
ContainerInterface $container, ContainerInterface $container,
PaymentUtils $paymentUtils PaymentUtils $paymentUtils
) { ) {
...@@ -48,7 +48,7 @@ class PaymentStatusExtension implements ExtensionInterface ...@@ -48,7 +48,7 @@ class PaymentStatusExtension implements ExtensionInterface
$this->serializer = $serializer; $this->serializer = $serializer;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->operationUtils = $operationUtils; $this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils; $this->tavCotisationUtils = $tavCotisationUtils;
$this->container = $container; $this->container = $container;
$this->paymentUtils = $paymentUtils; $this->paymentUtils = $paymentUtils;
} }
......
...@@ -37,7 +37,21 @@ class AchatMonnaieFormType extends FluxFormType ...@@ -37,7 +37,21 @@ class AchatMonnaieFormType extends FluxFormType
if ($this->container->getParameter('tav_env')) { if ($this->container->getParameter('tav_env')) {
$montant = 0; $montant = 0;
if ($this->container->getParameter('household_based_allowance')) { if ($this->container->getParameter('simplified_household_based_allowance')) {
// if no cotisation amount, get amount from profil de cotisation instead if set
// (for transition purposes from other allocation process)
$cosisationMontant = $this->security->getUser()->getAdherent()->getCotisationAmount();
if (null != $cosisationMontant) {
$montant = $cosisationMontant;
} else {
$profilDeCotisation = $this->security->getUser()->getAdherent()->getProfilDeCotisation();
if (null != $profilDeCotisation) {
$montant = $profilDeCotisation->getMontant();
} else {
$montant = false;
}
}
} else if ($this->container->getParameter('household_based_allowance')) {
$cosisationMontant = $this->security->getUser()->getAdherent()->getCotisationAmount(); $cosisationMontant = $this->security->getUser()->getAdherent()->getCotisationAmount();
if (null != $cosisationMontant) { if (null != $cosisationMontant) {
$montant = $cosisationMontant; $montant = $cosisationMontant;
......
...@@ -24,7 +24,14 @@ class EncaisserCotisationAdherentFormType extends VenteEmlcAdherentFormType ...@@ -24,7 +24,14 @@ class EncaisserCotisationAdherentFormType extends VenteEmlcAdherentFormType
foreach ($adherents as $adh) { foreach ($adherents as $adh) {
$montant = null; $montant = null;
if ($this->container->getParameter('household_based_allowance') && !is_null($adh->getCotisationAmount())) { if ($this->container->getParameter('simplified_household_based_allowance')) {
if (!is_null($adh->getCotisationAmount())) {
$montant = $adh->getCotisationAmount();
} else if (!is_null($adh->getProfilDeCotisation())) {
// For transition purposes, if adherent doesn't have a cotisation amount set but has a ProfilDeCotisation, use ProfilDeCotisation amount
$montant = $adh->getProfilDeCotisation()->getMontant();
}
} if ($this->container->getParameter('household_based_allowance') && !is_null($adh->getCotisationAmount())) {
$montant = $adh->getCotisationAmount(); $montant = $adh->getCotisationAmount();
} else if (!$this->container->getParameter('household_based_allowance') && !is_null($adh->getProfilDeCotisation())) { } else if (!$this->container->getParameter('household_based_allowance') && !is_null($adh->getProfilDeCotisation())) {
$montant = $adh->getProfilDeCotisation()->getMontant(); $montant = $adh->getProfilDeCotisation()->getMontant();
......
...@@ -27,7 +27,7 @@ class PaymentUtils ...@@ -27,7 +27,7 @@ class PaymentUtils
private $serializer; private $serializer;
private $userManager; private $userManager;
private $operationUtils; private $operationUtils;
private $tavCotisationsUtils; private $tavCotisationUtils;
private $container; private $container;
/** /**
...@@ -38,14 +38,14 @@ class PaymentUtils ...@@ -38,14 +38,14 @@ class PaymentUtils
SerializerInterface $serializer, SerializerInterface $serializer,
UserManagerInterface $userManager, UserManagerInterface $userManager,
OperationUtils $operationUtils, OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils, TAVCotisationUtils $tavCotisationUtils,
ContainerInterface $container ContainerInterface $container
) { ) {
$this->em = $em; $this->em = $em;
$this->serializer = $serializer; $this->serializer = $serializer;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->operationUtils = $operationUtils; $this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils; $this->tavCotisationUtils = $tavCotisationUtils;
$this->container = $container; $this->container = $container;
} }
...@@ -248,11 +248,13 @@ class PaymentUtils ...@@ -248,11 +248,13 @@ class PaymentUtils
$this->operationUtils->executeOperations($flux); $this->operationUtils->executeOperations($flux);
if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type || Payment::TYPE_PAIEMENT_RECURRENT_COTISATION_TAV == $type) { if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type || Payment::TYPE_PAIEMENT_RECURRENT_COTISATION_TAV == $type) {
$allocationMethod = $this->tavCotisationUtils->getAppropriateAllocationMethod($destinataire);
// Create new flux for cotisation, depending on process // Create new flux for cotisation, depending on process
if ($this->container->getParameter('household_based_allowance')) { if ($this->container->getParameter('household_based_allowance') || $this->container->getParameter('simplified_household_based_allowance')) {
$this->tavCotisationsUtils->applyHouseholdAllowance($flux); $this->tavCotisationUtils->applyHouseholdAllowance($flux);
} else { } else {
$this->tavCotisationsUtils->applyTauxCotisation($flux); $this->tavCotisationUtils->applyTauxCotisation($flux);
} }
} }
} }
......
...@@ -16,21 +16,25 @@ use App\Repository\PaymentRepository; ...@@ -16,21 +16,25 @@ use App\Repository\PaymentRepository;
use App\Utils\CustomEntityManager; use App\Utils\CustomEntityManager;
use Payum\Core\Request\GetHumanStatus; use Payum\Core\Request\GetHumanStatus;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TAVCotisationUtils class TAVCotisationUtils
{ {
private $em; private $em;
private $security; private $security;
private $operationUtils; private $operationUtils;
private $container;
public function __construct ( public function __construct (
CustomEntityManager $em, CustomEntityManager $em,
Security $security, Security $security,
OperationUtils $operationUtils OperationUtils $operationUtils,
ContainerInterface $container
) { ) {
$this->em = $em; $this->em = $em;
$this->security = $security; $this->security = $security;
$this->operationUtils = $operationUtils; $this->operationUtils = $operationUtils;
$this->container = $container;
} }
/** /**
...@@ -401,4 +405,30 @@ class TAVCotisationUtils ...@@ -401,4 +405,30 @@ class TAVCotisationUtils
} }
$this->em->flush(); $this->em->flush();
} }
/**
* Check parameters and Adherent data in order to detect the right allocation method to use.
*
* Specific rule: if simplified_household_based_allowance is active BUT adherent's profile is incomplete for this method AND (s)he has a ProfilDeCotisation set, use ProfilDeCotisation
* (allows flowless transition from ProfilDeCotisation to simplified_household_based_allowance)
*
* @param Adherent $adherent
* @return String 'cotisation_profile' | 'household_based_allowance' | 'simplified_household_based_allowance
*/
public function getAppropriateAllocationMethod($adherent) {
if ($this->container->getParameter('simplified_household_based_allowance')) {
if (
(is_null($adherent->getCotisationAmount()) || is_null($adherent->getHouseholdCount()))
&& !is_null($adherent->getProfilDeCotisation())
) {
return 'cotisation_profile';
} else {
return 'simplified_household_based_allowance';
}
} else if ($this->container->getParameter('household_based_allowance')) {
return 'household_based_allowance';
} else {
return 'cotisation_profile';
}
}
} }
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