<?php $__env->startSection('intitule'); ?>
    <h4 class="text-uppercase mb-0">INSERTION DES NOTES: <?php echo e($data['intituleUE']); ?></h4>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <li class="breadcrumb-item active" aria-current="page">Insertion notes</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
    <link href="<?php echo e(asset('assets/extra-libs/datatables.net-bs4/css/dataTables.bootstrap4.css')); ?>" rel="stylesheet">

    <link rel="stylesheet" type="text/css"
        href="<?php echo e(asset('assets/extra-libs/datatables.net-bs4/css/responsive.dataTables.min.css')); ?>">

    <link href="<?php echo e(asset('assets/libs/jquery-steps/jquery.steps.css')); ?>" rel="stylesheet">

    <link href="<?php echo e(asset('assets/libs/jquery-steps/steps.css')); ?>" rel="stylesheet">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('main'); ?>
    <div class="row justify-content-center mt-4" style="min-height: calc(85vh - 60px)">
        <div class="col-lg-12">
            <div class="bg-white" style="padding: 25px">
                <h3 class="box-title m-b-0">Notes des étudiants:Rattrapages</h3>
                <p class="text-muted m-b-30 font-13"> Ce formulaire permet de renseigner la note des étudiants...</p>
                <?php if($data['modeResultat'] == 'U'): ?>
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body wizard-content p-0">
                                <h6 class="card-subtitle mb-3"></h6>
                                <form action="<?php echo e(route('insertion.normale.note1')); ?>" class="tab-wizard wizard-circle">
                                    <h6><?php echo e($data['intituleUE']); ?></h6>
                                    <section>
                                        <div class="row justify-content-center">
                                            <table id="datatable" cellpadding="10px" style="border: 1px solid #e9ecef"
                                                class="table table-striped table-hover table-bordered " role="grid">
                                                <thead class="text-info">
                                                    <th>#</th>
                                                    <th>Matricule</th>
                                                    <th>Sexe</th>
                                                    <th>Noms &amp; Prénoms</th>
                                                    <th style="width:150px">
                                                        Notes</th>
                                                </thead>
                                                <?php
                                                $counter = 1;
                                                ?>
                                                <tbody>
                                                    <?php $__currentLoopData = $data['students']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php
                                                            $code_ecu = $data['ecus']->code_ecu;
                                                            $noteEcu = App\Models\NoteEcu::whereRaw('idFiliere=? AND annee=? AND niveauFormation=? AND annee_acad=?  AND code_unite=?  AND code_ecu=?  AND matricule=?', [$data['idFiliere'], $data['annee'], $data['niveauFormation'], $data['annee_acad'], $data['code_unite'], $code_ecu, $student->matricule])->first()->noteEcu;
                                                        ?>
                                                        <tr>
                                                            <td style="width:75px!important">
                                                                <?php echo e($counter); ?></td>
                                                            <td style="width:150px!important"><?php echo e($student->matricule); ?>

                                                            </td>
                                                            <td><?php echo e($student->sexe); ?>

                                                            </td>
                                                            <td><?php echo e($student->nomPrenom); ?></td>
                                                            <td contenteditable align='center'><b><?php echo e($noteEcu); ?></b>
                                                            </td>
                                                        </tr>
                                                        <?php
                                                        $counter++;
                                                        ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </section>
                                </form>
                            </div>
                        </div>
                    </div>
                <?php else: ?>
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body wizard-content p-0">
                                <?php
                                    $counterEtu = 0;
                                ?>
                                <form action="<?php echo e(route('insertion.rattrapage.note1')); ?>" class="tab-wizard wizard-circle">
                                    <h6><?php echo e($data['intituleUE']); ?></h6>
                                    <section>
                                        <div class="row justify-content-center">
                                            <div class="wizard-content">
                                                <div class="wizard-pane active" role="tabpanel" aria-expanded="true">
                                                    <div style="padding-left: 10%!important;padding-right:10%!important;">
                                                        <table id="datatable" cellpadding="10px"
                                                            style="border: 1px solid #e9ecef"
                                                            class="table table-striped table-hover table-bordered "
                                                            role="grid">
                                                            <thead class="text-info">
                                                                <td>#</td>
                                                                <td>Matricule</td>
                                                                <td>Noms &amp; Prénoms</td>
                                                                <?php $__currentLoopData = $data['ecus']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <td style="width:150px">
                                                                        Notes (<?php echo e($ec->intituleEcu); ?>)</td>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </thead>
                                                            <tbody>
                                                                <?php $__currentLoopData = $data['students']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php
                                                                        $counterEtu++;
                                                                        $counterEC = 0;
                                                                    ?>
                                                                    <tr role="row">
                                                                        <td><?php echo e($counterEtu); ?></td>
                                                                        <td><?php echo e($student->matricule); ?></td>

                                                                        <td><?php echo e($student->nom . ' ' . $student->prenom); ?>

                                                                        </td>
                                                                        <?php $__currentLoopData = $data['ecus']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                            <?php
                                                                                $counterEC++;
                                                                                $note = App\Models\NoteEcu::whereRaw('idFiliere=? AND annee=? AND niveauFormation=? AND annee_acad=?  AND code_unite=?  AND code_ecu=?  AND matricule=?', [$data['idFiliere'], $data['annee'], $data['niveauFormation'], $data['annee_acad'], $data['code_unite'], $ec->code_ecu, $student->matricule])->first()->noteEcu;
                                                                            ?>
                                                                            <td contenteditable>
                                                                                <input type="number" min="0"
                                                                                    max="<?php echo e($data['echelle']); ?>"
                                                                                    step="0.1"
                                                                                    name="noteEC<?php echo e($counterEC . '_Etu' . $counterEtu); ?>"
                                                                                    id="noteEC<?php echo e($counterEC . '_Etu' . $counterEtu); ?>"
                                                                                    value=<?php echo e($note); ?>

                                                                                    style="width:200px;border: 1px solid #e9ecef;"
                                                                                    required>
                                                                            </td>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                    </tr>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </section>
                                </form>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script src="<?php echo e(asset('assets/extra-libs/datatables.net/js/jquery.dataTables.min.js')); ?>"></script>

    <script src="<?php echo e(asset('assets/extra-libs/datatables.net-bs4/js/dataTables.responsive.min.js')); ?>"></script>

    <script src="<?php echo e(asset('dist/js/pages/datatable/datatable-basic.init.js')); ?>"></script>

    <script>
        $(document).ready(function() {
            $('#datatable').DataTable();
        });
        $(document).ready(function() {
            $('#datatable2').DataTable();
        });
        $(document).ready(function() {
            $('#datatable3').DataTable();
        });
    </script>

    <script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
    <script src="<?php echo e(asset('dist/js/pages/datatable/datatable-advanced.init.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/libs/jquery-steps/build/jquery.steps.min.js')); ?>"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.4.29/dist/sweetalert2.all.min.js"></script>
    <script src="<?php echo e(asset('assets/extra-libs/toastr/dist/build/toastr.min.js')); ?>"></script>

    <script>
        //Custom design form example
        $(".tab-wizard").steps({
            headerTag: "h6",
            bodyTag: "section",
            transitionEffect: "fade",
            titleTemplate: '<span class="step">#index#</span> #title#',
            labels: {
                finish: "Submit"
            },
            onFinished: function(event, currentIndex) {
                if ( /*allCaseValid()*/ 1) {
                    Swal.fire({
                        title: 'Confirmer cette opération?',
                        text: "Cette opération ajoutera les notes des étudiants dans la base",
                        icon: 'info',
                        showCancelButton: true,
                        confirmButtonColor: 'rgb(44, 208, 126)',
                        cancelButtonColor: '#d33',
                        cancelButtonText: 'Annuler',
                        reverseButtons: true,
                        confirmButtonText: 'Confirmer l\'opération',
                        backdrop: true,
                        preConfirm: () => {
                            let url = "<?php echo e(route('insertion.rattrapage.note1')); ?>";
                            let allNotes = [];
                            let allEC = [];
                            let allMatricules = [];

                            for (let i = 1; i <= <?php echo e($counterEC); ?>; i++) {
                                allNotes[i - 1] = [];
                                allEC.push(JSON.parse('<?php echo $data['ecus']; ?>')[i - 1]["code_ecu"]);
                                for (let j = 1; j <= <?php echo e($counterEtu); ?>; j++) {
                                    allNotes[i - 1].push($("#noteEC" + i + "_Etu" + j).val());
                                    if (i == 1) {
                                        allMatricules.push(JSON.parse('<?php echo $data['students']; ?>')[j - 1][
                                            "matricule"
                                        ]);
                                    }
                                }
                            }

                            let token = document
                                .querySelector('meta[name="csrf-token"]')
                                .getAttribute("content");

                            let options = {
                                headers: {
                                    "Content-Type": "application/json",
                                    Accept: "application/json, text-plain, */*",
                                    "X-Requested-With": "XMLHttpRequest",
                                    "X-CSRF-TOKEN": token,
                                },
                                method: "post",
                                credentials: "same-origin",
                                body: JSON.stringify({
                                    code_unite: "<?php echo $data['code_unite']; ?>",
                                    idFiliere: "<?php echo $data['idFiliere']; ?>",
                                    etudeYear: "<?php echo $data['students']->first()->annee; ?>",
                                    acadYear: "<?php echo $data['students']->first()->inscription_actuelle; ?>",
                                    formation: "<?php echo $data['students']->first()->niveauFormation; ?>",
                                    ec: allEC,
                                    plafond: "<?php echo $data['plafond']; ?>",
                                    matricules: allMatricules,
                                    notes: allNotes
                                }),
                            };
                            return fetch(url, options)
                                .then((response) => response.json())
                                .then((response) => {
                                    console.log(response);
                                    if (!response.success) {
                                        throw new Error("L'opération à échoué");
                                    };
                                })
                                .catch((e) => {
                                    console.log(e);
                                    throw new Error("L'opération à échoué");
                                });
                        },
                        allowOutsideClick: () => !Swal.isLoading(),
                        showLoaderOnConfirm: true,
                    }).then((result) => {
                        if (result.isConfirmed) {
                            Swal.fire(
                                'Insertion des notes de <?php echo e($counterEtu - 1); ?> étudiants',
                                'réalisée avec succès.',
                                'success'
                            );
                            window.location.replace("<?php echo e(route('insertion.reprise')); ?>");
                        }
                    }).catch(() => {
                        Swal.fire({
                            icon: 'error',
                            title: 'Oops...',
                            text: 'Une erreur s\'est produite lors de l\'insertion',

                        });
                    });
                } else {
                    $('.wizard-content .wizard>.steps>ul>li').removeClass("done");
                    toaster("error", "Veuillez entrer toutes les notes...");
                }
            }
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/africawebstudent/public_html/aws/results/resources/views/insertion/listeRattrapage.blade.php ENDPATH**/ ?>