Commit 45fbd986 by Damien Moulard

WIP: create new method to distribute TAV allowance, based on household

parent 265e0af4
......@@ -125,7 +125,7 @@ class ProfilDeCotisation
}
/**
* setContacts.
* setBeneficiaires.
*
* @param [type] $beneficiaires [description]
*/
......
......@@ -103,34 +103,71 @@ class TAVCotisationUtils
*
* Rules are as follow:
* - 150 emlc for the first person in user's household
* - 75 emlc for each other
* - in case of shared custody for a dependent child, apply a percentage on the "75 emlc" amount for this child:
* - 75 emlc for each other adult
* - 75 emlc amount for each dependant child, with a percentage applied if the child is in shared custody:
* 25%, 50% or 75% depending on the shared custody arrangement
*
* Once the full amount is calculated, cap user's balance.
* User account balance is capped at twice the amount previously calculated.
*/
public function applyAllowanceAccordingToHousehold() {
$profile = $flux->getDestinataire()->getProfilDeCotisation();
public function applyAllowanceAccordingToHousehold(Flux $flux) {
$adherent = $flux->getDestinataire();
$profile = $adherent->getProfilDeCotisation();
$cotisationAmount = $profile->getMontant();
// TODO amounts param
// base allowance, for one adult
$mlcAllowanceAmount = 150;
// $mlcAllowanceAmount += 75 * NombreDAdultesACharge;
// for each enfant à charge
// $childAllowanceAmount = 75;
// if (custody != null)
// $childAllowanceAmount = $childAllowanceAmount * custody
//
// $mlcAllowanceAmount += $childAllowanceAmount;
// // Apply cap
// $currentBalance = UserCurrentBalance;
// if ($currentBalance + $mlcAllowanceAmount >= 2 * $mlcAllowanceAmount)
// $capped = true
// $mlcAllowanceAmount = 2 * $mlcAllowanceAmount - $currentBalance // give difference to reach max balance
// create flux
$adultsCount = $adherent->getHouseholdAdultCount();
if ($adultsCount == null) {
// error
}
// increment for each other adult in the household
$mlcAllowanceAmount += 75 * ($adultsCount - 1);
// increment allowance for each dependant child, depending on the shared custody arrangement
$dependentChildren = $adherent->getDependentChildren();
foreach ($dependentChildren as $child) {
$childAllowanceAmount = 75;
if ($child->sharedCustodyPercentage != null) {
$childAllowanceAmount = $childAllowanceAmount * $child->sharedCustodyPercentage;
}
$mlcAllowanceAmount += $childAllowanceAmount;
}
// Apply cap
$currentBalance = $adherent->getEmlcAccount()->getBalance();
$capped = false;
if ($currentBalance + $mlcAllowanceAmount >= 2 * $mlcAllowanceAmount) {
// Allow difference to reach max balance
$mlcAllowanceAmount = 2 * $mlcAllowanceAmount - $currentBalance;
$capped = true;
}
// Create Flux
if ($flux->getExpediteur() instanceof Siege) {
$siege = $flux->getExpediteur();
} else {
$siege = $flux->getExpediteur()->getGroupe()->getSiege();
}
// TODO new flux entity ? use same entities ?
$fluxCotis = new TauxCotisationReversement();
$fluxCotis->setExpediteur($siege);
$fluxCotis->setDestinataire($flux->getDestinataire());
$fluxCotis->setMontant($amountDiff);
$fluxCotis->setReference("Reversement allocation après paiement de " . $cotisationAmount . "€ et calcul en fonction du foyer.");
$fluxCotis->setOperateur($flux->getOperateur());
$fluxCotis->setRole($flux->getRole());
$fluxCotis->setMoyen(MoyenEnum::MOYEN_EMLC);
$this->em->persist($fluxCotis);
$this->operationUtils->executeOperations($fluxCotis);
}
/**
......
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