Commit 9ea86c09 by Damien Moulard

ssa: add a cotisation minimum by shares

parent 9d4bb669
...@@ -334,7 +334,10 @@ class AdherentAdmin extends AbstractAdmin ...@@ -334,7 +334,10 @@ class AdherentAdmin extends AbstractAdmin
$minCotisationAmount = $em->getRepository(GlobalParameter::class) $minCotisationAmount = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_COTISATION_MINIMUM); ->val(GlobalParameter::SSA_HOUSEHOLD_COTISATION_MINIMUM);
$minCotisationMsg = (null !== $minCotisationAmount) ? "Montant minimum : {$minCotisationAmount}€ par foyer." : ''; $minimumByShare = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE);
$minGranularity = ('true' === $minimumByShare) ? 'part' : 'foyer';
$minCotisationMsg = (null !== $minCotisationAmount) ? "Montant minimum : {$minCotisationAmount}€ par {$minGranularity}." : '';
// Add cotisation info // Add cotisation info
$formMapper $formMapper
...@@ -563,9 +566,27 @@ class AdherentAdmin extends AbstractAdmin ...@@ -563,9 +566,27 @@ class AdherentAdmin extends AbstractAdmin
// check cotisation amount above minimum if activated // check cotisation amount above minimum if activated
$minCotisationAmount = $em->getRepository(GlobalParameter::class) $minCotisationAmount = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_COTISATION_MINIMUM); ->val(GlobalParameter::SSA_HOUSEHOLD_COTISATION_MINIMUM);
if (null !== $minCotisationAmount && $adherent->getCotisationAmount() < (int) $minCotisationAmount) { if (null !== $minCotisationAmount) {
$event->getForm()->get('cotisationAmount')->addError(new FormError('Champ invalide')); // if minimum by share is activated
$minimumByShare = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE);
if ('true' === $minimumByShare) {
$cotisationBaseAmount = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_BASE_AMOUNT);
$calculatedAllocationAmount = $this->tavCotisationUtils->getCalculatedHouseholdAllowanceValue($adherent);
$sharesNb = intdiv($calculatedAllocationAmount, $cotisationBaseAmount);
$minAmountByShares = (int) $minCotisationAmount * $sharesNb;
if ($adherent->getCotisationAmount() < $minAmountByShares) {
$event->getForm()->get('cotisationAmount')->addError(new FormError("Montant invalide : le minimum est de {$minAmountByShares}€"));
}
} else if ($adherent->getCotisationAmount() < (int) $minCotisationAmount) {
$event->getForm()->get('cotisationAmount')->addError(new FormError('Montant invalide'));
}
} }
// try to fix balance if required // try to fix balance if required
......
...@@ -72,6 +72,7 @@ class GlobalParameter ...@@ -72,6 +72,7 @@ class GlobalParameter
const SSA_HOUSEHOLD_WITH_QUARTIER = 'SSA_HOUSEHOLD_WITH_QUARTIER'; const SSA_HOUSEHOLD_WITH_QUARTIER = 'SSA_HOUSEHOLD_WITH_QUARTIER';
const SSA_HOUSEHOLD_QUARTIER_LIST_VALUES = 'SSA_HOUSEHOLD_QUARTIER_LIST_VALUES'; const SSA_HOUSEHOLD_QUARTIER_LIST_VALUES = 'SSA_HOUSEHOLD_QUARTIER_LIST_VALUES';
const SSA_HOUSEHOLD_WITH_SUBTERRITORY = 'SSA_HOUSEHOLD_WITH_SUBTERRITORY'; const SSA_HOUSEHOLD_WITH_SUBTERRITORY = 'SSA_HOUSEHOLD_WITH_SUBTERRITORY';
const SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE = 'SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE';
/** /**
* @var \Ramsey\Uuid\UuidInterface * @var \Ramsey\Uuid\UuidInterface
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250417105302 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql("INSERT INTO global_parameter (id, name, description, value, mandatory) VALUES (UUID(), 'SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE', 'Si la valeur est à true et que SSA_HOUSEHOLD_COTISATION_MINIMUM est défini, active un mode de cotisation par part plutôt que par foyer. La part correspond à la valeur de SSA_HOUSEHOLD_BASE_AMOUNT.', null, '0')");
}
public function down(Schema $schema) : void
{
$this->addSql("DELETE FROM global_parameter where name='SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE'");
// this down() migration is auto-generated, please modify it to your needs
}
}
...@@ -171,8 +171,7 @@ class TAVCotisationUtils ...@@ -171,8 +171,7 @@ class TAVCotisationUtils
} }
/** /**
* Second method to calculate allowance: * Calculate & return allowance value in household mode.
* allowance based on user's household.
* *
* Rules are as follow: * Rules are as follow:
* - [SSA_HOUSEHOLD_BASE_AMOUNT] emlc for the first person in user's household * - [SSA_HOUSEHOLD_BASE_AMOUNT] emlc for the first person in user's household
...@@ -185,21 +184,12 @@ class TAVCotisationUtils ...@@ -185,21 +184,12 @@ class TAVCotisationUtils
* - if SSA_HOUSEHOLD_USE_SHARED_CUSTODY is true: * - if SSA_HOUSEHOLD_USE_SHARED_CUSTODY is true:
* apply a percentage if the child is in shared custody: 25%, 50% or 75% depending on the shared custody arrangement * apply a percentage if the child is in shared custody: 25%, 50% or 75% depending on the shared custody arrangement
* *
* @param Adherent $adherent (by ref) * @param Adherent $adherent
*/ */
public function calculateAllowanceAccordingToHousehold(&$adherent) { public function getCalculatedHouseholdAllowanceValue($adherent) {
// TODO base amounts to param in .env, or in global params ?
$forcedAmount = (int) $this->em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_FORCE_ALLOCATION_AMOUNT);
if($forcedAmount > 0) {
$adherent->setAllocationAmount($forcedAmount);
return;
}
$adultsCount = $adherent->getHouseholdAdultCount(); $adultsCount = $adherent->getHouseholdAdultCount();
if ($adultsCount == null) { if ($adultsCount == null) {
return; return null;
} }
// base allowance, for the first adult // base allowance, for the first adult
...@@ -239,10 +229,38 @@ class TAVCotisationUtils ...@@ -239,10 +229,38 @@ class TAVCotisationUtils
$mlcAllowanceAmount += $childAllowanceAmount; $mlcAllowanceAmount += $childAllowanceAmount;
} }
return $mlcAllowanceAmount;
}
/**
* Second method to calculate allowance:
* allowance based on user's household.
*
* See @getCalculatedHouseholdAllowanceValue() for calculations implentation without verifications
*
* @param Adherent $adherent (by ref)
*/
public function calculateAllowanceAccordingToHousehold(&$adherent) {
// If forced amount activated, set value
$forcedAmount = (int) $this->em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_FORCE_ALLOCATION_AMOUNT);
if($forcedAmount > 0) {
$adherent->setAllocationAmount($forcedAmount);
return;
}
// Calculation
$mlcAllowanceAmount = $this->getCalculatedHouseholdAllowanceValue($adherent);
// Null return in case of missing necessary param: exit
if ($mlcAllowanceAmount === null) {
return;
}
// Apply cap if activated in configuration
$maxAllocationAmount = $this->em->getRepository(GlobalParameter::class) $maxAllocationAmount = $this->em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT); ->val(GlobalParameter::SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT);
// Apply cap if activated in configuration
if (null !== $maxAllocationAmount && 0 !== intval($maxAllocationAmount) && $mlcAllowanceAmount > intval($maxAllocationAmount)) { if (null !== $maxAllocationAmount && 0 !== intval($maxAllocationAmount) && $mlcAllowanceAmount > intval($maxAllocationAmount)) {
$mlcAllowanceAmount = intval($maxAllocationAmount); $mlcAllowanceAmount = intval($maxAllocationAmount);
} }
......
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