Commit 4bafcfee by Damien Moulard

dont create second flux for tav cotis if rate is 1

parent 09be2c5b
...@@ -46,48 +46,52 @@ class TAVCotisationUtils ...@@ -46,48 +46,52 @@ class TAVCotisationUtils
/** /**
* Apply the cotisation profile rate to the amount paid * Apply the cotisation profile rate to the amount paid
* and register the complement as a new flux * and register the complement as a new flux (only if rate != 1)
* *
* Warning: EntityManager not flushed here. * Warning: EntityManager not flushed here.
*/ */
public function applyTauxCotisation(Flux $flux) public function applyTauxCotisation(Flux $flux)
{ {
// get the mlc amount the user will receive
$profile = $flux->getDestinataire()->getProfilDeCotisation(); $profile = $flux->getDestinataire()->getProfilDeCotisation();
$cotisationAmount = $profile->getMontant();
$cotisationTaux = $profile->getTauxCotisation(); $cotisationTaux = $profile->getTauxCotisation();
$mlcAmount = round($cotisationAmount * $cotisationTaux);
// don't need to create an other Flux if the rate is 1
// get the difference between what the user paid and what he•she's supposed to receive if ($cotisationTaux != 1) {
$amountDiff = $mlcAmount - $cotisationAmount; // calculate the mlc amount the user will receive
$cotisationAmount = $profile->getMontant();
if ($flux->getExpediteur() instanceof Siege) { $mlcAmount = round($cotisationAmount * $cotisationTaux);
$siege = $flux->getExpediteur();
} else { // get the difference between what the user paid and what he•she's supposed to receive
$siege = $flux->getExpediteur()->getGroupe()->getSiege(); $amountDiff = $mlcAmount - $cotisationAmount;
if ($flux->getExpediteur() instanceof Siege) {
$siege = $flux->getExpediteur();
} else {
$siege = $flux->getExpediteur()->getGroupe()->getSiege();
}
if ($amountDiff > 0) {
// User should receive more than he•she paid: send a new flux to the user to complete its cotisation
$fluxCotis = new TauxCotisationReversement();
$fluxCotis->setExpediteur($siege);
$fluxCotis->setDestinataire($flux->getDestinataire());
$fluxCotis->setMontant($amountDiff);
$fluxCotis->setReference("Reversement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
} else {
// User should receive less than he•she paid: fetch the difference from his account
$fluxCotis = new TauxCotisationPrelevement();
$fluxCotis->setExpediteur($flux->getDestinataire());
$fluxCotis->setDestinataire($siege);
$fluxCotis->setMontant(-$amountDiff);
$fluxCotis->setReference("Prélèvement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
}
$fluxCotis->setOperateur($flux->getOperateur());
$fluxCotis->setRole($flux->getRole());
$fluxCotis->setMoyen(MoyenEnum::MOYEN_EMLC);
$this->em->persist($fluxCotis);
$this->operationUtils->executeOperations($fluxCotis);
} }
if ($amountDiff > 0) {
// User should receive more than he•she paid: send a new flux to the user to complete its cotisation
$fluxCotis = new TauxCotisationReversement();
$fluxCotis->setExpediteur($siege);
$fluxCotis->setDestinataire($flux->getDestinataire());
$fluxCotis->setMontant($amountDiff);
$fluxCotis->setReference("Reversement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
} else {
// User should receive less than he•she paid: fetch the difference from his account
$fluxCotis = new TauxCotisationPrelevement();
$fluxCotis->setExpediteur($flux->getDestinataire());
$fluxCotis->setDestinataire($siege);
$fluxCotis->setMontant(-$amountDiff);
$fluxCotis->setReference("Prélèvement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
}
$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