Commit d6c29285 authored by Johnny Leveneur's avatar Johnny Leveneur
Browse files

pointage valider un nb de place

parent 7c5e6a9f
Loading
Loading
Loading
Loading
+52 −4
Original line number Diff line number Diff line
@@ -336,12 +336,60 @@ class InscriptionController extends AbstractActionController
                            . " a bien été enregistré. " . $inscription->getStringNombrePlacesLibres());
                    }
                } else {
                    $nombrePlaces = 1;
                    if ($inscription->estGroupe()) {
                        $nombrePlacesParam = $this->params()->fromQuery('nombrePlaces');
                        $placesRestantes = (int)$inscription->getNombrePlacesDemandees()
                            - (int)$inscription->getNombrePlacesPointees();

                        if ($nombrePlacesParam !== null
                            && (!is_scalar($nombrePlacesParam) || !ctype_digit((string)$nombrePlacesParam))) {
                            $this->flashMessenger()->addErrorMessage("Le nombre de places à pointer est invalide.");
                            $nombrePlaces = 0;
                        } elseif ($nombrePlacesParam !== null) {
                            $nombrePlaces = (int)$nombrePlacesParam;
                        }

                        if ($nombrePlaces < 1 || $nombrePlaces > $placesRestantes) {
                            $this->flashMessenger()->addErrorMessage("Le nombre de places à pointer doit être compris entre 1 et " . $placesRestantes . ".");
                            $nombrePlaces = 0;
                        }

                        $placesNonPointees = [];
                        foreach ($inscription->getPlaces() as $place) {
                            if (!$place->isPointee()) {
                                $placesNonPointees[] = $place;
                            }
                        }

                        if ($nombrePlaces > count($placesNonPointees)
                            && !$inscription->getPlaces()->isEmpty()) {
                            $this->flashMessenger()->addErrorMessage("Le nombre de places à pointer dépasse le nombre de places nominatives disponibles.");
                            $nombrePlaces = 0;
                        }

                        if ($nombrePlaces > 0) {
                            if (!$inscription->getPlaces()->isEmpty()) {
                                foreach (array_slice($placesNonPointees, 0, $nombrePlaces) as $place) {
                                    $inscription->pointer($place);
                                }
                            } else {
                                for ($i = 0; $i < $nombrePlaces; $i++) {
                                    $inscription->pointer();
                                }
                            }
                        }
                    } else {
                        $inscription->pointer();
                    }

                    if ($nombrePlaces > 0) {
                        $this->getInscriptionService()->update($inscription);
                    $this->flashMessenger()->addSuccessMessage("Le pointage pour <strong>"
                        . "<strong>" . $inscription->getParticipantDenomination() . "</strong>"
                        . " à l'évènement " . "<strong>" . $inscription->getEvenement()->getLibelle() . "</strong>"
                        . " a bien été enregistré. " . $inscription->getStringNombrePlacesLibres());
                        $this->flashMessenger()->addSuccessMessage("Le pointage de " . $nombrePlaces . " place(s) pour <strong>"
                            . $inscription->getParticipantDenomination() . "</strong> à l'évènement <strong>"
                            . $inscription->getEvenement()->getLibelle() . "</strong> a bien été enregistré. "
                            . $inscription->getStringNombrePlacesLibres());
                    }
                }
            }
        }
+5 −3
Original line number Diff line number Diff line
@@ -44,12 +44,14 @@ class InscriptionPlaces extends AbstractHelper

            if ($canPointerInscription) {
                if ($inscription->getNombrePlacesPointees() < $inscription->getNombrePlacesDemandees()) {
                    $html .= '<a class="btn btn-success action js-retour-link" href="'
                    $placesRestantes = $inscription->getNombrePlacesDemandees() - $inscription->getNombrePlacesPointees();
                    $html .= '<a class="btn btn-success action js-retour-link js-pointer-groupe" data-places-restantes="'
                        . $e((string)$placesRestantes) . '" href="'
                        . $this->getView()->url('evenementiel/inscription/pointer', [
                            'entity' => $inscription->getId(),
                        ], true)
                        . '"><span class="icon icon-checked" title="Pointer une place">'
                        . ' Pointer une place</span></a> ';
                        . '"><span class="icon icon-checked" title="Pointer des places">'
                        . ' Pointer des places</span></a> ';
                }

                if ($inscription->getNombrePlacesPointees() > 0) {
+27 −0
Original line number Diff line number Diff line
@@ -128,6 +128,33 @@ $canInscrire = $this->isAllowed(EvenementPrivileges::getResourceId(EvenementPriv
    // generer le lien de retour dans les boutons (dé)pointer créé dans le viewHelper inscriptionPlaces
    // on n’attache pas l’événement directement sur le bouton, mais sur le document (event delegation).
    document.addEventListener('click', function (e) {
        const groupPointerLink = e.target.closest('.js-pointer-groupe');
        if (groupPointerLink) {
            e.preventDefault();

            const placesRestantes = Number(groupPointerLink.dataset.placesRestantes);
            const nombrePlaces = window.prompt(
                'Combien de places du groupe sont présentes ? (1 à ' + placesRestantes + ')',
                placesRestantes
            );

            if (nombrePlaces === null) return;

            const nombrePlacesEntier = Number(nombrePlaces);
            if (!Number.isInteger(nombrePlacesEntier)
                || nombrePlacesEntier < 1
                || nombrePlacesEntier > placesRestantes) {
                window.alert('Veuillez saisir un nombre de places compris entre 1 et ' + placesRestantes + '.');
                return;
            }

            const url = new URL(groupPointerLink.href, window.location.href);
            url.searchParams.set('nombrePlaces', nombrePlacesEntier);
            url.searchParams.set('retour', window.location.href);
            window.location.href = url.toString();
            return;
        }

        // Trouver le lien concerné : closest remonter dans le DOM jusqu’à trouver un élément ayant la classe .js-retour-link
        const link = e.target.closest('.js-retour-link');
        if (!link) return;
+31 −0
Original line number Diff line number Diff line
@@ -163,6 +163,37 @@ class ScanController extends AbstractActionController
                        . htmlspecialchars($inscription->getStringNombrePlacesLibres(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
                        ;
                }
            } elseif ($inscription->estGroupe()) {
                $nombrePlacesPointees = 0;

                // Le QR code général d'un groupe valide toutes ses places nominatives.
                foreach ($inscription->getPlaces() as $place) {
                    if (!$place->isPointee()) {
                        $inscription->pointer($place);
                        $nombrePlacesPointees++;
                    }
                }

                // Un groupe sans places nominatives est pointé sur l'inscription elle-même.
                while ($inscription->getNombrePlacesPointees() < $inscription->getNombrePlacesDemandees()) {
                    $inscription->pointer();
                    $nombrePlacesPointees++;
                }

                if ($nombrePlacesPointees > 0) {
                    $this->getInscriptionService()->update($inscription);
                    $status = 'ok';
                    $ok = true;
                    $msgHtml = 'Le pointage des <strong>' . $nombrePlacesPointees
                        . ' place(s)</strong> du groupe de <strong>' . $participant
                        . '</strong> a bien été enregistré.'
                        . '<br>' . htmlspecialchars($inscription->getStringNombrePlacesLibres(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
                } else {
                    $status = 'warn';
                    $ok = true;
                    $msgHtml = 'Tous les pointages du groupe de <strong>' . $participant
                        . '</strong> ont déjà été effectués.';
                }
            } else {
                $inscription->pointer();
                $this->getInscriptionService()->update($inscription);