<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Gestion de factures</title>

    <link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'>
    <link rel="stylesheet" type="text/css" href="plugins/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="plugins/simple-line-icons.css" />
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.5.0/font/bootstrap-icons.min.css' />
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/css/select2.min.css">
    <link rel="stylesheet" href="plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">
    <!-- Tempusdominus Bootstrap 4 -->
    <link rel="stylesheet" href="plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- JQVMap -->
    <link rel="stylesheet" href="plugins/jqvmap/jqvmap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/adminlte.min.css">
    <!-- overlayScrollbars -->
    <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker.css">
    <!-- summernote -->
    <link rel="stylesheet" href="plugins/summernote/summernote-bs4.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" href="/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <link rel="stylesheet" href="/plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs5/dt-1.10.25/datatables.min.css" />
    <!-- stepper -->
    <link rel="stylesheet" href="plugins/bs-stepper/css/bs-stepper.min.css">
    <link href="css\style.css" rel="stylesheet">
    <!-- Flatpickr -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">

        <!-- Preloader -->

        <!-- Navbar -->
        <nav class="main-header navbar navbar-expand navbar-white navbar-light">

            <!-- Left navbar links -->
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars" style="color: #000000;"></i></a>
                </li>
            </ul>

            <!-- Right navbar links -->
            <ul class="navbar-nav ml-auto">

                <!-- Notifications Dropdown Menu -->

                <li class="nav-item">
                    <a class="nav-link" href="#" role="button" style="color: #000000;" title="Verrouiller la session">
                        <h7 style="color: #000000;">Bienvenue <span id="nom_user"><?php echo e(session('utilisateur')); ?></span></h7>
                        <i class="fas fa-lock" aria-hidden="true"></i>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/" role="button" style="color: #000000;" title="Se déconnecter">
                        <i class="fas fa-power-off" aria-hidden="true"></i>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- /.navbar -->

        <!-- Main Sidebar Container -->
        <aside class="main-sidebar sidebar-dark-primary elevation-4">
            <!-- Brand Logo -->
            <a href="/" class="brand-link" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;font-size: 20px; text-align:center; font-weight: 300;line-height: 50px;">
                <span class="brand-text font-weight-light">GESTION DE FACTURES</span>
            </a>

            <!-- Sidebar -->
            <div class="sidebar">

                <!-- Sidebar Menu -->
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                        <!-- Add icons to the links using the .nav-icon class
               with font-awesome or any other icon font library -->
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-file"></i>
                                <p>
                                    Demandes
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="<?php echo e(route('demande_en_cours')); ?>" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Demandes en saisie</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="<?php echo e(route('demande_terminees')); ?>" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Demandes acceptées</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="<?php echo e(route('demandes')); ?>" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Demandes terminées</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <!-- <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-building"></i>
                                <p>
                                    Biens
                                    <i class="right fas fa-angle-left"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Type de bien</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Liste de tous les biens</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-university"></i>
                                <p>
                                    Souscriptions
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="" class="nav-link" data-toggle="modal" data-target="#SouscriptionModal">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Nouvelle souscription</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Souscriptions en cours</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon text-green"></i>
                                        <p>Souscriptions terminées</p>
                                    </a>
                                </li>
                            </ul>
                        </li> -->
                        <!-- <li class="nav-item">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-cogs"></i>
                                <p>
                                    Paramètres
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Type d'attestation</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="" class="nav-link">
                                        <i class="far fa-circle nav-icon"></i>
                                        <p>Compte</p>
                                    </a>
                                </li>
                            </ul>
                        </li> -->
                    </ul>
                </nav>
                <!-- /.sidebar-menu -->
            </div>
            <!-- /.sidebar -->
        </aside>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <?php echo $__env->yieldContent('content'); ?>
        </div>
        <!-- /.content-wrapper -->
        <footer class="main-footer">
            <div class="pull-right">
                <small>Copyright &copy; <a href="http://www.cian.ci" style="color: red"><b>CIAN</b></a>. Tous droits réservés. <span style="color: red">Version <b id="camp">2022</b></span></small>
            </div>
            <span style="color:#000000; font: bold">Facture</span>
        </footer>

        <!-- Control Sidebar -->
        <aside class="control-sidebar control-sidebar-dark">
            <!-- Control sidebar content goes here -->
        </aside>
        <!-- /.control-sidebar -->
    </div>
    <!-- ./wrapper -->

    <!-- jQuery -->
    <script src="plugins/jquery/jquery.min.js"></script>
    <!-- jQuery UI 1.11.4 -->
    <script src="plugins/jquery-ui/jquery-ui.min.js"></script>
    <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
    <script>
        $.widget.bridge('uibutton', $.ui.button)
    </script>
    <!-- Bootstrap 4 -->
    <script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- ChartJS -->
    <script src="plugins/chart.js/Chart.min.js"></script>
    <!-- Sparkline -->
    <script src="plugins/sparklines/sparkline.js"></script>
    <!-- JQVMap -->
    <script src="plugins/jqvmap/jquery.vmap.min.js"></script>
    <script src="plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
    <!-- jQuery Knob Chart -->
    <script src="plugins/jquery-knob/jquery.knob.min.js"></script>
    <!-- daterangepicker -->
    <script src="plugins/moment/moment.min.js"></script>
    <script src="plugins/daterangepicker/daterangepicker.js"></script>
    <!-- Tempusdominus Bootstrap 4 -->
    <script src="plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
    <!-- Summernote -->
    <script src="plugins/summernote/summernote-bs4.min.js"></script>
    <!-- overlayScrollbars -->
    <script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.js"></script>
    <!-- AdminLTE for demo purposes -->
    <!-- <script src="dist/js/demo.js"></script> -->
    <!-- AdminLTE dashboard demo (This is only for demo purposes) -->
    <!-- <script src="dist/js/pages/dashboard.js"></script> -->
    <!-- Datatables -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
    <script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
    <script src="plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
    <script src="plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
    <script src="plugins/jszip/jszip.min.js"></script>
    <script src="plugins/pdfmake/pdfmake.min.js"></script>
    <script src="plugins/pdfmake/vfs_fonts.js"></script>
    <script src="plugins/datatables-buttons/js/buttons.html5.min.js"></script>
    <script src="plugins/datatables-buttons/js/buttons.print.min.js"></script>
    <script src="plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/v/bs5/dt-1.10.25/datatables.min.js"></script>
    <!-- BS-Stepper -->
    <script src="plugins/bs-stepper/js/bs-stepper.min.js"></script>
    <!-- Select2 -->
    <script src="plugins/select2/js/select2.full.min.js"></script>
    <!-- Custom -->
    <script type="text/javascript" src="https://cdn.datatables.net/v/bs5/dt-1.10.25/datatables.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <!-- flatpickr -->
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> -->


    <script>
        tables();

        function tables() {
            $("table").DataTable({
                order: [0, 'DESC']
            });
        }


        function add_more() {
            var add_more = jQuery('#add_more').val();
            if (add_more > 0) {

                var add = "<div class='form-group' id='box"+add_more+"'><hr><div class='form-group' style='columns: 2;'><label>N° Facture</label><input type='text' name='n_fact[]' id='n_fact' class='form-control' required> <label>Date facture</label><input type='date' name='date_fact[]' id='date_fact' class='form-control' required></div><div class='form-group'><label>ncc Fournisseur</label><input type='text' name='ncc_fact[]' id='ncc_fact' class='form-control' required></div><div class='form-group'><label>Objet</label><input type='text' name='objet_fact[]' id='objet_fact' class='form-control' required></div><div class='form-group' style='columns: 2;'><label>Montant HT</label><input type='number' name='montht_fact[]' id='montht_fact' class='form-control' required> <label>Montant TVA</label><input type='number' name='monttva_fact[]' id='monttva_fact' class='form-control' required></div><div class='form-group'><label for='exampleInputFile'>Joindre une facture proforma</label><div class='input-group'><input type='text' name='facturename[]' id='facturename"+add_more+"' class='form-control' placeholder='Aucun fichier choisi' required><div class='custom-file'> <input type='file' name='facture[]' id='facture"+add_more+"' class='custom-file-input' onchange=printer('"+add_more+"')> <label class='custom-file-label' id='nomfacture"+add_more+"' for='exampleInputFile'>Aucun fichier choisi</label></div><div class='input-group-append'><span id='btn-eye2' onclick='"+add_more+"' class='input-group-text' style='background-color: #16B84E; border-color: #16B84E; border: 1px;'><i class='fas fa-eye' aria-hidden='true' style='color: #ffffff;'></i></span></div></div><button type='button'  id='supprimer' class='btn badge-danger mr-2' onclick=remove_more('"+add_more+"')><i class='bi-trash h4' style='color: #fff;'></i></button></div></div>";
                if ($("#liste_facture").append(add)) {
                    add_more++
                    jQuery('#add_more').val(add_more);
                    $("#d").val(add_more);
                };
            }
        }

        function add_more1() {
            var add_more = jQuery('#d1').val();
            if (add_more > 0) {
                add_more++
                var add = "<div class='form-group' id='box"+add_more+"'><hr><input type='text' name='id_facture[]' id='id_facture' class='form-control'><div class='form-group' style='columns: 2;'><label>N° Facture</label><input type='text' name='n_fact1[]' id='n_fact1' class='form-control' required> <label>Date facture</label><input type='date' name='date_fact1[]' id='date_fact1' class='form-control' required></div><div class='form-group'><label>ncc Fournisseur</label><input type='text' name='ncc_fact1[]' id='ncc_fact1' class='form-control' required></div><div class='form-group'><label>Objet</label><input type='text' name='objet_fact1[]' id='objet_fact1' class='form-control' required></div><div class='form-group' style='columns: 2;'><label>Montant HT</label><input type='number' name='montht_fact1[]' id='montht_fact1' class='form-control' required> <label>Montant TVA</label><input type='number' name='monttva_fact1[]' id='monttva_fact1' class='form-control' required></div><div class='form-group'><label for='exampleInputFile'>Joindre une facture proforma</label><div class='input-group'><input type='text' name='facturename1[]' id='facturename1"+add_more+"' class='form-control' placeholder='Aucun fichier choisi' required><div class='custom-file'> <input type='file' name='facture1[]' id='facture1"+add_more+"' class='custom-file-input' onchange=printer1('"+add_more+"')> <label class='custom-file-label' id='nomfacture1"+add_more+"' for='exampleInputFile'>Aucun fichier choisi</label></div><div class='input-group-append'><span id='btn-eye2' onclick='"+add_more+"' class='input-group-text' style='background-color: #16B84E; border-color: #16B84E; border: 1px;'><i class='fas fa-eye' aria-hidden='true' style='color: #ffffff;'></i></span></div></div><button type='button'  id='supprimer1' class='btn badge-danger mr-2' onclick=remove_more2('"+add_more+"')><i class='bi-trash h4' style='color: #fff;'></i></button></div></div>";
                if ($("#liste_facture1").append(add)) {
                    
                    $("#d1").val(add_more);
                };
            }
        }

        function remove_more(id) {
            jQuery('#box' + id).remove();
            var add_more = jQuery('#add_more').val();
            add_more--;
            jQuery('#add_more').val(add_more);
            $("#d").val(add_more);
        }

        function remove_more2(id) {
            jQuery('#box' + id).remove();
            var add_more = jQuery('#d1').val();
            add_more--;
            jQuery('#d1').val(add_more);
        }

        function remove_more1(id) {
            var add_more = jQuery('#d1').val();
            Swal.fire({
                title: 'Voulez-vous vraiment supprimer cette facture?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajax({
                        url: '<?php echo e(route('delete_facture')); ?>',
                        method: 'delete',
                        data: {
                            id: id,
                            _token: '<?php echo e(csrf_token()); ?>'
                        },
                        success: function(res) {
                            if (res.status == 200) {
                                jQuery('#box' + id).remove();
                                add_more--;
                                jQuery('#d1').val(add_more);
                            } else {
                                Swal.fire(
                                    'Erreur de suppression',
                                    'error'
                                )
                                //console.log(res);
                            }
                        }
                    });
                }
            });
            
        }

        $(document).ready(function() {
        $(document).on('change', '#InputFile', function() {
          const fileInput = document.querySelector("#InputFile");
          let file = fileInput.files[0];
          if (file) {
            let fileName = file.name;
            let fileSize = file.size;
            let fileType = file.type;
            let msg = 'Aucun fichier choisi';
            // console.log(fileName);
            // console.log(fileSize);
            // console.log(fileType);
            if (fileType != 'application/pdf') {
              Swal.fire({
                title: 'Type de fichier non pris en charge, selectionnez un fichier PDF',
                icon: 'error'
              })
              $("#facturename").val(msg);
              $("#nomfacture").text(msg);
            } else {
              if (fileSize > 102400) {
                Swal.fire({
                  title: 'Taille du fichier trop grand, veillez sélectionner un fichier inferieur ou égal à 100 Ko',
                  icon: 'error'
                })
                $("#facturename").val(msg);
                $("#nomfacture").text(msg);
              } else {
                $("#facturename").val(fileName);
                $("#nomfacture").text(fileName);
              }
            }
          }

        });
      });


    //           $(document).ready(function() {
    //     $(document).on('change', '#type_att1', function() {
    //       let file = $(this).val();
    //         console.log(file);
    //     });
    //   });

            //Chargement de preuve de paiement de fiche
      function printer(id) {
        
        const fileInput = $('#facture' + id)[0].files[0];

          if (fileInput) {
            let fileName = fileInput.name;
            let fileSize = fileInput.size;
            let fileType = fileInput.type;
            let msg = 'Aucun fichier choisi';
            // console.log(fileName);
            // console.log(fileSize);
            // console.log(fileType);
            if (fileType != 'application/pdf') {
              Swal.fire({
                title: 'Type de fichier non pris en charge, selectionnez un fichier PDF',
                icon: 'error'
              })
              $("#facturename" + id).val(msg);
              $("#nomfacture" + id).text(msg);
            } else {
              if (fileSize > 102400) {
                Swal.fire({
                  title: 'Taille du fichier trop grand, veillez sélectionner un fichier inferieur ou égal à 100 Ko',
                  icon: 'error'
                })
                $("#facturename" + id).val(msg);
                $("#nomfacture" + id).text(msg);
              } else {
                $("#facturename" + id).val(fileName);
                $("#nomfacture" + id).text(fileName);
              }
            }
          }
      }

    function printer1(id) {
        
        const fileInput = $('#facture1' + id)[0].files[0];

          if (fileInput) {
            let fileName = fileInput.name;
            let fileSize = fileInput.size;
            let fileType = fileInput.type;
            let msg = 'Aucun fichier choisi';
            // console.log(fileName);
            // console.log(fileSize);
            // console.log(fileType);
            if (fileType != 'application/pdf') {
              Swal.fire({
                title: 'Type de fichier non pris en charge, selectionnez un fichier PDF',
                icon: 'error'
              })
              $("#facturename1" + id).val(msg);
              $("#nomfacture1" + id).text(msg);
            } else {
              if (fileSize > 102400) {
                Swal.fire({
                  title: 'Taille du fichier trop grand, veillez sélectionner un fichier inferieur ou égal à 100 Ko',
                  icon: 'error'
                })
                $("#facturename1" + id).val(msg);
                $("#nomfacture1" + id).text(msg);
              } else {
                $("#facturename1" + id).val(fileName);
                $("#nomfacture1" + id).text(fileName);
              }
            }
          }
      }

    function printer3(id) {
        console.log(id);
        const fileInput = $('#facture2' + id)[0].files[0];
        console.log(fileInput);
          if (fileInput) {
            let fileName = fileInput.name;
            let fileSize = fileInput.size;
            let fileType = fileInput.type;
            let msg = 'Aucun fichier choisi';
            // console.log(fileName);
            // console.log(fileSize);
            // console.log(fileType);
            if (fileType != 'application/pdf') {
              Swal.fire({
                title: 'Type de fichier non pris en charge, selectionnez un fichier PDF',
                icon: 'error'
              })
              $("#facturename2" + id).val(msg);
              $("#nomfacture2" + id).text(msg);
            } else {
              if (fileSize > 102400) {
                Swal.fire({
                  title: 'Taille du fichier trop grand, veillez sélectionner un fichier inferieur ou égal à 100 Ko',
                  icon: 'error'
                })
                $("#facturename2" + id).val(msg);
                $("#nomfacture2" + id).text(msg);
              } else {
                $("#facturename2" + id).val(fileName);
                $("#nomfacture2" + id).text(fileName);
              }
            }
          }
      }

        //Enregistrer
        $("#demande-form").submit(function(e) {
            e.preventDefault();
            const fd = new FormData(this);

            Swal.fire({
                title: 'Voulez-vous enregistrer cette demande?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    var spinner = '<button type="submit" id="enr_demande" class="btn btn-primary" disabled><span class="spinner-border-sm" role="status" aria-hidden="true"></span>Enregistrement en cours...</button>'
                    $("#enr_demande").html(spinner);
                    $.ajax({
                        url: '<?php echo e(route('ajout_demande')); ?>',
                        method: 'post',
                        data: fd,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function(res) {
                            if (res.status == 200) {
                                Swal.fire(
                                    'Informations enregistrées avec succès!',
                                    'success'
                                )
                                window.location.href = '/demandesencours'
                            } else {
                                Swal.fire(
                                    'Erreur d\'ajout',
                                    'error'
                                )
                                console.log(res);
                            }
                        }
                    });
                }
            });
        });
        // Fin enregistrer

        // Afficher
        $(document).on('click', '#edit_demande', function(e) {
            e.preventDefault();
            let id = $(this).attr('value');
            $("#id_demande").val(id);
            $.ajax({
             url: '<?php echo e(route('get_demande')); ?>',
             method: 'get',
             data: {
                 id: id,
                 _token: '<?php echo e(csrf_token()); ?>'
             },
             dataType: "json",
             success: function(res) {
                 //console.log(res);
                 $("#show_demande").html(res);
             }
            });
        });

                // Afficher2
        $(document).on('click', '#show_demande', function(e) {
            e.preventDefault();
            let id = $(this).attr('value');
            $("#id_demande").val(id);
            $.ajax({
             url: '<?php echo e(route('show_demande')); ?>',
             method: 'get',
             data: {
                 id: id,
                 _token: '<?php echo e(csrf_token()); ?>'
             },
             dataType: "json",
             success: function(res) {
                 //console.log(res);
                 $("#show").html(res);
             }
            });
        });

        //Modifier
        $("#edt-demande-form").submit(function(e) {
            e.preventDefault();
            const fd = new FormData(this);

            Swal.fire({
                title: 'Voulez-vous enregistrer les modifications de cette demande?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    var spinner = '<button type="submit" id="edt_demande" class="btn btn-primary" disabled><span class="spinner-border-sm" role="status" aria-hidden="true"></span>Modification en cours...</button>'
                    $("#edt_demande").html(spinner);
                    $.ajax({
                        url: '<?php echo e(route('modificationDemande')); ?>',
                        method: 'post',
                        data: fd,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function(res) {
                            if (res.status == 200) {
                                Swal.fire(
                                    'Informations enregistrées avec succès!',
                                    'success'
                                )
                                window.location.href = '/demandesencours'
                            } else {
                                Swal.fire(
                                    'Erreur de modification',
                                    'error'
                                )
                                console.log(res);
                            }
                        }
                    });
                }
            });
        });
        // Fin enregistrer

        // supprimer
        $(document).on('click', '#delete_demande', function(e) {
            e.preventDefault();
            let id = $(this).attr('value');
            Swal.fire({
                title: 'Voulez-vous vraiment supprimer cette demande?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajax({
                        url: '<?php echo e(route('supprimeDemande')); ?>',
                        method: 'delete',
                        data: {
                            id: id,
                            _token: '<?php echo e(csrf_token()); ?>'
                        },
                        success: function(res) {
                            if (res.status == 200) {
                                Swal.fire({
                                    title: 'Demande supprimée avec succès',
                                    icon: 'success',
                                })
                            } else {
                                Swal.fire(
                                    'Erreur de suppression',
                                    'warning'
                                )
                                //console.log(res);
                            }
                        }
                    });
                }
            });
        });

        // soumettre
        $(document).on('click', '#done_demande', function(e) {
            e.preventDefault();
            let id = $(this).attr('value');
            Swal.fire({
                title: 'Voulez-vous vraiment soumettre cette demande?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    $.ajax({
                        url: '<?php echo e(route('soumettreDemande')); ?>',
                        method: 'get',
                        data: {
                            id: id,
                            _token: '<?php echo e(csrf_token()); ?>'
                        },
                        success: function(res) {
                            if (res.status == 200) {
                                Swal.fire({
                                    title: 'Demande soumise avec succès',
                                    icon: 'success',
                                })
                                window.location.href = '/demandesencours'
                            } else {
                                Swal.fire(
                                    'Erreur de soumission',
                                    'warning'
                                )
                                //console.log(res);
                            }
                        }
                    });
                }
            });
        });

        // Afficher2
        $(document).on('click', '#put_demande', function(e) {
            e.preventDefault();
            let id = $(this).attr('value');
            $('#id_demande_facture').val(id);
            $.ajax({
             url: '<?php echo e(route('get_facture')); ?>',
             method: 'get',
             data: {
                 id: id,
                 _token: '<?php echo e(csrf_token()); ?>'
             },
             dataType: "json",
             success: function(res) {
                 //console.log(res);
                 $("#facture").html(res);
             }
            });
        });

        //Facture normale
        $("#facture-form").submit(function(e) {
            e.preventDefault();
            const fd = new FormData(this);

            Swal.fire({
                title: 'Voulez-vous enregistrer ces informations ?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Oui',
                cancelButtonText: 'Non'
            }).then((result) => {
                if (result.isConfirmed) {
                    var spinner = '<button type="submit" id="enr_facture" class="btn btn-primary" disabled><span class="spinner-border-sm" role="status" aria-hidden="true"></span>Enregistrement en cours...</button>'
                    $("#enr_facture").html(spinner);
                    $.ajax({
                        url: '<?php echo e(route('motif_facture')); ?>',
                        method: 'post',
                        data: fd,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function(res) {
                            if (res.status == 200) {
                                Swal.fire(
                                    'Informations enregistrées avec succès!',
                                    'success'
                                )
                                window.location.href = '/demandesterminee'
                            } else {
                                Swal.fire(
                                    'Erreur d\'enregistrement',
                                    'error'
                                )
                                console.log(res);
                            }
                        }
                    });
                }
            });
        });
        // Fin enregistrer
    </script>
</body>

</html><?php /**PATH F:\facture\resources\views/app.blade.php ENDPATH**/ ?>