Commit a91fd19b by Damien Moulard

third party financers fixes

parent 196a95ba
...@@ -50,15 +50,15 @@ class ThirdPartyAllocationFundingAdmin extends AbstractAdmin ...@@ -50,15 +50,15 @@ class ThirdPartyAllocationFundingAdmin extends AbstractAdmin
->addIdentifier('created_at', 'datetime', [ ->addIdentifier('created_at', 'datetime', [
'label' => 'Date' 'label' => 'Date'
]) ])
->addIdentifier('thirdPartyFinancer', null, [
'label' => 'Tiers financeur'
])
->addIdentifier('amount', null, [ ->addIdentifier('amount', null, [
'label' => 'Montant' 'label' => 'Montant de prise en charge'
]) ])
->addIdentifier('adherent', null, [ ->addIdentifier('adherent', null, [
'label' => 'Adhérent' 'label' => 'Adhérent'
]) ])
->addIdentifier('thirdPartyFinancer', null, [
'label' => 'Tiers financeur'
])
->addIdentifier('cotisationFlux.montant', null, [ ->addIdentifier('cotisationFlux.montant', null, [
'label' => 'Montant cotisé' 'label' => 'Montant cotisé'
]) ])
...@@ -75,9 +75,9 @@ class ThirdPartyAllocationFundingAdmin extends AbstractAdmin ...@@ -75,9 +75,9 @@ class ThirdPartyAllocationFundingAdmin extends AbstractAdmin
{ {
return [ return [
'Date' => 'created_at', 'Date' => 'created_at',
'Montant' => 'amount',
'Adhérent' => 'adherent.fullname',
'Tiers financeur' => 'thirdPartyFinancer', 'Tiers financeur' => 'thirdPartyFinancer',
'Montant de prise en charge' => 'amount',
'Adhérent' => 'adherent.fullname',
'Montant cotisé' => 'cotisationFlux.montant', 'Montant cotisé' => 'cotisationFlux.montant',
'Allocation' => 'allocationAmount', 'Allocation' => 'allocationAmount',
'Référence' => 'reference', 'Référence' => 'reference',
......
...@@ -11,6 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; ...@@ -11,6 +11,7 @@ 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\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use App\Form\Type\GeolocFormType;
use App\Entity\Adherent; use App\Entity\Adherent;
/** /**
...@@ -31,7 +32,7 @@ class ThirdPartyFinancerAdmin extends AbstractAdmin ...@@ -31,7 +32,7 @@ class ThirdPartyFinancerAdmin extends AbstractAdmin
{ {
$thirdPartyFinancer = $this->getSubject(); $thirdPartyFinancer = $this->getSubject();
$form $form
->with('Tiers Financeur', ['class' => 'col-md-12']) ->with('Tiers Financeur', ['class' => 'col-md-7'])
->add('name', TextType::class, [ ->add('name', TextType::class, [
'label' => 'Nom :', 'label' => 'Nom :',
'required' => true, 'required' => true,
...@@ -50,6 +51,22 @@ class ThirdPartyFinancerAdmin extends AbstractAdmin ...@@ -50,6 +51,22 @@ class ThirdPartyFinancerAdmin extends AbstractAdmin
'help' => 'Vous pouvez sélectionner les adhérents qui ne sont pas déjà soutenu par un tiers financeur' 'help' => 'Vous pouvez sélectionner les adhérents qui ne sont pas déjà soutenu par un tiers financeur'
]) ])
->end() ->end()
->with('Coordonnées', ['class' => 'col-md-5'])
->add('geoloc', GeolocFormType::class, [
'label' => false,
'required' => true,
'with_geoloc' => false,
'with_latlon' => false,
])
->add('phone', TextType::class, [
'label' => 'Téléphone',
'required' => false,
])
->add('personInChargeName', TextType::class, [
'label' => 'Nom de la personne responsable',
'required' => true,
])
->end()
; ;
} }
......
...@@ -48,6 +48,16 @@ class ThirdPartyFinancer ...@@ -48,6 +48,16 @@ class ThirdPartyFinancer
*/ */
private $thirdPartyAllocationFundings; private $thirdPartyAllocationFundings;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, options={"default": ""})
*/
private $personInChargeName;
public function __construct() public function __construct()
{ {
$this->supportedAdherents = new ArrayCollection(); $this->supportedAdherents = new ArrayCollection();
...@@ -147,4 +157,28 @@ class ThirdPartyFinancer ...@@ -147,4 +157,28 @@ class ThirdPartyFinancer
{ {
return $this->getName(); return $this->getName();
} }
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getPersonInChargeName(): ?string
{
return $this->personInChargeName;
}
public function setPersonInChargeName(string $personInChargeName): self
{
$this->personInChargeName = $personInChargeName;
return $this;
}
} }
...@@ -37,11 +37,15 @@ class GeolocListener ...@@ -37,11 +37,15 @@ class GeolocListener
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr'); $geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
$fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille(); $fullAddress = $entity->getAdresse() . ' ' . $entity->getCpostal() . ' ' . $entity->getVille();
// Query geocoding from complete address // Query geocoding from complete address
$result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress)); try {
if (count($result) > 0) { $result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress));
$coords = $result->first()->getCoordinates(); if (count($result) > 0) {
$entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude()))); $coords = $result->first()->getCoordinates();
$entity->setLon(floatval(str_replace(',', '.', $coords->getLongitude()))); $entity->setLat(floatval(str_replace(',', '.', $coords->getLatitude())));
$entity->setLon(floatval(str_replace(',', '.', $coords->getLongitude())));
}
} catch (\Throwable $th) {
//throw $th;
} }
} }
} }
......
<?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 Version20260114084303 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('ALTER TABLE third_party_financer ADD phone VARCHAR(64) DEFAULT NULL, ADD person_in_charge_name VARCHAR(255) DEFAULT \'\' NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE third_party_financer DROP phone, DROP person_in_charge_name');
}
}
...@@ -129,7 +129,8 @@ class TAVCotisationUtils ...@@ -129,7 +129,8 @@ class TAVCotisationUtils
*/ */
public function applyTauxCotisation(Flux $flux) public function applyTauxCotisation(Flux $flux)
{ {
$profile = $flux->getDestinataire()->getProfilDeCotisation(); $adherent = $flux->getDestinataire();
$profile = $adherent->getProfilDeCotisation();
$cotisationTaux = $profile->getTauxCotisation(); $cotisationTaux = $profile->getTauxCotisation();
// don't need to create an other Flux if the rate is 1 // don't need to create an other Flux if the rate is 1
...@@ -148,16 +149,23 @@ class TAVCotisationUtils ...@@ -148,16 +149,23 @@ class TAVCotisationUtils
} }
if ($amountDiff > 0) { if ($amountDiff > 0) {
// User should receive more than he•she paid: send a new flux to the user to complete its cotisation // User should receive more than he•she paid: send a new flux to the user to complete their cotisation
$fluxCotis = new CotisationTavReversement(); $fluxCotis = new CotisationTavReversement();
$fluxCotis->setExpediteur($siege); $fluxCotis->setExpediteur($siege);
$fluxCotis->setDestinataire($flux->getDestinataire()); $fluxCotis->setDestinataire($adherent);
$fluxCotis->setMontant($amountDiff); $fluxCotis->setMontant($amountDiff);
$fluxCotis->setReference("Reversement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux); $fluxCotis->setReference("Reversement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
// Create third party funding instance if required
if ($adherent->getThirdPartyFinancer() !== null) {
// $this->createThirdPartyAllocationFunding($adherent, $fluxCotis);
$this->createThirdPartyAllocationFunding($adherent, $flux, $fluxCotis, 100, $cotisationAmount, $amountDiff);
}
} else { } else {
// User should receive less than he•she paid: fetch the difference from his account // User should receive less than he•she paid: fetch the difference from his account
$fluxCotis = new CotisationTavPrelevement(); $fluxCotis = new CotisationTavPrelevement();
$fluxCotis->setExpediteur($flux->getDestinataire()); $fluxCotis->setExpediteur($adherent);
$fluxCotis->setDestinataire($siege); $fluxCotis->setDestinataire($siege);
$fluxCotis->setMontant(-$amountDiff); $fluxCotis->setMontant(-$amountDiff);
$fluxCotis->setReference("Prélèvement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux); $fluxCotis->setReference("Prélèvement cotisation après paiement de " . $cotisationAmount . "€ et application du taux " . $cotisationTaux);
...@@ -351,25 +359,8 @@ class TAVCotisationUtils ...@@ -351,25 +359,8 @@ class TAVCotisationUtils
$fluxCotis->setReference($fluxCotisRef); $fluxCotis->setReference($fluxCotisRef);
// Create third party funding instance if required // Create third party funding instance if required
if ($adherent->getThirdPartyFinancer() !== null) { if ($adherent->getThirdPartyFinancer() !== null) {
$thirdparty = $adherent->getThirdPartyFinancer(); $this->createThirdPartyAllocationFunding($adherent, $flux, $fluxCotis, $mlcAllowanceAmount, $cotisationAmount, $amountDiff);
$fundingAmount = $thirdparty->getFundingAmount();
$thirdPartyAllocationFunding = new ThirdPartyAllocationFunding();
$thirdPartyAllocationFunding->setThirdPartyFinancer($thirdparty);
$thirdPartyAllocationFunding->setAmount($fundingAmount);
$thirdPartyAllocationFunding->setAdherent($adherent);
$thirdPartyAllocationFunding->setCotisationFlux($flux);
$thirdPartyAllocationFunding->setAllocationFlux($fluxCotis);
$thirdPartyAllocationFunding->setAllocationAmount($mlcAllowanceAmount);
$ref = "Prise en charge du tiers financeur $thirdparty d'un montant de " . $fundingAmount . "€ pour l'adhérent " . $adherent . ", pour sa cotisation de " . $cotisationAmount . "€ avec reversement de $amountDiff MonA";
$thirdPartyAllocationFunding->setReference($ref);
$this->em->persist($thirdPartyAllocationFunding);
// Update allocation flux reference to include third party
$fluxCotisRef .= " ; dont prise en charge de " . $fundingAmount . "€ par le tiers financeur $thirdparty";
$fluxCotis->setReference($fluxCotisRef);
} }
} else { } else {
// User should receive less than he•she paid: fetch the difference from his account // User should receive less than he•she paid: fetch the difference from his account
...@@ -389,6 +380,38 @@ class TAVCotisationUtils ...@@ -389,6 +380,38 @@ class TAVCotisationUtils
} }
/** /**
* Create the ThirdPartyAllocationFunding from adherent and cotisation flux data
*/
private function createThirdPartyAllocationFunding(
$adherent,
$flux,
&$fluxCotis,
$mlcAllowanceAmount,
$cotisationAmount,
$amountDiff
) {
$thirdparty = $adherent->getThirdPartyFinancer();
$fundingAmount = $thirdparty->getFundingAmount();
$thirdPartyAllocationFunding = new ThirdPartyAllocationFunding();
$thirdPartyAllocationFunding->setThirdPartyFinancer($thirdparty);
$thirdPartyAllocationFunding->setAmount($fundingAmount);
$thirdPartyAllocationFunding->setAdherent($adherent);
$thirdPartyAllocationFunding->setCotisationFlux($flux);
$thirdPartyAllocationFunding->setAllocationFlux($fluxCotis);
$thirdPartyAllocationFunding->setAllocationAmount($mlcAllowanceAmount);
$ref = "Prise en charge du tiers financeur $thirdparty d'un montant de " . $fundingAmount . "€ pour l'adhérent " . $adherent . ", pour sa cotisation de " . $cotisationAmount . "€ avec reversement de $amountDiff MonA";
$thirdPartyAllocationFunding->setReference($ref);
$this->em->persist($thirdPartyAllocationFunding);
// Update allocation flux reference to include third party
$fluxCotisRef = $fluxCotis->getReference();
$fluxCotisRef .= " ; dont prise en charge de " . $fundingAmount . "€ par le tiers financeur $thirdparty";
$fluxCotis->setReference($fluxCotisRef);
}
/**
* Method called to create Flux based on allowance amount (for household based allowance). * Method called to create Flux based on allowance amount (for household based allowance).
*/ */
public function withdrawDownToTheCeiling(Adherent $adherent) public function withdrawDownToTheCeiling(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