add message in expense report notitfications
This commit is contained in:
parent
6c4cedc144
commit
2931c095ea
|
@ -6,15 +6,16 @@ use App\Core\Controller\Admin\Crud\CrudController;
|
|||
use App\Core\Crud\CrudConfiguration;
|
||||
use App\Core\Crud\Field;
|
||||
use App\Core\Entity\EntityInterface;
|
||||
use App\Core\Event\EntityManager\EntityManagerEvent;
|
||||
use App\Core\Form\FileUploadHandler;
|
||||
use App\Core\Manager\EntityManager;
|
||||
use App\Entity\ExpenseReport as Entity;
|
||||
use App\Event\EntityManagerEvent;
|
||||
use App\Factory\ExpenseReportFactory as Factory;
|
||||
use App\Form\ExpenseReportType as Type;
|
||||
use App\Repository\ExpenseReportRepositoryQuery as RepositoryQuery;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -84,18 +85,54 @@ class ExpenseReportAdminController extends CrudController
|
|||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
if (true === $entity->getIsRequestedPayment()) {
|
||||
if ($entity->getIsRequestedPayment()) {
|
||||
return $this->redirectToRoute('admin_expense_report_show', [
|
||||
'entity' => $entity->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$entity->getIsRequestedPayment()) {
|
||||
$form = $this->createFormBuilder()
|
||||
->add('message', TextareaType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Message',
|
||||
'help' => 'Message à ajouter dans le mail de notification (optionnel)',
|
||||
])
|
||||
->getForm()
|
||||
->createView()
|
||||
;
|
||||
|
||||
$route = 'admin_expense_report_request_payment';
|
||||
$tokenName = 'request_payment';
|
||||
} elseif ($entity->getIsRequestedPayment() && !$entity->getIsPaid()) {
|
||||
$form = $this->createFormBuilder()
|
||||
->add('message', TextareaType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Message',
|
||||
'help' => 'Message à ajouter dans le mail de notification (optionnel)',
|
||||
])
|
||||
->getForm()
|
||||
->createView()
|
||||
;
|
||||
|
||||
$route = 'admin_expense_report_paid';
|
||||
$tokenName = 'paid';
|
||||
}
|
||||
|
||||
if (isset($form)) {
|
||||
$this->getConfiguration()
|
||||
->addViewData('edit', 'mailFormRoute', $route)
|
||||
->addViewData('edit', 'mailFormTokenName', $tokenName)
|
||||
->addViewData('edit', 'mailForm', $form)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->doEdit($entity, $entityManager, $request, [$this, 'beforeUpdate']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/expense_report/request_payment/{entity}/{token}", name="admin_expense_report_request_payment", methods={"GET"})
|
||||
* @Route("/admin/expense_report/request_payment/{entity}/{token}", name="admin_expense_report_request_payment", methods={"POST"})
|
||||
*/
|
||||
public function requestPayment(
|
||||
Entity $entity,
|
||||
|
@ -114,10 +151,14 @@ class ExpenseReportAdminController extends CrudController
|
|||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$message = $request->request->get('form')['message'] ?? null;
|
||||
$entity->setIsRequestedPayment(true);
|
||||
$entityManager->update($entity);
|
||||
|
||||
$eventDispatcher->dispatch(new EntityManagerEvent($entity), 'expense_report.requested_payment');
|
||||
$eventDispatcher->dispatch(new EntityManagerEvent($entity, [
|
||||
'message' => $message,
|
||||
'user' => $this->getUser(),
|
||||
]), 'expense_report.requested_payment');
|
||||
|
||||
$this->addFlash('success', 'La demande a été envoyée.');
|
||||
|
||||
|
@ -127,7 +168,7 @@ class ExpenseReportAdminController extends CrudController
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/admin/expense_report/paud/{entity}/{token}", name="admin_expense_report_paid", methods={"GET"})
|
||||
* @Route("/admin/expense_report/paid/{entity}/{token}", name="admin_expense_report_paid", methods={"POST"})
|
||||
*/
|
||||
public function paid(
|
||||
Entity $entity,
|
||||
|
@ -144,6 +185,7 @@ class ExpenseReportAdminController extends CrudController
|
|||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$message = $request->request->get('form')['message'] ?? null;
|
||||
$entity->setIsPaid(true);
|
||||
|
||||
if (!$entity->getPaidAt()) {
|
||||
|
@ -152,7 +194,10 @@ class ExpenseReportAdminController extends CrudController
|
|||
|
||||
$entityManager->update($entity);
|
||||
|
||||
$eventDispatcher->dispatch(new EntityManagerEvent($entity), 'expense_report.paid');
|
||||
$eventDispatcher->dispatch(new EntityManagerEvent($entity, [
|
||||
'message' => $message,
|
||||
'user' => $this->getUser(),
|
||||
]), 'expense_report.paid');
|
||||
|
||||
$this->addFlash('success', 'The data has been saved.');
|
||||
|
||||
|
|
28
src/Event/EntityManagerEvent.php
Normal file
28
src/Event/EntityManagerEvent.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Core\Entity\EntityInterface;
|
||||
use App\Core\Event\EntityManager\EntityManagerEvent as Event;
|
||||
|
||||
/**
|
||||
* class EntityManagerEvent.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class EntityManagerEvent extends Event
|
||||
{
|
||||
protected $params;
|
||||
|
||||
public function __construct(EntityInterface $entity, array $params = [])
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
parent::__construct($entity);
|
||||
}
|
||||
|
||||
public function getParams(): array
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
}
|
|
@ -55,6 +55,8 @@ class ExpenseReportEventSubscriber extends EntityManagerEventSubscriber
|
|||
->addRecipientsByUsers($this->userQuery->where('.isTreasurer = true')->find(), true)
|
||||
->notify('mail/expense_report/paid.html.twig', [
|
||||
'entity' => $event->getEntity(),
|
||||
'message' => $event->getParams()['message'],
|
||||
'user' => $event->getParams()['user'],
|
||||
'show_url' => $this->urlGenerator->generate(
|
||||
'admin_expense_report_show',
|
||||
[
|
||||
|
@ -77,6 +79,8 @@ class ExpenseReportEventSubscriber extends EntityManagerEventSubscriber
|
|||
->addRecipientsByUsers($this->userQuery->where('.isTreasurer = true')->find(), true)
|
||||
->notify('mail/expense_report/requested_payment.html.twig', [
|
||||
'entity' => $event->getEntity(),
|
||||
'message' => $event->getParams()['message'],
|
||||
'user' => $event->getParams()['user'],
|
||||
'show_url' => $this->urlGenerator->generate(
|
||||
'admin_expense_report_show',
|
||||
[
|
||||
|
|
|
@ -3,25 +3,52 @@
|
|||
{% block header_actions_after %}
|
||||
{% if not entity.isPaid %}
|
||||
{% if not entity.isRequestedPayment and (entity.user.id == app.user.id or is_granted('ROLE_TREASURER')) %}
|
||||
{% set url = safe_path(configuration.pageRoute('requestPayment'), {
|
||||
entity: entity.id,
|
||||
token: csrf_token('request_payment')
|
||||
}) %}
|
||||
|
||||
<a class="btn btn-success" href="{{ url }}" onclick="return confirm('Avez-vous bien enregistré vos modification ?')">
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Demander le paiement
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if entity.isRequestedPayment and is_granted('ROLE_TREASURER') %}
|
||||
{% set url = safe_path(configuration.pageRoute('paid'), {
|
||||
entity: entity.id,
|
||||
token: csrf_token('paid')
|
||||
}) %}
|
||||
|
||||
<a class="btn btn-success" href="{{ url }}">
|
||||
<span class="btn btn-success" data-toggle="modal" data-target="#notification">
|
||||
Définir comme payée
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{{ parent() }}
|
||||
|
||||
{% set mailFormRoute = configuration.viewData(context, 'mailFormRoute') %}
|
||||
{% set mailFormTokenName = configuration.viewData(context, 'mailFormTokenName') %}
|
||||
{% set mailForm = configuration.viewData(context, 'mailForm') %}
|
||||
|
||||
{% if mailFormRoute %}
|
||||
<form action="{{ path(mailFormRoute, {entity: entity.id, token: csrf_token(mailFormTokenName)}) }}" method="POST">
|
||||
<div class="modal" tabindex="-1" id="notification">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Notification</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-warning">
|
||||
Attention, si vous avez modifié la note de frais sans avoir enregistré,
|
||||
les données ne seront pas conservées.
|
||||
</div>
|
||||
|
||||
{{ form(mailForm) }}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ 'Close'|trans }}</button>
|
||||
<button type="submit" class="btn btn-primary">{{ 'Submit'|trans }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
</p>
|
||||
|
||||
<p>Le paiement pour la <a href="{{ show_url }}">note de frais #{{ entity.id }}</a> a été réalisé ☺️</p>
|
||||
|
||||
{% if message %}
|
||||
<p>Message de {{ user.displayName }} : « {{ message|nl2br }} »</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
</p>
|
||||
|
||||
<p>Une demande de paiement a été réalisée pour la <a href="{{ show_url }}">note de frais #{{ entity.id }}</a> 🔔</p>
|
||||
|
||||
{% if message %}
|
||||
<p>Message de {{ user.displayName }} : « {{ message|nl2br }} »</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue