Commit 6b224702 by Damien Moulard

calculate allocation with simplified household process

parent 011398af
......@@ -131,7 +131,7 @@ services:
class: App\Utils\TAVCotisationUtils
autowire: false
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:
class: App\Utils\PaymentUtils
......
......@@ -90,7 +90,7 @@ class FluxController extends AbstractController
SessionInterface $session,
Environment $templating,
OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils,
TAVCotisationUtils $tavCotisationUtils,
TokenGeneratorInterface $tokenGenerator,
ValidatorInterface $validator,
CsrfTokenManagerInterface $tokenManager,
......@@ -107,7 +107,7 @@ class FluxController extends AbstractController
$this->tokenGenerator = $tokenGenerator;
$this->validator = $validator;
$this->tokenManager = $tokenManager;
$this->tavCotisationsUtils = $tavCotisationsUtils;
$this->tavCotisationUtils = $tavCotisationUtils;
$this->userManager = $userManager;
$this->router = $router;
}
......
......@@ -130,19 +130,22 @@ class UserAdherentController extends FluxController
private function paiementCotisTavValidation($flux) {
$destinataire = $flux->getDestinataire();
if($reason = $this->tavCotisationsUtils->preventCotisationDuplication($destinataire)) {
if($reason = $this->tavCotisationUtils->preventCotisationDuplication($destinataire)) {
return $reason;
}
// 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();
if (
is_null($cotisationAmount)
|| is_null($destinataire->getHouseholdAdultCount()) && !$this->getParameter('simplified_household_based_allowance')
|| is_null($destinataire->getHouseholdCount()) && $this->getParameter('simplified_household_based_allowance')
) {
// Use ProfilDeCotisation if set & conditions for simplified_household_based_allowance not met
if ((is_null($cotisationAmount) || is_null($destinataire->getHouseholdCount())) && is_null($destinataire->getProfilDeCotisation())) {
return "Opération impossible : votre profil est incomplet, informations de cotisation manquantes. Veuillez contacter un administrateur.";
}
} 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.";
}
} else {
......@@ -193,12 +196,20 @@ class UserAdherentController extends FluxController
'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->operationUtils->executeOperations($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->addFlash(
......
......@@ -205,7 +205,7 @@ class UserComptoirController extends FluxController
$flux = $form->getData();
// Look for existing cotisation
if ($reason = $this->tavCotisationsUtils->preventCotisationDuplication($flux->getDestinataire())) {
if ($reason = $this->tavCotisationUtils->preventCotisationDuplication($flux->getDestinataire())) {
$this->addFlash(
'error',
$this->translator->trans($reason)
......@@ -216,16 +216,15 @@ class UserComptoirController extends FluxController
$destinataire = $flux->getDestinataire();
if ($this->getParameter('household_based_allowance') == true) {
/* Process: allowance based on household */
$allocationMethod = $this->tavCotisationUtils->getAppropriateAllocationMethod($destinataire);
// 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();
// Verifications
if (
is_null($cotisationAmount)
|| is_null($destinataire->getHouseholdAdultCount()) && !$this->getParameter('simplified_household_based_allowance')
|| is_null($destinataire->getHouseholdCount()) && $this->getParameter('simplified_household_based_allowance')
) {
if (is_null($cotisationAmount) || is_null($destinataire->getHouseholdCount()) ) {
$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.")
......@@ -235,12 +234,32 @@ class UserComptoirController extends FluxController
}
if (is_null($destinataire->getAllocationAmount())) {
if ($this->getParameter('simplified_household_based_allowance') == true) {
$this->tavCotisationUtils->calculateAllowanceAccordingToHouseholdSimplified($destinataire);
} else {
$this->tavCotisationUtils->calculateAllowanceAccordingToHousehold($destinataire);
$this->em->persist($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);
}
......@@ -248,8 +267,8 @@ class UserComptoirController extends FluxController
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
// Apply cotisation rate, create new flux
$this->tavCotisationsUtils->applyHouseholdAllowance($flux);
// Create new flux based on difference with cotisation amount
$this->tavCotisationUtils->applyHouseholdAllowance($flux);
} else {
/* Process: allowance based on cotisation profile with cotisation rate */
$profile = $destinataire->getProfilDeCotisation();
......@@ -270,7 +289,7 @@ class UserComptoirController extends FluxController
$this->operationUtils->executeOperations($flux);
// Apply cotisation rate, create new flux
$this->tavCotisationsUtils->applyTauxCotisation($flux);
$this->tavCotisationUtils->applyTauxCotisation($flux);
}
$this->em->flush();
......
......@@ -24,7 +24,7 @@ class PaymentStatusExtension implements ExtensionInterface
private $serializer;
private $userManager;
private $operationUtils;
private $tavCotisationsUtils;
private $tavCotisationUtils;
private $container;
private $paymentUtils;
......@@ -39,7 +39,7 @@ class PaymentStatusExtension implements ExtensionInterface
SerializerInterface $serializer,
UserManagerInterface $userManager,
OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils,
TAVCotisationUtils $tavCotisationUtils,
ContainerInterface $container,
PaymentUtils $paymentUtils
) {
......@@ -48,7 +48,7 @@ class PaymentStatusExtension implements ExtensionInterface
$this->serializer = $serializer;
$this->userManager = $userManager;
$this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils;
$this->tavCotisationUtils = $tavCotisationUtils;
$this->container = $container;
$this->paymentUtils = $paymentUtils;
}
......
......@@ -37,7 +37,21 @@ class AchatMonnaieFormType extends FluxFormType
if ($this->container->getParameter('tav_env')) {
$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();
if (null != $cosisationMontant) {
$montant = $cosisationMontant;
......
......@@ -24,7 +24,14 @@ class EncaisserCotisationAdherentFormType extends VenteEmlcAdherentFormType
foreach ($adherents as $adh) {
$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();
} else if (!$this->container->getParameter('household_based_allowance') && !is_null($adh->getProfilDeCotisation())) {
$montant = $adh->getProfilDeCotisation()->getMontant();
......
......@@ -27,7 +27,7 @@ class PaymentUtils
private $serializer;
private $userManager;
private $operationUtils;
private $tavCotisationsUtils;
private $tavCotisationUtils;
private $container;
/**
......@@ -38,14 +38,14 @@ class PaymentUtils
SerializerInterface $serializer,
UserManagerInterface $userManager,
OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils,
TAVCotisationUtils $tavCotisationUtils,
ContainerInterface $container
) {
$this->em = $em;
$this->serializer = $serializer;
$this->userManager = $userManager;
$this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils;
$this->tavCotisationUtils = $tavCotisationUtils;
$this->container = $container;
}
......@@ -248,11 +248,13 @@ class PaymentUtils
$this->operationUtils->executeOperations($flux);
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
if ($this->container->getParameter('household_based_allowance')) {
$this->tavCotisationsUtils->applyHouseholdAllowance($flux);
if ($this->container->getParameter('household_based_allowance') || $this->container->getParameter('simplified_household_based_allowance')) {
$this->tavCotisationUtils->applyHouseholdAllowance($flux);
} else {
$this->tavCotisationsUtils->applyTauxCotisation($flux);
$this->tavCotisationUtils->applyTauxCotisation($flux);
}
}
}
......
......@@ -16,21 +16,25 @@ use App\Repository\PaymentRepository;
use App\Utils\CustomEntityManager;
use Payum\Core\Request\GetHumanStatus;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TAVCotisationUtils
{
private $em;
private $security;
private $operationUtils;
private $container;
public function __construct (
CustomEntityManager $em,
Security $security,
OperationUtils $operationUtils
OperationUtils $operationUtils,
ContainerInterface $container
) {
$this->em = $em;
$this->security = $security;
$this->operationUtils = $operationUtils;
$this->container = $container;
}
/**
......@@ -401,4 +405,30 @@ class TAVCotisationUtils
}
$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