Commit 33295215 by Yvon

add btn to cancel transaction adherent prestataire in last operations drop down…

add btn to cancel transaction adherent prestataire in last operations drop down admin prestataire ; back-end creates an opposite transaction prestataire adherent
parent 496f94c7
...@@ -8,6 +8,7 @@ use App\Entity\CotisationPrestataire; ...@@ -8,6 +8,7 @@ use App\Entity\CotisationPrestataire;
use App\Entity\GlobalParameter; use App\Entity\GlobalParameter;
use App\Entity\Payment; use App\Entity\Payment;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\TransactionPrestataireAdherent;
use App\Entity\User; use App\Entity\User;
use App\Entity\TransactionAdherentPrestataire; use App\Entity\TransactionAdherentPrestataire;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
...@@ -247,23 +248,36 @@ class UserController extends AbstractController ...@@ -247,23 +248,36 @@ class UserController extends AbstractController
* @param Request $request * @param Request $request
* @param TransactionAdherentPrestataire $transactionAdherentPrestataire * @param TransactionAdherentPrestataire $transactionAdherentPrestataire
* @return void * @return void
* @Security("is_granted('ROLE_PRESTATAIRE') or is_granted('ROLE_CAISSIER')") * @IsGranted({"ROLE_CAISSIER", "ROLE_PRESTATAIRE"})
* @Route("/cancel-transaction-adherent-prestataire/{id}", name="cancel_transaction_adherent_prestataire") * @Route("/cancel-transaction-adherent-prestataire/{id}", name="cancel_transaction_adherent_prestataire")
*/ */
public function cancelTransactionAdherentPrestataireAction(Request $request, TransactionAdherentPrestataire $transactionAdherentPrestataire) public function cancelTransactionAdherentPrestataireAction(Request $request, TransactionAdherentPrestataire $transactionAdherentPrestataire)
{ {
$adherent = $transactionAdherentPrestataire->getExpediteur();
$presta = $transactionAdherentPrestataire->getDestinataire();
//Make sure current user is destinataire of transaction //Make sure current user is destinataire of transaction
if(!in_array($this->getUser(),$transactionAdherentPrestataire->getDestinataire()->getUsers())) { if(!in_array($this->getUser(),$presta->getUsers()->toArray())) {
$this->addFlash( $this->addFlash(
'error', 'error',
"Vous n'êtes pas autorisé à annuler cette transaction." "Vous n'êtes pas autorisé à annuler cette transaction."
); );
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
} }
//Make sure flux has not been cancelled already
if($transactionAdherentPrestataire->getCancellerFlux()) {
$this->addFlash(
'error',
"Cette transaction a déjà été annulée."
);
return $this->redirectToRoute('index');
}
// Check prestataire has enough funds // Check prestataire has enough funds
$balance = $transactionAdherentPrestataire->getDestinataire()->getEmlcAccount()->getBalance(); $balance = $presta->getEmlcAccount()->getBalance();
//I think this is unlikely in real situation but we need to make sure prestataire has enough founds //I think this is unlikely in real situation but we need to make sure prestataire has enough founds
if ($balance < $transactionAdherentPrestataire->getMontant()) { $montant = $transactionAdherentPrestataire->getMontant();
if ($balance < $montant) {
$this->addFlash( $this->addFlash(
'error', 'error',
'Fonds insuffisants pour annuler cette transaction.' 'Fonds insuffisants pour annuler cette transaction.'
...@@ -271,7 +285,33 @@ class UserController extends AbstractController ...@@ -271,7 +285,33 @@ class UserController extends AbstractController
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
} }
//TODO: Save transaction //Create new transaction in opposite direction
$flux = new TransactionPrestataireAdherent();
$flux->setExpediteur($presta);
$flux->setDestinataire($adherent);
$flux->setOperateur($this->security->getUser());
$flux->setMontant($montant);
$flux->setMoyen(MoyenEnum::MOYEN_EMLC);
$now = (new \Datetime('now'))->format('d/m/Y H:i:s');
$flux->setReference(
'Remboursement en Monnaie Solidaire du ' . $now . ', annule ' . $transactionAdherentPrestataire->getReference()
);
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
//Mark original transaction as cancelled
$transactionAdherentPrestataire->setCancellerFlux($flux);
$this->em->flush();
$this->addFlash(
'success',
'La transaction a bien été annulée.'
);
return $this->redirectToRoute('index');
} }
/** /**
......
...@@ -29,6 +29,12 @@ class TransactionAdherentPrestataire extends Transaction ...@@ -29,6 +29,12 @@ class TransactionAdherentPrestataire extends Transaction
protected $destinataire; protected $destinataire;
/** /**
* @ORM\ManyToOne(targetEntity="Flux")
* @ORM\JoinColumn(name="cancellerflux_id", referencedColumnName="id", nullable=true)
*/
protected $cancellerFlux;
/**
* @return string * @return string
*/ */
public function getType(): string public function getType(): string
...@@ -43,4 +49,7 @@ class TransactionAdherentPrestataire extends Transaction ...@@ -43,4 +49,7 @@ class TransactionAdherentPrestataire extends Transaction
'destinataires' => $this->getDestinataire()->getUsers()->toArray(), 'destinataires' => $this->getDestinataire()->getUsers()->toArray(),
]; ];
} }
public function setCancellerFlux($var) {$this->cancellerFlux = $var;}
public function getCancellerFlux() {return $this->cancellerFlux;}
} }
<?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 Version20240312135007 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 flux ADD cancellerflux_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE flux ADD CONSTRAINT FK_7252313ABB04641D FOREIGN KEY (cancellerflux_id) REFERENCES flux (id)');
$this->addSql('CREATE INDEX IDX_7252313ABB04641D ON flux (cancellerflux_id)');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE flux DROP FOREIGN KEY FK_7252313ABB04641D');
$this->addSql('DROP INDEX IDX_7252313ABB04641D ON flux');
$this->addSql('ALTER TABLE flux DROP cancellerflux_id');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_general_ci` COMMENT \'(DC2Type:personal_data)\'');
}
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
{% include '@kohinos/presta/block/infos.html.twig' %} {% include '@kohinos/presta/block/infos.html.twig' %}
{% endif %} {% endif %}
{# {% include '@kohinos/block/transactions.html.twig' %} #} {# {% include '@kohinos/block/transactions.html.twig' %} #}
{% include '@kohinos/block/operations.html.twig' %} {% include '@kohinos/block/operations.html.twig' with {'display_cancel_transaction_btn' : true} %}
{% if not tav_env %} {% if not tav_env %}
{% if getCurrentPrestataire().mlc == true %} {% if getCurrentPrestataire().mlc == true %}
{% include '@kohinos/block/operations.html.twig' with {'title' : 'Compte de fonctionnement €', 'operations': getLastOperations(app.request, app.user, constant('App\\Enum\\CurrencyEnum::CURRENCY_EURO'))} %} {% include '@kohinos/block/operations.html.twig' with {'title' : 'Compte de fonctionnement €', 'operations': getLastOperations(app.request, app.user, constant('App\\Enum\\CurrencyEnum::CURRENCY_EURO'))} %}
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
<th scope="col">Operation</th> <th scope="col">Operation</th>
<th scope="col">Montant</th> <th scope="col">Montant</th>
{# Display column to store btn to cancel transaction adherent prestataire #} {# Display column to store btn to cancel transaction adherent prestataire #}
{% if operation.flux.type = constant('App\\Entity\\Transaction::TYPE_TRANSACTION_ADHERENT_PRESTATAIRE') {% if display_cancel_transaction_btn %}
and app.user in operation.flux.destinataire %}
<th scope="col"></th> <th scope="col"></th>
{% endif %} {% endif %}
</tr> </tr>
...@@ -60,14 +59,26 @@ ...@@ -60,14 +59,26 @@
Moyen : {{ operation.flux.moyen|trans }} Moyen : {{ operation.flux.moyen|trans }}
</div> </div>
</td> </td>
<td class='text-right'><span class='font-weight-bold {{ (operation.montant < 0)? '':'text-primary' }}'>{{ (operation.montant < 0)? '- ':'+ ' }} {{ operation.montant|abs|number_format(2) }} {{ getCurrencyName(operation.currency) }}</span></td> <td><span class='font-weight-bold {{ (operation.montant < 0)? '':'text-primary' }}'>{{ (operation.montant < 0)? '- ':'+ ' }} {{ operation.montant|abs|number_format(2) }} {{ getCurrencyName(operation.currency) }}</span></td>
{# Display btn to cancel transaction adherent prestataire #} {# Display btn to cancel transaction adherent prestataire #}
{% if operation.flux.type = constant('App\\Entity\\Transaction::TYPE_TRANSACTION_ADHERENT_PRESTATAIRE') {% if display_cancel_transaction_btn
and app.user in operation.flux.destinataire %} and operation.flux.type is same as(constant('App\\Entity\\Transaction::TYPE_TRANSACTION_ADHERENT_PRESTATAIRE'))
<td> and app.user in operation.flux.destinataire.users %}
<a href="{{ path('cancel_transactio_adherent_prestataire', {'id': operation.flux.id}) }}" type="button" class="button button-danger"> <td class='text-right'>
<i class="fa fa-remove" aria-hidden="true"></i> {# If transaction has been cancelled already #}
{% if operation.flux.cancellerFlux %}
<button class="btn btn-sm" title="Cette transaction a déjà été annulée." disabled>
<i class="fas fa-undo"></i>
</button>
{% else %}
<a href="{{ path('cancel_transaction_adherent_prestataire', {'id': operation.flux.id}) }}"
type="button"
class="btn btn-sm btn-primary"
title="Annuler cette transaction."
onclick="return confirm('Êtes-vous sûr de vouloir annuler cette transaction et rembourser le client ? L\'opération est irréversible.')">
<i class="fas fa-undo"></i>
</a> </a>
{% endif %}
</td> </td>
{% endif %} {% endif %}
</tr> </tr>
......
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