Commit bf498140 by Yvon

add fields to fix balance in fiche adherent form for super admin only

parent 924cdf01
...@@ -40,6 +40,7 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType; ...@@ -40,6 +40,7 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
...@@ -359,6 +360,39 @@ class AdherentAdmin extends AbstractAdmin ...@@ -359,6 +360,39 @@ class AdherentAdmin extends AbstractAdmin
]) ])
->end() ->end()
->end(); ->end();
//Add form part allowing super admin to fix balance
if($this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance')
&& $this->security->isGranted('ROLE_SUPER_ADMIN')) {
$formMapper
->tab('General')
->with('Informations de cotisation')
->add('fixedBalance', TextType::class, [
'label' => "Corriger le solde suite à une erreur de cotisation",
'mapped' => false,
'required' => false,
'attr' => [
'autocomplete' => 'off'
]
])
->add('justification', TextType::class, [
'mapped' => false,
'required' => false,
'attr' => [
'autocomplete' => 'off'
]
])
->add('password', PasswordType::class, [
'label' => 'Mot de passe pour corriger le solde',
'mapped' => false,
'required' => false,
'data' => "",
'attr' => [
'autocomplete' => 'off'
]
])
->end()
->end();
}
} }
} }
...@@ -378,8 +412,8 @@ class AdherentAdmin extends AbstractAdmin ...@@ -378,8 +412,8 @@ class AdherentAdmin extends AbstractAdmin
} }
} }
// check cotisation amount
if ($this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance')) { if ($this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance')) {
// check cotisation amount
$adultsCount = $adherent->getHouseholdAdultCount(); $adultsCount = $adherent->getHouseholdAdultCount();
$dependentChildrenCount = count($adherent->getDependentChildren()); $dependentChildrenCount = count($adherent->getDependentChildren());
$minCotisationAmount = 10 + 5 * ( $adultsCount - 1 ) + 5 * $dependentChildrenCount; $minCotisationAmount = 10 + 5 * ( $adultsCount - 1 ) + 5 * $dependentChildrenCount;
...@@ -387,6 +421,26 @@ class AdherentAdmin extends AbstractAdmin ...@@ -387,6 +421,26 @@ class AdherentAdmin extends AbstractAdmin
if ($adherent->getCotisationAmount() < $minCotisationAmount) { if ($adherent->getCotisationAmount() < $minCotisationAmount) {
$event->getForm()->get('cotisationAmount')->addError(new FormError('Le montant minimum est de ' . $minCotisationAmount . '€ (selon les données du foyer indiquées)')); $event->getForm()->get('cotisationAmount')->addError(new FormError('Le montant minimum est de ' . $minCotisationAmount . '€ (selon les données du foyer indiquées)'));
} }
// try to fix balance if required
if($this->security->isGranted('ROLE_SUPER_ADMIN')
&& $event->getForm()->has('fixedBalance')
&& $event->getForm()->get('fixedBalance')->getData()
&& $event->getForm()->get('fixedBalance')->getData() >= 0) {
$password = "cestl@fete";
//this password purpose is to be an additional warning for super admin and
//is not intended to be securely stored as only super admin can use this feature
if ($event->getForm()->get('password')->getData() !== $password) {
$event->getForm()->get('password')->addError(new FormError('Mot de passe incorrect.'));
} elseif(!$event->getForm()->get('justification')->getData()) {
$event->getForm()->get('justification')->addError(new FormError('Merci de justifier cette opération sensible.'));
} else {
$this->tavCotisationUtils->fixBalance(
$adherent, $event->getForm()->get('fixedBalance')->getData(), $event->getForm()->get('justification')->getData()
);
$em->flush();
}
}
} }
}); });
parent::configureFormFields($formMapper); parent::configureFormFields($formMapper);
......
...@@ -238,6 +238,41 @@ class TAVCotisationUtils ...@@ -238,6 +238,41 @@ class TAVCotisationUtils
} }
/** /**
* Method called to create Flux to fix balance (for household based allowance).
*/
public function fixBalance(Adherent $adherent, $fixedBalance, $justification)
{
$balance = $adherent->getEmlcAccount()->getBalance();
$siege = $this->em->getRepository(Siege::class)->getTheOne();
$amountDiff = $fixedBalance - $balance;
if ($amountDiff >= 0) {
//Accroissement du solde
$flux = new CotisationTavReversement();
$flux->setExpediteur($siege);
$flux->setDestinataire($adherent);
$flux->setReference(
"Reversement pour corriger le solde de " . $balance . " MonA à " . $fixedBalance . " MonA : " . $justification
);
} else {
//Réduction du solde
$flux = new CotisationTavPrelevement();
$flux->setExpediteur($adherent);
$flux->setDestinataire($siege);
$flux->setReference(
"Prélèvement pour corriger le solde de " . $balance . " MonA à " . $fixedBalance . " MonA : " . $justification
);
}
$flux->setMontant(abs($amountDiff));
$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);
}
/**
* Get the last cotisation of an adhérent * Get the last cotisation of an adhérent
* *
* @param Adherent $adherent * @param Adherent $adherent
......
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