Commit 8cfcd5f6 by Yvon

6073 : fix naming in flux export + rework filtering area in flux + some refactoring

parent 94cfa847
......@@ -64,6 +64,8 @@ class FluxAdmin extends AbstractAdmin
protected function configureExportFields(): array
{
$ssaFriendlyTypeNames = $this->getConfigurationPool()->getContainer()->getParameter('tav_env')
&& $this->getConfigurationPool()->getContainer()->getParameter('ssa_friendly_flux_type_names');
return [
$this->trans('Date') => 'createdAt',
$this->trans('Expediteur') => 'expediteur',
......@@ -91,17 +93,12 @@ class FluxAdmin extends AbstractAdmin
*/
protected function configureListFields(ListMapper $listMapper)
{
if($this->getConfigurationPool()->getContainer()->getParameter('tav_env')
&& $this->getConfigurationPool()->getContainer()->getParameter('ssa_friendly_flux_type_names'))
{
$typeTemplate = '@kohinos/bundles/SonataAdminBundle/Block/ssa_friendly_flux_type_names_translated_value.html.twig';
} else {
$typeTemplate = '@kohinos/bundles/SonataAdminBundle/Block/translated_value.html.twig';
}
$ssaFriendlyTypeNames = $this->getConfigurationPool()->getContainer()->getParameter('tav_env')
&& $this->getConfigurationPool()->getContainer()->getParameter('ssa_friendly_flux_type_names');
unset($this->listModes['mosaic']);
$listMapper
->add('createdAt', 'datetime', ['label' => 'Date'])
->add('type', 'text', ['label' => 'Type', 'template' => $typeTemplate])
->add($ssaFriendlyTypeNames ? 'ssaFriendlyTypeName' : 'type', 'text', ['label' => 'Type', 'template' => '@kohinos/bundles/SonataAdminBundle/Block/translated_value.html.twig'])
->add('montant', 'decimal', ['label' => 'Montant', 'attributes' => ['fraction_digits' => 2]])
->add('expediteur', null, ['label' => 'Expediteur'])
->add('destinataire', null, ['label' => 'Destinataire'])
......@@ -117,6 +114,11 @@ class FluxAdmin extends AbstractAdmin
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$ssaFriendlyTypeNames = $this->getConfigurationPool()->getContainer()->getParameter('tav_env')
&& $this->getConfigurationPool()->getContainer()->getParameter('ssa_friendly_flux_type_names');
$choices = $ssaFriendlyTypeNames ? //in ssa mode, remove flux types that are irrelevant or confusing
['Transactions' => Flux::TYPE_TRANSACTION]
: ['Cotisations' => Flux::TYPE_COTISATION, 'Achat de monnaie' => Flux::TYPE_ACHAT, 'Dépôt de billets' => Flux::TYPE_CHANGE, 'Retrait' => Flux::TYPE_RETRAIT, 'Transactions' => Flux::TYPE_TRANSACTION, 'Transferts' => Flux::TYPE_TRANSFERT, 'Vente' => Flux::TYPE_VENTE];
$datagridMapper
->add('transfert_or_transaction', 'doctrine_orm_callback', [
'label' => 'Type',
......@@ -134,17 +136,32 @@ class FluxAdmin extends AbstractAdmin
'show_filter' => true,
'field_type' => SChoiceType::class,
'field_options' => [
'choices' => ['Cotisations' => Flux::TYPE_COTISATION, 'Achat de monnaie' => Flux::TYPE_ACHAT, 'Dépôt de billets' => Flux::TYPE_CHANGE, 'Retrait' => Flux::TYPE_RETRAIT, 'Transactions' => Flux::TYPE_TRANSACTION, 'Transferts' => Flux::TYPE_TRANSFERT, 'Vente' => Flux::TYPE_VENTE],
'choices' => $choices,
'placeholder' => 'Indifférent',
'expanded' => true,
'multiple' => false,
],
])
]);
if ($ssaFriendlyTypeNames) {
$datagridMapper
->add('type', null, [
'label' => 'Type plus précis',
'advanced_filter' => false,
'show_filter' => true,
])
'field_type' => SChoiceType::class,
'field_options' => [
'choices' => array_flip(Flux::ssaUsefulFriendlyTypeNames())
]
]);
} else {
$datagridMapper
->add('type', null, [
'label' => 'Type plus précis',
'advanced_filter' => false,
'show_filter' => true,
]);
}
$datagridMapper
->add('operateur', null, [
'label' => 'Operateur',
'advanced_filter' => false,
......@@ -189,9 +206,11 @@ class FluxAdmin extends AbstractAdmin
public function getExportFields()
{
$ssaFriendlyTypeNames = $this->getConfigurationPool()->getContainer()->getParameter('tav_env')
&& $this->getConfigurationPool()->getContainer()->getParameter('ssa_friendly_flux_type_names');
return [
'Date' => 'created_at',
'Type' => 'type',
'Type' => $ssaFriendlyTypeNames ? 'ssaFriendlyTypeName' : 'type',
'Montant' => 'montant',
'Expediteur' => 'expediteur',
'Destinataire' => 'destinataire',
......
......@@ -649,4 +649,27 @@ abstract class Flux implements FluxInterface
return ($this->getCreatedAt() ? $this->getCreatedAt()->format('d/m/Y H:i') . ' | ' : '') . ucwords($this->getParenttype()) . ' : ' . $this->getExpediteur() . ' => ' . $this->getDestinataire() . ' : ' . $this->getMontant() . '€';
}
public function ssaFriendlyTypeName()
{
$friendlyTypeNames = Flux::ssaUsefulFriendlyTypeNames();
return array_key_exists($this->type,$friendlyTypeNames) ?
$friendlyTypeNames[$this->type]
: $this->type;
}
public static function ssaUsefulFriendlyTypeNames()
{
return [
VenteEmlc::TYPE_VENTE_EMLC_ADHERENT => "Achat de MonA via cotisation",
AchatMonnaie::TYPE_ACHAT_ADHERENT => "Achat de MonA via cotisation",
CotisationTavApplication::TYPE_REVERSEMENT_COTISATION_ADHERENT => "Allocation complémentaire de la caisse",
CotisationTavApplication::TYPE_PRELEVEMENT_COTISATION_ADHERENT => "Réduction de l'allocation",
Don::TYPE_DON_ADHERENT => Don::TYPE_DON_ADHERENT,
Don::TYPE_DON_PRESTATAIRE => Don::TYPE_DON_PRESTATAIRE,
Reconversion::TYPE_RECONVERSION_PRESTATAIRE => Reconversion::TYPE_RECONVERSION_PRESTATAIRE,
Transaction::TYPE_TRANSACTION_PRESTATAIRE_ADHERENT => Transaction::TYPE_TRANSACTION_PRESTATAIRE_ADHERENT,
Transaction::TYPE_TRANSACTION_ADHERENT_PRESTATAIRE => Transaction::TYPE_TRANSACTION_ADHERENT_PRESTATAIRE
];
}
}
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