Commit 50b074b8 by Damien Moulard

add third party financers entities & admin panel

parent 01e27d7a
......@@ -256,6 +256,13 @@ sonata_admin:
- admin.transfert.gerer
- admin.transaction.gerer
- admin.reconversion.gerer
sonata.admin.group.thirdPartyFinancers:
keep_open: false
label: "Tiers financeurs"
label_catalogue: SonataAdminBundle
icon: '<i class="fa fa-handshake-o"></i>'
items:
- admin.thirdPartyFinancers
# sonata.admin.group.helloasso:
# keep_open: false
# on_top: true
......
......@@ -712,6 +712,19 @@ services:
label: "Popups d'information"
public: true
admin.thirdPartyFinancers:
class: App\Admin\ThirdPartyFinancerAdmin
arguments: [~, App\Entity\ThirdPartyFinancer, 'App\Controller\CRUD\CRUDController']
tags:
- name: sonata.admin
manager_type: orm
group: "thirdPartyFinancers"
label: "Liste"
pager_type: "simple"
public: true
calls:
- [ setSecurity, ['@security.helper']]
sonata.media.provider.csv:
class: App\Admin\ImportProvider
tags:
......
<?php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Security\Core\Security;
use App\Entity\Adherent;
/**
* Administration des tiers financeurs.
*
* KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
*/
class ThirdPartyFinancerAdmin extends AbstractAdmin
{
protected $security;
public function setSecurity(Security $security)
{
$this->security = $security;
}
protected function configureFormFields(FormMapper $form): void
{
$thirdPartyFinancer = $this->getSubject();
$form
->with('Tiers Financeur', ['class' => 'col-md-12'])
->add('name', TextType::class, [
'label' => 'Nom :',
'required' => true,
])
->add('fundingAmount', NumberType::class, [
'label' => 'Montant de prise en charge :',
'required' => true,
])
->add('supportedAdherents', EntityType::class, [
'class' => Adherent::class,
'multiple' => true,
'required' => false,
'by_reference' => false,
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Adherent::class)->findbyNoThirdPartyFinancer($thirdPartyFinancer->getId()),
'label' => 'Adhérents soutenus :',
'help' => 'Vous pouvez sélectionner les adhérents qui ne sont pas déjà soutenu par un tiers financeur'
])
->end()
;
}
protected function configureDatagridFilters(DatagridMapper $datagrid): void
{
$datagrid->add('name', null, [
'label' => 'Nom'
]);
}
protected function configureListFields(ListMapper $list): void
{
$list
->addIdentifier('name', null, [
'label' => 'Nom'
])
->addIdentifier('fundingAmount', null, [
'label' => 'Montant de prise en charge'
])
;
}
}
\ No newline at end of file
......@@ -176,6 +176,11 @@ class Adherent extends AccountableObject implements AccountableInterface
*/
private $externalDatedDataCollection;
/**
* @ORM\ManyToOne(targetEntity=ThirdPartyFinancer::class, inversedBy="supportedAdherents")
*/
private $thirdPartyFinancer;
public function __construct()
{
$this->accounts = new ArrayCollection();
......@@ -576,4 +581,16 @@ class Adherent extends AccountableObject implements AccountableInterface
$this->externalDatedDataCollection->removeElement($externalDatedData);
return $this;
}
public function getThirdPartyFinancer(): ?ThirdPartyFinancer
{
return $this->thirdPartyFinancer;
}
public function setThirdPartyFinancer(?ThirdPartyFinancer $thirdPartyFinancer): self
{
$this->thirdPartyFinancer = $thirdPartyFinancer;
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\ThirdPartyAllocationFundingRepository;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ThirdPartyAllocationFundingRepository::class)
*/
class ThirdPartyAllocationFunding
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="float")
*/
private $amount;
/**
* @ORM\ManyToOne(targetEntity=Adherent::class)
*/
private $adherent;
/**
* @ORM\ManyToOne(targetEntity=ThirdPartyFinancer::class, inversedBy="thirdPartyAllocationFundings")
* @ORM\JoinColumn(nullable=false)
*/
private $thirdPartyFinancer;
/**
* @ORM\OneToOne(targetEntity=Flux::class, cascade={"persist", "remove"})
*/
private $cotisationFlux;
/**
* @ORM\OneToOne(targetEntity=Flux::class, cascade={"persist", "remove"})
*/
private $allocationFlux;
/**
* @ORM\Column(type="string", length=255)
*/
private $reference;
public function getId(): ?int
{
return $this->id;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getAdherent(): ?Adherent
{
return $this->adherent;
}
public function setAdherent(?Adherent $adherent): self
{
$this->adherent = $adherent;
return $this;
}
public function getThirdPartyFinancer(): ?ThirdPartyFinancer
{
return $this->thirdPartyFinancer;
}
public function setThirdPartyFinancer(?ThirdPartyFinancer $thirdPartyFinancer): self
{
$this->thirdPartyFinancer = $thirdPartyFinancer;
return $this;
}
public function getCotisationFlux(): ?Flux
{
return $this->cotisationFlux;
}
public function setCotisationFlux(?Flux $cotisationFlux): self
{
$this->cotisationFlux = $cotisationFlux;
return $this;
}
public function getAllocationFlux(): ?Flux
{
return $this->allocationFlux;
}
public function setAllocationFlux(?Flux $allocationFlux): self
{
$this->allocationFlux = $allocationFlux;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
}
<?php
namespace App\Entity;
use App\Entity\EntityTrait\GeolocEntityTrait;
use App\Repository\ThirdPartyFinancerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ThirdPartyFinancerRepository::class)
*/
class ThirdPartyFinancer
{
use GeolocEntityTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="float")
*/
private $fundingAmount;
/**
* @ORM\OneToMany(targetEntity=Adherent::class, mappedBy="thirdPartyFinancer")
*/
private $supportedAdherents;
/**
* @ORM\OneToMany(targetEntity=ThirdPartyAllocationFunding::class, mappedBy="thirdPartyFinancer", orphanRemoval=true)
*/
private $thirdPartyAllocationFundings;
public function __construct()
{
$this->supportedAdherents = new ArrayCollection();
$this->thirdPartyAllocationFundings = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getFundingAmount(): ?float
{
return $this->fundingAmount;
}
public function setFundingAmount(float $fundingAmount): self
{
$this->fundingAmount = $fundingAmount;
return $this;
}
/**
* @return Collection<int, Adherent>
*/
public function getSupportedAdherents(): Collection
{
return $this->supportedAdherents;
}
public function addSupportedAdherent(Adherent $supportedAdherent): self
{
if (!$this->supportedAdherents->contains($supportedAdherent)) {
$this->supportedAdherents[] = $supportedAdherent;
$supportedAdherent->setThirdPartyFinancer($this);
}
return $this;
}
public function removeSupportedAdherent(Adherent $supportedAdherent): self
{
if ($this->supportedAdherents->removeElement($supportedAdherent)) {
// set the owning side to null (unless already changed)
if ($supportedAdherent->getThirdPartyFinancer() === $this) {
$supportedAdherent->setThirdPartyFinancer(null);
}
}
return $this;
}
/**
* @return Collection<int, ThirdPartyAllocationFunding>
*/
public function getThirdPartyAllocationFundings(): Collection
{
return $this->thirdPartyAllocationFundings;
}
public function addThirdPartyAllocationFunding(ThirdPartyAllocationFunding $thirdPartyAllocationFunding): self
{
if (!$this->thirdPartyAllocationFundings->contains($thirdPartyAllocationFunding)) {
$this->thirdPartyAllocationFundings[] = $thirdPartyAllocationFunding;
$thirdPartyAllocationFunding->setThirdPartyFinancer($this);
}
return $this;
}
public function removeThirdPartyAllocationFunding(ThirdPartyAllocationFunding $thirdPartyAllocationFunding): self
{
if ($this->thirdPartyAllocationFundings->removeElement($thirdPartyAllocationFunding)) {
// set the owning side to null (unless already changed)
if ($thirdPartyAllocationFunding->getThirdPartyFinancer() === $this) {
$thirdPartyAllocationFunding->setThirdPartyFinancer(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->getName();
}
}
<?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 Version20251217103039 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('CREATE TABLE third_party_allocation_funding (id INT AUTO_INCREMENT NOT NULL, adherent_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', third_party_financer_id INT NOT NULL, cotisation_flux_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', allocation_flux_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', amount DOUBLE PRECISION NOT NULL, reference VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_DBA138125F06C53 (adherent_id), INDEX IDX_DBA13812FFF280D (third_party_financer_id), UNIQUE INDEX UNIQ_DBA1381363D74 (cotisation_flux_id), UNIQUE INDEX UNIQ_DBA13818704443C (allocation_flux_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_general_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE third_party_financer (id INT AUTO_INCREMENT NOT NULL, geoloc_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, funding_amount DOUBLE PRECISION NOT NULL, UNIQUE INDEX UNIQ_C52E80E4EF390162 (geoloc_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_general_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE third_party_allocation_funding ADD CONSTRAINT FK_DBA138125F06C53 FOREIGN KEY (adherent_id) REFERENCES adherent (id)');
$this->addSql('ALTER TABLE third_party_allocation_funding ADD CONSTRAINT FK_DBA13812FFF280D FOREIGN KEY (third_party_financer_id) REFERENCES third_party_financer (id)');
$this->addSql('ALTER TABLE third_party_allocation_funding ADD CONSTRAINT FK_DBA1381363D74 FOREIGN KEY (cotisation_flux_id) REFERENCES flux (id)');
$this->addSql('ALTER TABLE third_party_allocation_funding ADD CONSTRAINT FK_DBA13818704443C FOREIGN KEY (allocation_flux_id) REFERENCES flux (id)');
$this->addSql('ALTER TABLE third_party_financer ADD CONSTRAINT FK_C52E80E4EF390162 FOREIGN KEY (geoloc_id) REFERENCES geoloc (id)');
$this->addSql('ALTER TABLE adherent ADD third_party_financer_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE adherent ADD CONSTRAINT FK_90D3F0602FFF280D FOREIGN KEY (third_party_financer_id) REFERENCES third_party_financer (id)');
$this->addSql('CREATE INDEX IDX_90D3F0602FFF280D ON adherent (third_party_financer_id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE adherent DROP FOREIGN KEY FK_90D3F0602FFF280D');
$this->addSql('ALTER TABLE third_party_allocation_funding DROP FOREIGN KEY FK_DBA13812FFF280D');
$this->addSql('DROP TABLE third_party_allocation_funding');
$this->addSql('DROP TABLE third_party_financer');
$this->addSql('DROP INDEX IDX_90D3F0602FFF280D ON adherent');
$this->addSql('ALTER TABLE adherent DROP third_party_financer_id');
}
}
......@@ -155,4 +155,23 @@ class AdherentRepository extends ServiceEntityRepository
->getResult()
;
}
/**
* @return Adherent[] Returns an array of Adherent objects
*/
public function findbyNoThirdPartyFinancer($thirdPartId)
{
$qb = $this->createQueryBuilder('a');
return $qb
->leftjoin('a.user', 'u')
->where('a.thirdPartyFinancer IS null OR a.thirdPartyFinancer = :thirdPartId')
->andWhere('a.enabled = :enabled')
->setParameter('enabled', true)
->setParameter('thirdPartId', $thirdPartId)
->orderBy('u.lastname', 'ASC')
->getQuery()
->getResult()
;
}
}
<?php
namespace App\Repository;
use App\Entity\ThirdPartyAllocationFunding;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ThirdPartyAllocationFunding>
*
* @method ThirdPartyAllocationFunding|null find($id, $lockMode = null, $lockVersion = null)
* @method ThirdPartyAllocationFunding|null findOneBy(array $criteria, array $orderBy = null)
* @method ThirdPartyAllocationFunding[] findAll()
* @method ThirdPartyAllocationFunding[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ThirdPartyAllocationFundingRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ThirdPartyAllocationFunding::class);
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(ThirdPartyAllocationFunding $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
$this->_em->flush();
}
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(ThirdPartyAllocationFunding $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
$this->_em->flush();
}
}
// /**
// * @return ThirdPartyAllocationFunding[] Returns an array of ThirdPartyAllocationFunding objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?ThirdPartyAllocationFunding
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
<?php
namespace App\Repository;
use App\Entity\ThirdPartyFinancer;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ThirdPartyFinancer>
*
* @method ThirdPartyFinancer|null find($id, $lockMode = null, $lockVersion = null)
* @method ThirdPartyFinancer|null findOneBy(array $criteria, array $orderBy = null)
* @method ThirdPartyFinancer[] findAll()
* @method ThirdPartyFinancer[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ThirdPartyFinancerRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ThirdPartyFinancer::class);
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(ThirdPartyFinancer $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
$this->_em->flush();
}
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(ThirdPartyFinancer $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
$this->_em->flush();
}
}
// /**
// * @return ThirdPartyFinancer[] Returns an array of ThirdPartyFinancer objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?ThirdPartyFinancer
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
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