Commit b4013766 by Damien Moulard

encaissement max amount based on conventionnement

parent 35151662
......@@ -405,3 +405,27 @@ form[name="formEncaissement"] label {
text-align: right;
font-style: italic;
}
.presta-conventionnement-applied-text {
margin-top: -0.75rem !important;
margin-bottom: 1rem;
font-size: 100%;
}
.montant-panier-error {
margin-top: -0.75rem !important;
margin-bottom: 1rem;
font-size: 100%;
color: #ff4136;
}
.input-error {
border-color: #ff4136 !important;
}
.input-error:focus {
box-shadow: 0 0 0 0.2rem #ff403667 !important;
}
.text-error {
color: #ff4136;
}
\ No newline at end of file
......@@ -494,6 +494,80 @@ $(function() {
// Set payment summary on validation page
let recap = `${$("#formEncaissement_adherent option:selected").text()}, montant : ${$("#formEncaissement_montant").val()} ${KOH_MLC_NAME_SMALL}`;
$(".payment-recap").text(recap);
// If conventionnement mode is active
if ($(this).find("#formEncaissement_montantPanier").length > 0) {
$("#formEncaissement_montant").prop("disabled",true);
let maxAmount = 0;
function disableMontant() {
$("#formEncaissement_montant").val("");
$("#formEncaissement_montant").prop("disabled", true);
$(".presta-conventionnement-applied-text").hide();
}
function checkMontantPanier() {
let input = $("#formEncaissement_montantPanier");
let val = input.val();
if (val === '') {
// reset
$(".montant-panier-error").hide();
input.removeClass('input-error');
disableMontant();
} else {
let basketAmount = parseFloat(val);
if (isNaN(basketAmount)) {
// display error and reset the rest
$(".montant-panier-error").show();
input.addClass('input-error');
disableMontant();
return;
}
$(".montant-panier-error").hide();
input.removeClass('input-error');
// no error: enable amount field, set max emlc amount and display helper text
$("#formEncaissement_montant").prop("disabled", false);
$(".presta-conventionnement-applied-text").show();
maxAmount = parseFloat(formEncaissementConventionnement) * basketAmount;
$(".encaissment-emlc-max-amount").text(maxAmount);
}
}
checkMontantPanier();
// enable emlc amount field if basket amount is set and valid
$("#formEncaissement_montantPanier").on("input", checkMontantPanier);
function checkMaxAmount() {
function reset() {
$("#formEncaissement_montant").removeClass('input-error');
$(".encaissment-emlc-max-amount-container").removeClass("text-error");
}
let val = $("#formEncaissement_montant").val();
if (val === '') {
reset();
} else {
let amount = parseFloat(val);
if (!isNaN(amount) && amount > maxAmount) {
$(this).addClass('input-error');
$(".encaissment-emlc-max-amount-container").addClass("text-error");
} else if (!isNaN(amount) && amount <= maxAmount) {
reset();
}
}
}
checkMaxAmount();
$("#formEncaissement_montant").on("input", checkMaxAmount);
}
}
/**
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,10 +3,10 @@
"app": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/app.a926d504.js"
"/build/app.29f72415.js"
],
"css": [
"/build/app.6350a995.css"
"/build/app.04bd0e32.css"
]
},
"admin": {
......
{
"build/app.css": "/build/app.6350a995.css",
"build/app.js": "/build/app.a926d504.js",
"build/app.css": "/build/app.04bd0e32.css",
"build/app.js": "/build/app.29f72415.js",
"build/admin.css": "/build/admin.4de55830.css",
"build/admin.js": "/build/admin.86a2d986.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
......
......@@ -243,11 +243,30 @@ class UserController extends AbstractController
}
/**
* Payment terminal page.
*
* @Route("/encaissement", name="encaissement")
* @IsGranted({"ROLE_CAISSIER", "ROLE_PRESTATAIRE"})
*/
public function encaissementAction(Request $request)
{
// If conventionnement process is activated, prevent access to payment terminal if prestataire conventionnement is not set
$conventionnementMode = $this->getParameter('presta_self_init_and_eval');
if ($conventionnementMode == true) {
$presta = $this->session->get('_prestagere');
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$conventionnement = $presta->getConventionnement();
if ($conventionnement == null || $conventionnement == 0) {
$this->addFlash(
'error',
$this->translator->trans("Impossible d'accéder au terminal de paiement tant que votre conventionnement n'a pas été établi par un·e gestionnaire.")
);
return $this->redirectToRoute('index');
}
}
$form = $this->createForm(EncaissementFormType::class, null, []);
$form->handleRequest($request);
$validation = false;
......@@ -280,6 +299,22 @@ class UserController extends AbstractController
goto end;
}
// If entered amount is above maximum amount, depending on prestataire conventionnement
if ($conventionnementMode == true) {
$transaction_amount = floatval($data["montant"]);
$montantPanier = floatval($form['montantPanier']->getData());
$maxAmount = $montantPanier * floatval($conventionnement);
if ($transaction_amount > $maxAmount) {
$this->addFlash(
'error',
$this->translator->trans('Montant maximal en MonA dépassé. Veuillez modifier le montant en MonA.')
);
goto end;
}
}
$input_code = $data["payment_code"];
$validation = true; // When the form is submitted & valid, and the user account checks passed, we enter the validation process
......@@ -329,13 +364,15 @@ class UserController extends AbstractController
goto end;
}
// Save transaction
$flux = new TransactionAdherentPrestataire();
$flux->setExpediteur($adherent);
$presta = $this->session->get('_prestagere');
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
if (!isset($presta)) {
$presta = $this->session->get('_prestagere');
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
}
$flux->setDestinataire($presta);
$flux->setOperateur($this->security->getUser());
......@@ -359,11 +396,17 @@ class UserController extends AbstractController
}
end:
return $this->render('@kohinos/tav/encaissement_page.html.twig', [
$templateData = [
'form' => $form->createView(),
'validation' => $validation,
'insufficientBalance' => $insufficientBalance
]);
];
if ($conventionnementMode == true) {
$templateData['conventionnement'] = $conventionnement;
}
return $this->render('@kohinos/tav/encaissement_page.html.twig', $templateData);
}
/**
......
......@@ -10,23 +10,29 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\Entity\Adherent;
use App\Entity\GlobalParameter;
class EncaissementFormType extends AbstractType
{
protected $em;
protected $security;
protected $container;
public function __construct(
EntityManagerInterface $em,
Security $security
Security $security,
ContainerInterface $container
) {
$this->em = $em;
$this->security = $security;
$this->container = $container;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$mlcName = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NAME_SMALL);
$builder
->add('adherent', EntityType::class, [
'class' => Adherent::class,
......@@ -40,7 +46,7 @@ class EncaissementFormType extends AbstractType
'choice_label' => 'name'
])
->add('montant', NumberType::class, [
'label' => 'Montant : ',
'label' => "Montant en {$mlcName} : ",
'required' => true,
'attr' => ['autocomplete' => 'off']
])
......@@ -52,14 +58,18 @@ class EncaissementFormType extends AbstractType
->add('save', SubmitType::class, ['label' => 'Valider'])
;
$builder
->add('montantPanier', NumberType::class, [
'label' => 'Montant total du panier : ',
'required' => true,
'attr' => ['autocomplete' => 'off'],
'mapped' => false
])
;
if ($this->container->getParameter('presta_self_init_and_eval')) {
$builder
->add('montantPanier', NumberType::class, [
'label' => 'Montant total du panier : ',
'required' => true,
'attr' => ['autocomplete' => 'off'],
'mapped' => false,
'help' => ''
])
;
}
}
......
......@@ -14,7 +14,7 @@
<b>{{ app.session.get('_prestagere') }}</b>
</div>
<h2 class='text-center w-100 mt-4 mb-4'>{{ "Paiement en MonA"|trans }}</h2>
<h2 class='text-center w-100 mt-4 mb-4'>{{ "Paiement"|trans }}</h2>
{% else %}
<div class="mt-3 payment-page-header">
<a href='{{ path('encaissement') }}'>
......@@ -77,8 +77,13 @@
{% if form.montantPanier is defined %}
{{ form_row(form.montantPanier) }}
<small class="form-text text-muted">Conventionnement du point de vente : 50% ; montant maximum payable en MonA : 10 MonA</small>
{# style="display:none;" #}
<div class="presta-conventionnement-applied-text form-text text-muted" style="display:none;">
Conventionnement du point de vente : {{ conventionnement * 100 }}% ;
<span class="encaissment-emlc-max-amount-container">
le montant maximum payable en MonA est de : <span class="encaissment-emlc-max-amount"></span> MonA
</span>
</div>
<div class="montant-panier-error form-text" style="display:none;">La valeur est invalide.</div>
{% endif %}
{{ form_row(form.montant) }}
......@@ -93,6 +98,7 @@
<script type="text/javascript">
var formEncaissementValidation = '{{ validation }}';
var KOH_MLC_NAME_SMALL = "{{ KOH_MLC_NAME_SMALL|default('') }}";
var formEncaissementConventionnement = '{{ conventionnement }}';
</script>
{% endblock %}
......
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