Commit eec85c3d by Yvon Kerdoncuff

Merge branch '7977-cotis-minimum-by-share' into 'develop'

ssa: add a cotisation minimum by shares

See merge request !144
parents e2c90d3a bfc3a0fd
......@@ -334,7 +334,10 @@ class AdherentAdmin extends AbstractAdmin
$minCotisationAmount = $em->getRepository(GlobalParameter::class)
->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
$formMapper
......@@ -563,9 +566,27 @@ class AdherentAdmin extends AbstractAdmin
// check cotisation amount above minimum if activated
$minCotisationAmount = $em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_COTISATION_MINIMUM);
if (null !== $minCotisationAmount && $adherent->getCotisationAmount() < (int) $minCotisationAmount) {
$event->getForm()->get('cotisationAmount')->addError(new FormError('Champ invalide'));
if (null !== $minCotisationAmount) {
// 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
......
......@@ -69,6 +69,10 @@ class GlobalParameter
const SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT = 'SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT';
const SSA_HOUSEHOLD_COTISATION_MINIMUM = 'SSA_HOUSEHOLD_COTISATION_MINIMUM';
const ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR = 'ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR';
const SSA_HOUSEHOLD_WITH_QUARTIER = 'SSA_HOUSEHOLD_WITH_QUARTIER';
const SSA_HOUSEHOLD_QUARTIER_LIST_VALUES = 'SSA_HOUSEHOLD_QUARTIER_LIST_VALUES';
const SSA_HOUSEHOLD_WITH_SUBTERRITORY = 'SSA_HOUSEHOLD_WITH_SUBTERRITORY';
const SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE = 'SSA_HOUSEHOLD_COTIS_MINIMUM_BY_SHARE';
const GEOLOC_WITH_QUARTIER = 'GEOLOC_WITH_QUARTIER';
const GEOLOC_QUARTIER_LIST_VALUES = 'GEOLOC_QUARTIER_LIST_VALUES';
const GEOLOC_WITH_SUBTERRITORY = 'GEOLOC_WITH_SUBTERRITORY';
......
<?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 minimum de cotisation par part plutôt que par foyer. Une part est un montant correspondant à la valeur de SSA_HOUSEHOLD_BASE_AMOUNT, et on calcule le nombre de parts entières dans le montant d\'allocation prévu (avant application éventuelle de SSA_FORCE_ALLOCATION_AMOUNT ou SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT). Le minimum est alors SSA_HOUSEHOLD_COTISATION_MINIMUM * nb de parts.', 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
}
/**
* Second method to calculate allowance:
* allowance based on user's household.
* Calculate & return allowance value in household mode.
*
* Rules are as follow:
* - [SSA_HOUSEHOLD_BASE_AMOUNT] emlc for the first person in user's household
......@@ -185,21 +184,12 @@ class TAVCotisationUtils
* - 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
*
* @param Adherent $adherent (by ref)
* @param Adherent $adherent
*/
public function calculateAllowanceAccordingToHousehold(&$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;
}
public function getCalculatedHouseholdAllowanceValue($adherent) {
$adultsCount = $adherent->getHouseholdAdultCount();
if ($adultsCount == null) {
return;
return null;
}
// base allowance, for the first adult
......@@ -239,10 +229,38 @@ class TAVCotisationUtils
$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 returned in case of missing necessary param: exit
if ($mlcAllowanceAmount === null) {
return;
}
// Apply cap if activated in configuration
$maxAllocationAmount = $this->em->getRepository(GlobalParameter::class)
->val(GlobalParameter::SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT);
// Apply cap if activated in configuration
if (null !== $maxAllocationAmount && 0 !== 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