Commit 4314a749 by Damien Moulard

Merge branch '3569-profil-de-cotisation' into 'develop'

3569 profil de cotisation

See merge request cooperatic/kohinos-tav!10
parents d1437332 f9c2fa48
...@@ -201,6 +201,7 @@ sonata_admin: ...@@ -201,6 +201,7 @@ sonata_admin:
roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_ADHERENT_GERER_ALL', 'ROLE_ADMIN_ADHERENT_GERER_CREATE'] roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_ADHERENT_GERER_ALL', 'ROLE_ADMIN_ADHERENT_GERER_CREATE']
- admin.adherent.gerer - admin.adherent.gerer
- admin.adherent.cotisations - admin.adherent.cotisations
- admin.adherent.profilsdecotisation
sonata.admin.group.prestataire: sonata.admin.group.prestataire:
keep_open: false keep_open: false
label: "Prestataires" label: "Prestataires"
......
...@@ -300,6 +300,16 @@ services: ...@@ -300,6 +300,16 @@ services:
- [ setSecurity, ['@security.helper']] - [ setSecurity, ['@security.helper']]
- [ setOperationUtils, ['@app.utils.operations']] - [ setOperationUtils, ['@app.utils.operations']]
admin.adherent.profilsdecotisation:
class: App\Admin\ProfilDeCotisationAdmin
arguments: [~, App\Entity\ProfilDeCotisation, ~]
tags:
- name: sonata.admin
manager_type: orm
group: "Adherent"
label: "Profils De Cotisation"
public: true
admin.prestataire.gerer: admin.prestataire.gerer:
class: App\Admin\PrestataireAdmin class: App\Admin\PrestataireAdmin
arguments: [~, App\Entity\Prestataire, App\Controller\PrestataireAdminController] arguments: [~, App\Entity\Prestataire, App\Controller\PrestataireAdminController]
......
...@@ -9,6 +9,7 @@ use App\Entity\Geoloc; ...@@ -9,6 +9,7 @@ use App\Entity\Geoloc;
use App\Entity\Groupe; use App\Entity\Groupe;
use App\Entity\User; use App\Entity\User;
use App\Entity\Usergroup; use App\Entity\Usergroup;
use App\Entity\ProfilDeCotisation;
use App\Enum\CurrencyEnum; use App\Enum\CurrencyEnum;
use App\Events\MLCEvents; use App\Events\MLCEvents;
use App\Exporter\CustomDoctrineORMQuerySourceIterator; use App\Exporter\CustomDoctrineORMQuerySourceIterator;
...@@ -165,6 +166,27 @@ class AdherentAdmin extends AbstractAdmin ...@@ -165,6 +166,27 @@ class AdherentAdmin extends AbstractAdmin
->end() ->end()
; ;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$formMapper
->tab('General')
->with('Profil de cotisation', ['class' => 'col-md-5'])
->add('profilDeCotisation', ChoiceType::class, [
'required' => false,
'label' => 'Choix du profil : ',
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(ProfilDeCotisation::class)->findAll(),
'empty_data' => null,
'choice_label' => function ($choice, $key, $value) {
if (null === $choice) {
return '';
}
return $choice->__toString();
}
])
->end()
->end();
}
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager(); $em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$formMapper->getFormBuilder()->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($em) { $formMapper->getFormBuilder()->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($em) {
$adherent = $event->getData(); $adherent = $event->getData();
......
<?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\Form\Type\DateTimeRangePickerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use App\Enum\CurrencyEnum;
/**
* Administration des profils de cotisation.
*
* KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
*/
class ProfilDeCotisationAdmin extends AbstractAdmin
{
protected $baseRouteName = 'profilcotisation';
protected $baseRoutePattern = 'profilcotisation';
protected $datagridValues = [
'_sort_order' => 'DESC',
'_sort_by' => 'createdAt',
];
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
->with('Profil', ['class' => 'col-md-12'])
->add('montant', NumberType::class, [
'label' => 'Montant'
])
->add('tauxCotisation', NumberType::class, [
'label' => 'Taux de cotisation'
])
->end()
;
parent::configureFormFields($formMapper);
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('createdAt', 'doctrine_orm_datetime_range', [
'field_type' => DateTimeRangePickerType::class,
'label' => 'Date de création',
])
->add('updatedAt', 'doctrine_orm_datetime_range', [
'field_type' => DateTimeRangePickerType::class,
'label' => 'Date de mise à jour',
])
;
}
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper
->addIdentifier('montant', FieldDescriptionInterface::TYPE_CURRENCY, [
'label' => 'Montant',
'currency' => CurrencyEnum::getCode(CurrencyEnum::CURRENCY_EURO),
'sortable' => true
])
->addIdentifier('tauxCotisation', null, [
'label' => 'Taux de cotisation',
'sortable' => true
])
->add('createdAt', 'date', [
'pattern' => 'dd/MM/YYYY HH:mm',
'label' => 'Crée le',
])
->add('updatedAt', 'date', [
'pattern' => 'dd/MM/YYYY HH:mm',
'label' => 'Mis à jour le',
])
->add('_action', null, [
'actions' => ['edit' => []],
])
;
}
}
...@@ -89,7 +89,7 @@ class Adherent extends AccountableObject implements AccountableInterface ...@@ -89,7 +89,7 @@ class Adherent extends AccountableObject implements AccountableInterface
* @var ProfilDeCotisation * @var ProfilDeCotisation
* *
* @ORM\ManyToOne(targetEntity="ProfilDeCotisation", cascade={"persist"}, inversedBy="beneficiaires") * @ORM\ManyToOne(targetEntity="ProfilDeCotisation", cascade={"persist"}, inversedBy="beneficiaires")
* @ORM\JoinColumn(name="profildecotisation_id", referencedColumnName="id", nullable=true) * @ORM\JoinColumn(name="profildecotisation_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/ */
private $profilDeCotisation; private $profilDeCotisation;
...@@ -253,7 +253,7 @@ class Adherent extends AccountableObject implements AccountableInterface ...@@ -253,7 +253,7 @@ class Adherent extends AccountableObject implements AccountableInterface
/** /**
* @return ProfilDeCotisation * @return ProfilDeCotisation
*/ */
public function getProfilDeCotisation(): ProfilDeCotisation public function getProfilDeCotisation(): ?ProfilDeCotisation
{ {
return $this->profilDeCotisation; return $this->profilDeCotisation;
} }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\NameSlugContentEntityTrait;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity; use Gedmo\Timestampable\Traits\TimestampableEntity;
...@@ -19,9 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert; ...@@ -19,9 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert;
*/ */
class ProfilDeCotisation class ProfilDeCotisation
{ {
use NameSlugContentEntityTrait;
use TimestampableEntity; use TimestampableEntity;
use EnablableEntityTrait;
/** /**
* @var \Ramsey\Uuid\UuidInterface * @var \Ramsey\Uuid\UuidInterface
...@@ -34,13 +30,16 @@ class ProfilDeCotisation ...@@ -34,13 +30,16 @@ class ProfilDeCotisation
protected $id; protected $id;
/** /**
* @ORM\Column(name="maxPercevableMensuel", type="integer") * The amount the user will pay.
* The amount the user will receive depends on tauxCotisation.
*
* @ORM\Column(name="montant", type="integer")
* @Assert\Type("numeric") * @Assert\Type("numeric")
* @Assert\GreaterThanOrEqual( * @Assert\GreaterThanOrEqual(
* value = 0 * value = 0
* ) * )
*/ */
protected $maxPercevableMensuel; protected $montant;
/** /**
* @var float * @var float
...@@ -74,6 +73,50 @@ class ProfilDeCotisation ...@@ -74,6 +73,50 @@ class ProfilDeCotisation
} }
/** /**
* Get tauxCotisation.
*
* @return float tauxCotisation
*/
public function getTauxCotisation(): ?float
{
return $this->tauxCotisation;
}
/**
* Set tauxCotisation.
*
* @return $this
*/
public function setTauxCotisation(?float $tauxCotisation): self
{
$this->tauxCotisation = $tauxCotisation;
return $this;
}
/**
* Get montant.
*
* @return int montant
*/
public function getMontant(): ?int
{
return $this->montant;
}
/**
* Set montant.
*
* @return $this
*/
public function setMontant(?int $montant): self
{
$this->montant = $montant;
return $this;
}
/**
* @return ArrayCollection * @return ArrayCollection
*/ */
public function getBeneficiaires() public function getBeneficiaires()
...@@ -128,7 +171,7 @@ class ProfilDeCotisation ...@@ -128,7 +171,7 @@ class ProfilDeCotisation
public function __toString(): string public function __toString(): string
{ {
return 'Profil de taux ' . strval(100 * $this->tauxCotisation) . ' %' return 'Montant ' . strval($this->montant) . '€'
. ' et de maximum percevable mensuel ' . strval($this->maxPercevableMensuel) . ' €'; . ', Taux ' . strval(number_format($this->tauxCotisation, 2, '.', ''));
} }
} }
...@@ -17,6 +17,14 @@ abstract class CurrencyEnum ...@@ -17,6 +17,14 @@ abstract class CurrencyEnum
self::CURRENCY_MLC_NANTIE => 'MLC Nantie', self::CURRENCY_MLC_NANTIE => 'MLC Nantie',
]; ];
/** @var array ISO Code for national currencies */
protected static $code = [
self::CURRENCY_EMLC => 'EMLC',
self::CURRENCY_MLC => 'MLC',
self::CURRENCY_EURO => 'EUR',
self::CURRENCY_MLC_NANTIE => 'MLCN',
];
/** /**
* @param string $typeShortName * @param string $typeShortName
* *
...@@ -32,6 +40,20 @@ abstract class CurrencyEnum ...@@ -32,6 +40,20 @@ abstract class CurrencyEnum
} }
/** /**
* @param string $typeShortName
*
* @return string
*/
public static function getCode($typeShortName)
{
if (!isset(static::$code[$typeShortName])) {
return "Unknown type ($typeShortName)";
}
return static::$code[$typeShortName];
}
/**
* @return array<string> * @return array<string>
*/ */
public static function getAvailableTypes() public static function getAvailableTypes()
......
<?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 Version20221205112952 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 adherent DROP FOREIGN KEY FK_90D3F060D0B364B6');
$this->addSql('ALTER TABLE adherent ADD CONSTRAINT FK_90D3F060D0B364B6 FOREIGN KEY (profildecotisation_id) REFERENCES profildecotisation (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
$this->addSql('DROP INDEX UNIQ_386FBA47989D9B62 ON profildecotisation');
$this->addSql('ALTER TABLE profildecotisation DROP name, DROP slug, DROP content, DROP enabled, CHANGE maxpercevablemensuel montant INT NOT NULL');
}
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_90D3F060D0B364B6');
$this->addSql('ALTER TABLE adherent ADD CONSTRAINT FK_90D3F060D0B364B6 FOREIGN KEY (profildecotisation_id) REFERENCES profildecotisation (id)');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_general_ci` COMMENT \'(DC2Type:personal_data)\'');
$this->addSql('ALTER TABLE profildecotisation ADD name VARCHAR(150) CHARACTER SET utf8mb3 NOT NULL COLLATE `utf8mb3_general_ci`, ADD slug VARCHAR(150) CHARACTER SET utf8mb3 NOT NULL COLLATE `utf8mb3_general_ci`, ADD content LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_general_ci`, ADD enabled TINYINT(1) NOT NULL, CHANGE montant maxPercevableMensuel INT NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_386FBA47989D9B62 ON profildecotisation (slug)');
}
}
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