Commit db470103 by Damien Moulard

allow full parameterization for comptoir available payment types

parent 4d2be1ca
...@@ -137,6 +137,12 @@ services: ...@@ -137,6 +137,12 @@ services:
class: App\Utils\PaymentUtils class: App\Utils\PaymentUtils
autowire: true autowire: true
app.utils.moyens:
class: App\Utils\MoyensUtils
autowire: true
public: true
arguments: ['@app.utils.custom_entity_manager']
app.twig.main.extension: app.twig.main.extension:
class: App\Twig\AppExtension class: App\Twig\AppExtension
autowire: false autowire: false
......
...@@ -68,7 +68,6 @@ class GlobalParameter ...@@ -68,7 +68,6 @@ class GlobalParameter
const SSA_HOUSEHOLD_USE_SHARED_CUSTODY = 'SSA_HOUSEHOLD_USE_SHARED_CUSTODY'; const SSA_HOUSEHOLD_USE_SHARED_CUSTODY = 'SSA_HOUSEHOLD_USE_SHARED_CUSTODY';
const SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT = 'SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT'; const SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT = 'SSA_HOUSEHOLD_MAX_ALLOCATION_AMOUNT';
const SSA_HOUSEHOLD_COTISATION_MINIMUM = 'SSA_HOUSEHOLD_COTISATION_MINIMUM'; const SSA_HOUSEHOLD_COTISATION_MINIMUM = 'SSA_HOUSEHOLD_COTISATION_MINIMUM';
const ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR = 'ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR';
const SSA_HOUSEHOLD_WITH_QUARTIER = 'SSA_HOUSEHOLD_WITH_QUARTIER'; const SSA_HOUSEHOLD_WITH_QUARTIER = 'SSA_HOUSEHOLD_WITH_QUARTIER';
const SSA_HOUSEHOLD_QUARTIER_LIST_VALUES = 'SSA_HOUSEHOLD_QUARTIER_LIST_VALUES'; const SSA_HOUSEHOLD_QUARTIER_LIST_VALUES = 'SSA_HOUSEHOLD_QUARTIER_LIST_VALUES';
const SSA_HOUSEHOLD_WITH_SUBTERRITORY = 'SSA_HOUSEHOLD_WITH_SUBTERRITORY'; const SSA_HOUSEHOLD_WITH_SUBTERRITORY = 'SSA_HOUSEHOLD_WITH_SUBTERRITORY';
...@@ -76,6 +75,7 @@ class GlobalParameter ...@@ -76,6 +75,7 @@ class GlobalParameter
const GEOLOC_WITH_QUARTIER = 'GEOLOC_WITH_QUARTIER'; const GEOLOC_WITH_QUARTIER = 'GEOLOC_WITH_QUARTIER';
const GEOLOC_QUARTIER_LIST_VALUES = 'GEOLOC_QUARTIER_LIST_VALUES'; const GEOLOC_QUARTIER_LIST_VALUES = 'GEOLOC_QUARTIER_LIST_VALUES';
const GEOLOC_WITH_SUBTERRITORY = 'GEOLOC_WITH_SUBTERRITORY'; const GEOLOC_WITH_SUBTERRITORY = 'GEOLOC_WITH_SUBTERRITORY';
const COMPTOIR_PAYMENT_TYPES = 'COMPTOIR_PAYMENT_TYPES';
/** /**
* @var \Ramsey\Uuid\UuidInterface * @var \Ramsey\Uuid\UuidInterface
......
...@@ -40,35 +40,6 @@ abstract class MoyenEnum ...@@ -40,35 +40,6 @@ abstract class MoyenEnum
} }
/** /**
* Return available type for Comptoir.
*
* @return array<string>
*/
public static function getAvailableTypesComptoir()
{
return [
self::MOYEN_ESPECE,
self::MOYEN_CHEQUE,
self::MOYEN_AUTRE,
];
}
/**
* Return another set of available types for Comptoir.
* For Comptoirs not accepting checks
*
* @return array<string>
*/
public static function getAlternateAvailableTypesComptoir()
{
return [
self::MOYEN_VIREMENT,
self::MOYEN_ESPECE,
self::MOYEN_AUTRE,
];
}
/**
* Return all available type of moyen. * Return all available type of moyen.
* *
* @return array<string> * @return array<string>
......
...@@ -24,11 +24,10 @@ class ComptoirEncaisserDonAdherentFormType extends FluxFormType ...@@ -24,11 +24,10 @@ class ComptoirEncaisserDonAdherentFormType extends FluxFormType
throw new \Exception('[FORM COMPTOIR ENCAISSEMENT DON ADHERENT] Opération impossible !'); throw new \Exception('[FORM COMPTOIR ENCAISSEMENT DON ADHERENT] Opération impossible !');
} }
$alternatePaymentTypes = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR);
$builder $builder
->add('moyen', ChoiceType::class, [ ->add('moyen', ChoiceType::class, [
'required' => true, 'required' => true,
'choices' => ('true' === $alternatePaymentTypes) ? MoyenEnum::getAlternateAvailableTypesComptoir() : MoyenEnum::getAvailableTypesComptoir(), 'choices' => $this->moyensUtils->getAvailableTypesComptoir(),
'choice_label' => function ($choice) { 'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice); return MoyenEnum::getTypeName($choice);
}, },
......
...@@ -5,6 +5,7 @@ namespace App\Form\Type; ...@@ -5,6 +5,7 @@ namespace App\Form\Type;
use App\Entity\Flux; use App\Entity\Flux;
use App\Entity\User; use App\Entity\User;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Utils\MoyensUtils;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
...@@ -27,17 +28,20 @@ class FluxFormType extends AbstractType ...@@ -27,17 +28,20 @@ class FluxFormType extends AbstractType
protected $security; protected $security;
protected $container; protected $container;
protected $session; protected $session;
protected $moyensUtils;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
Security $security, Security $security,
ContainerInterface $container, ContainerInterface $container,
SessionInterface $session SessionInterface $session,
MoyensUtils $moyensUtils
) { ) {
$this->em = $em; $this->em = $em;
$this->security = $security; $this->security = $security;
$this->container = $container; $this->container = $container;
$this->session = $session; $this->session = $session;
$this->moyensUtils = $moyensUtils;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
......
...@@ -22,11 +22,10 @@ class VenteEmlcFormType extends FluxFormType ...@@ -22,11 +22,10 @@ class VenteEmlcFormType extends FluxFormType
throw new \Exception('[FORM VENTE EMLC] Opération impossible !'); throw new \Exception('[FORM VENTE EMLC] Opération impossible !');
} }
$alternatePaymentTypes = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR);
$builder $builder
->add('moyen', ChoiceType::class, [ ->add('moyen', ChoiceType::class, [
'required' => true, 'required' => true,
'choices' => ('true' === $alternatePaymentTypes) ? MoyenEnum::getAlternateAvailableTypesComptoir() : MoyenEnum::getAvailableTypesComptoir(), 'choices' => $this->moyensUtils->getAvailableTypesComptoir(),
'choice_label' => function ($choice) { 'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice); return MoyenEnum::getTypeName($choice);
}, },
......
...@@ -11,11 +11,10 @@ class VenteFormType extends TicketFormType ...@@ -11,11 +11,10 @@ class VenteFormType extends TicketFormType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$alternatePaymentTypes = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR);
$builder $builder
->add('moyen', ChoiceType::class, [ ->add('moyen', ChoiceType::class, [
'required' => true, 'required' => true,
'choices' => ('true' === $alternatePaymentTypes) ? MoyenEnum::getAlternateAvailableTypesComptoir() : MoyenEnum::getAvailableTypesComptoir(), 'choices' => $this->moyensUtils->getAvailableTypesComptoir(),
'choice_label' => function ($choice) { 'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice); return MoyenEnum::getTypeName($choice);
}, },
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\Entity\GlobalParameter;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250502111501 extends AbstractMigration implements ContainerAwareInterface
{
/**
* @var ObjectManager
*/
protected $em;
public function setContainer(ContainerInterface $container = null)
{
$this->em = $container->get('doctrine')->getManager();
}
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
$alternatePaymentTypes = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR);
if ($alternatePaymentTypes === 'true') {
$defaultValue = "MOYEN_VIREMENT,MOYEN_ESPECE,MOYEN_AUTRE";
} else {
$defaultValue = "MOYEN_ESPECE,MOYEN_CHEQUE,MOYEN_AUTRE";
}
$this->addSql("INSERT INTO global_parameter (id, name, description, value, mandatory) VALUES (UUID(), 'COMPTOIR_PAYMENT_TYPES', 'Défini la liste des paiements disponible aux comptoirs. Insérer les valeurs désirées dans l\'ordre séparées par une virgule sans espace. Valeurs possibles : MOYEN_CB, MOYEN_ESPECE, MOYEN_CHEQUE, MOYEN_VIREMENT, MOYEN_HELLOASSO, MOYEN_EMLC, MOYEN_MLC, MOYEN_AUTRE.', '$defaultValue', '0')");
$this->addSql("DELETE FROM global_parameter where name='ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR'");
}
public function down(Schema $schema) : void
{
$this->addSql("DELETE FROM global_parameter where name='COMPTOIR_PAYMENT_TYPES'");
$this->addSql("INSERT INTO global_parameter (id, name, description, value, mandatory) VALUES (UUID(), 'ALTERNATE_AVAILABLE_PAYMENT_TYPES_COMPTOIR', 'Active un set de moyens de paiement disponibles alternatif pour les comptoirs. Par défaut : Espèce, Chèque, Autre. Avec ce paramètre activé : Virement, Espèce, Autre.', 'false', '1')");
}
}
<?php
namespace App\Utils;
use App\Entity\GlobalParameter;
use App\Utils\CustomEntityManager;
use App\Enum\MoyenEnum;
class MoyensUtils
{
private $em;
public function __construct(CustomEntityManager $em) {
$this->em = $em;
}
/**
* Return available payment types for Comptoir from configuration param value.
*
* @return array<string>
*/
public function getAvailableTypesComptoir()
{
$paymentTypes = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::COMPTOIR_PAYMENT_TYPES);
if (null == $paymentTypes) {
return $this->getDefaultAvailableTypesComptoir();
}
$paymentTypesArr = explode(",", $paymentTypes);
try {
$res = array_map(function ($val) {
return constant("App\\Enum\\MoyenEnum::$val");
}, $paymentTypesArr);
} catch (\Exception $e) {
// Error in parameter definition
$res = $this->getDefaultAvailableTypesComptoir();
}
return $res;
}
public function getDefaultAvailableTypesComptoir() {
return [
MoyenEnum::MOYEN_ESPECE,
MoyenEnum::MOYEN_CHEQUE,
MoyenEnum::MOYEN_AUTRE,
];
}
}
\ No newline at end of file
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