Commit 849f4176 by Julien Jorry

ADMIN : Fix bug sur l'ajout d'une cotisation en emlc => le compte est désormais prélevé du montant

parent 3455e977
# Update v2.2.5 (2022-03-25)
- ajout d'un paramètre obligatoire MLC_URL qui doit refléter l'url du site kohinos installé (exemple : https://doume.org) => utile pour l'installation de l'application
- Fix bug sur le rôle contact d'un groupe local => impossible d'afficher l'historique des transactions du groupe
- ADMIN : Fix bug sur l'ajout d'une cotisation en emlc => le compte est désormais prélevé du montant !
- PWA Kohinos :
- utilisation de workbox-webpack-plugin pour la génération du sw.js
- ajout à la racine des fichiers manifest.json (généré via un twig) et sw.js
......
......@@ -246,6 +246,7 @@ services:
public: true
calls:
- [ setSecurity, ['@security.helper']]
- [ setOperationUtils, ['@app.utils.operations']]
admin.all.achatsmonnaie:
class: App\Admin\AchatMonnaieAdmin
......@@ -282,6 +283,7 @@ services:
public: true
calls:
- [ setSecurity, ['@security.helper']]
- [ setOperationUtils, ['@app.utils.operations']]
admin.prestataire.gerer:
class: App\Admin\PrestataireAdmin
......@@ -310,6 +312,7 @@ services:
public: true
calls:
- [ setSecurity, ['@security.helper']]
- [ setOperationUtils, ['@app.utils.operations']]
admin.groupe.gerer:
class: App\Admin\GroupeAdmin
......
......@@ -7,9 +7,12 @@ use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\User;
use App\Enum\MoyenEnum;
use App\Exception\BalanceInsufficientException;
use App\Utils\OperationUtils;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Exception\ModelManagerException;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
......@@ -32,6 +35,7 @@ class CotisationAdmin extends AbstractAdmin
protected $baseRouteName = 'cotisation';
protected $baseRoutePattern = 'cotisation';
protected $security;
protected $operationUtils;
protected $translator;
protected $datagridValues = [
......@@ -42,6 +46,11 @@ class CotisationAdmin extends AbstractAdmin
protected $maxPerPage = 250;
protected $perPageOptions = [50, 100, 250, 500, 1000];
public function setOperationUtils(OperationUtils $operationUtils)
{
$this->operationUtils = $operationUtils;
}
public function setSecurity(Security $security)
{
$this->security = $security;
......@@ -228,6 +237,36 @@ class CotisationAdmin extends AbstractAdmin
return $iterator;
}
public function prePersist($cotisation)
{
try {
if ($cotisation->getCotisationInfos()->isRecu()) {
$this->operationUtils->executeOperations($cotisation);
}
} catch (\Exception $e) {
throw new BalanceInsufficientException($e->getMessage());
}
}
/** Overwrite create methode to catch custom error */
public function create($object)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
try {
$em->beginTransaction();
$res = parent::create($object);
$em->getConnection()->commit();
return $res;
} catch (BalanceInsufficientException $e) {
$em->getConnection()->rollBack();
$this->getConfigurationPool()->getContainer()->get('session')->getFlashBag()->clear();
$this->getConfigurationPool()->getContainer()->get('session')->getFlashBag()->add('error', $e->getMessage());
return null;
}
}
public function getExportFields()
{
return [
......
......@@ -81,7 +81,7 @@ class OperationAdmin extends AbstractAdmin
->add('montant', 'decimal', ['label' => 'Montant', 'attributes' => ['fraction_digits' => 2]])
->add('currency', null, ['label' => 'Devise'])
->add('flux.expediteur', null, ['label' => 'Expediteur', 'template' => '@kohinos/bundles/SonataAdminBundle/Block/accountable.html.twig'])
->add('flux.destinataire', null, ['label' => 'Destinataire', 'template' => '@kohinos/bundles/SonataAdminBundle/Block/accountable.html.twig'])
// ->add('flux.destinataire', null, ['label' => 'Destinataire', 'template' => '@kohinos/bundles/SonataAdminBundle/Block/accountable.html.twig'])
// ->add('account.accountableObject', null, ['label' => 'Compte'])
->add('flux.type', 'text', ['label' => 'Type', 'template' => '@kohinos/bundles/SonataAdminBundle/Block/translated_value.html.twig'])
->add('flux.operateur', null, ['label' => 'Operateur'])
......
......@@ -120,7 +120,7 @@ abstract class Operation implements OperationInterface
*
* @return
*/
public function getFlux(): FluxInterface
public function getFlux(): ?FluxInterface
{
return $this->flux;
}
......
<?php
namespace App\Exception;
class BalanceInsufficientException extends \Exception
{
}
......@@ -4,32 +4,36 @@
{# {% if object is instanceof("App\\Entity\\Operation") %} #}
{% set objectFlux = null %}
{% if field_description.label|lower == 'expediteur' %}
{% if object.flux is not null %}
{% set objectFlux = object.account.accountableObject == object.flux.expediteur ? null : object.flux.expediteur %}
{% endif %}
{% elseif field_description.label|lower == 'destinataire' %}
{% set objectFlux = object.account.accountableObject == object.flux.destinataire ? null : object.flux.destinataire %}
{% if object.flux is not null %}
{% set objectFlux = object.account.accountableObject != object.flux.destinataire ? null : object.flux.destinataire %}
{% endif %}
{% elseif field_description.label|lower matches '/^Compte (groupe|comptoir|adherent|prestataire)/i' %}
{% set objectFlux = object.account.accountableObject %}
{% endif %}
{% if objectFlux is not null %}
{% if objectFlux is instanceof("App\\Entity\\Adherent") %}
{% set name = 'Adherent' %}
{% set routea = 'adherent_edit' %}
{% set editRoute = 'adherent_edit' %}
{% elseif objectFlux is instanceof("App\\Entity\\Prestataire") %}
{% set name = 'Prestataire' %}
{% set routea = 'prestataire_edit' %}
{% set editRoute = 'prestataire_edit' %}
{% elseif objectFlux is instanceof("App\\Entity\\Comptoir") %}
{% set name = 'Comptoir' %}
{% set routea = 'comptoir_edit' %}
{% set editRoute = 'comptoir_edit' %}
{% elseif objectFlux is instanceof("App\\Entity\\Groupe") %}
{% set name = 'Groupe' %}
{% set routea = 'admin_app_groupe_edit' %}
{% set editRoute = 'admin_app_groupe_edit' %}
{% else %}
{% set name = '' %}
{% set routea = '' %}
{% set editRoute = '' %}
{% endif %}
{% if routea != '' %}
<a class="sonata-link-identifier" href="{{ path(routea, {'id': objectFlux.id}) }}">
{% if editRoute != '' %}
<a class="sonata-link-identifier" href="{{ path(editRoute, {'id': objectFlux.id}) }}">
{{ name ? '('~name~') ' }}{{ value }}
</a>
{% else %}
......
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