<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>BIO - ALMACÉN</title>
        <link href="./view/css/styles.css" rel="stylesheet" />
        <link rel="icon" type="image/x-icon" href="./view/assets/img/trinity_bio/icono_trinity.png" />
        <script data-search-pseudo-elements defer src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/js/all.min.js" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/feather-icons/4.28.0/feather.min.js" crossorigin="anonymous"></script>
    </head>
    <body class="nav-fixed">

        <?php require_once("./view/menu.phtml") ?>

        <div id="layoutSidenav">

            <?php require_once("./view/menuv.phtml") ?>
            
            <div id="layoutSidenav_content">
                <main>
                    <header class="page-header page-header-compact page-header-light border-bottom bg-white mb-4">
                        <div class="container-xl px-4">
                            <div class="page-header-content">
                                <div class="row align-items-center justify-content-between pt-3">
                                    <div class="col-auto mb-3">
                                        <h1 class="page-header-title">
                                            <div class="page-header-icon"><a href="index.php"><i data-feather="corner-up-left"></i></a></div>
                                            ATRÁS
                                        </h1>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </header>
                    
                    <div class="row">
                        <div class="container-xl px-4 mt-4">
                            
                            <nav class="nav nav-borders">
                                <a class="nav-link active ms-0">DEVOLUCIÓN DE PRODUCTOS A EMPRESA</a>
                            </nav>
                            <hr class="mt-0 mb-4" />
                            <div class="row" >
                                
                                <div class="col-xl-12">
                                    
                                    <div class="card mb-4">
                                        <div class="card-header">DEVOLUCIÓN DE PRODUCTOS A EMPRESA</div>
                                        <div class="card-body">
                                            <form method="post" action="devolucion_empresa.php" enctype="multipart/form-data">
                                                
                                                <div class="row gx-3 mb-3">
                                                    
                                                    
                                                    <div class="col-md-12">
                                                        <label class="small mb-1" for="identificacion">FECHA DEVOLUCIÓN</label>
                                                        <input required class="form-control" id="identificacion" name="identificacion" type="date" value="" />
                                                    </div>

                                                </div>



                                                <div class="row gx-3 mb-3">
                                                    <label class="small mb-1" for="datatablesSimple3"><b>PRODUCTOS</b></label>
                                                    <table id="datatablesSimple3" name="datatablesSimple3">
                                                        <thead>
                                                            <tr>
                                                                
                                                                <th>SKU</th>
                                                                <th>PRODUCTO</th>
                                                                <th>DISPONIBLE</th>
                                                                <th>DEVOLUCIÓN</th>
                                                                <th>MALOGRADO</th>
                                                                <th>DEVOLUCIÓN</th>
                                                                <th>MERMA</th>
                                                                <th>DEVOLUCIÓN</th>
                                                                <!-- <th>SERIE</th> -->
                                                            </tr>
                                                        </thead>
                                                        
                                                        <tbody>
                                                            <?php
                                                            foreach($productos as $producto){
                                                               
                                                                if($producto['disponible'] == '0' && $producto['merma'] == '0' && $producto['malogrado'] == '0'){

                                                                }else{
                                                            ?>
                                                            <?php
                                                                if($producto['id_catalogo_serializado'] == 2){
                                                            ?>
                                                            <tr>
                                                                <?php
                                                                if($producto['bio'] == 1){
                                                                ?>
                                                                <td><?=$producto['sku']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /></td>
                                                                <?php
                                                                }else{
                                                                ?>
                                                                <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /></td>
                                                                <?php
                                                                }
                                                                ?>
                                                                <td><?=$producto['nombre_producto']?></td>
                                                                <td><?=$producto['disponible']?><input class="form-control" id="disponible" name="disponible[]" type="hidden" value="<?=$producto['disponible']?>" /></td>
                                                                <td>
                                                                    <input style="border: 0;" class="form-control" id="devolver_disponible" name="devolver_disponible[]" type="number" value="0" min="0" max="<?=$producto['disponible']?>"/>
                                                                </td>
                                                                <td><?=$producto['malogrado']?><input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="<?=$producto['malogrado']?>" /></td>
                                                                <td>
                                                                    <input style="border: 0;" class="form-control" id="devolver_malogrado" name="devolver_malogrado[]" type="number" value="0" min="0" max="<?=$producto['malogrado']?>"/>
                                                                </td>
                                                                <td><?=$producto['merma']?><input class="form-control" id="merma" name="merma[]" type="hidden" value="<?=$producto['merma']?>" /></td>
                                                                <td>
                                                                    <input style="border: 0;" class="form-control" id="devolver_merma" name="devolver_merma[]" type="number" value="0" min="0" max="<?=$producto['merma']?>"/>
                                                                </td>
                                                                
                                                                
                                                                <!-- <td><input style="border: 0;" class="form-control" id="serie" name="serie[]" type="hidden" value="0" placeholder="serie"/></td> -->
                                                            </tr>
                                                            <?php
                                                                }
                                                            ?>

                                                            <!-- <?php
                                                            //  }else{
                                                                    

                                                                    // foreach($series as $serie){

                                                                        // if($serie['id_producto'] == $producto['id_producto']){

                                                                    
                                                                    ?> -->
                                                                    <!-- <tr>
                                                                
                                                                        <?php
                                                                        if($producto['bio'] == 1){
                                                                        ?>
                                                                        <td><?=$producto['sku']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /></td>
                                                                        <?php
                                                                        }else{
                                                                        ?>
                                                                        <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /></td>
                                                                        <?php
                                                                        }
                                                                        ?>
                                                                        <td><?=$producto['nombre_producto']?></td>
                                                                        <?php
                                                                        if($serie['estado_estado'] == 1){
                                                                        ?>
                                                                        <td>1<input class="form-control" id="disponible" name="disponible[]" type="hidden" value="1" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_disponible" name="devolver_disponible[]" type="number" value="0" min="0" max="1"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_malogrado" name="devolver_malogrado[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="merma" name="merma[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_merma" name="devolver_merma[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <?php
                                                                        }elseif($serie['estado_estado'] == 2){
                                                                        ?>
                                                                        <td>0<input class="form-control" id="disponible" name="disponible[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_disponible" name="devolver_disponible[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <td>1<input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="1" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_malogrado" name="devolver_malogrado[]" type="number" value="0" min="0" max="1"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="merma" name="merma[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_merma" name="devolver_merma[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>c
                                                                        <?php
                                                                        }elseif($serie['estado_estado'] == 3){
                                                                        ?>
                                                                         <td>0<input class="form-control" id="disponible" name="disponible[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_disponible" name="devolver_disponible[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_malogrado" name="devolver_malogrado[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <td>1<input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="1" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_merma" name="devolver_merma[]" type="number" value="0" min="0" max="1"/>
                                                                        </td>
                                                                        <?php
                                                                        }else{
                                                                        ?>
                                                                        <td>1<input class="form-control" id="disponible" name="disponible[]" type="hidden" value="1" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_disponible" name="devolver_disponible[]" type="number" value="0" min="0" max="1"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="malogrado" name="malogrado[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_malogrado" name="devolver_malogrado[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <td>0<input class="form-control" id="merma" name="merma[]" type="hidden" value="0" /></td>
                                                                        <td>
                                                                            <input style="border: 0;" class="form-control" id="devolver_merma" name="devolver_merma[]" type="number" value="0" min="0" max="0"/>
                                                                        </td>
                                                                        <?php
                                                                        }
                                                                        ?>
                                                                        <td><?=$serie['serie']?><input style="border: 0;" class="form-control" id="serie" name="serie[]" type="hidden" value="<?=$serie['serie']?>" placeholder="serie"/></td>
                                                                    </tr> -->

                                                                    <?php
                                                                    //     }
                                                                    // }
                                                                    // }
                                                                }
                                                            }
                                                            ?>
                                                            
                                                        </tbody>



                                                    </table>

                                                </div>


                                                <div id="bgu" name ="bgu" class="card-header"><input  onclick="bgus()"  class="form-control btn btn-primary" type="submit" name="DEVOLVER" id="DEVOLVER" value="DEVOLVER"></div>
                                                <div id="bgu2" name ="bgu2"  class="card-header"><input class="form-control btn btn-dark"type="button" name="" id="" value="CARGANDO..."></div>
                                                
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </main>
                <footer class="footer-admin mt-auto footer-light">
                    <div class="container-xl px-4">
                        <div class="row">
                            <div class="col-md-6 small">Copyright &copy; TRINITY ERP - BIO SAC 2022</div>
                            <div class="col-md-6 text-md-end small">
                                <a href="#!">POLÍTICAS DE PRIVACIDAD</a>
                                &middot;
                                <a href="#!">TERMINOS &amp; CONDICIONES</a>
                            </div>
                        </div>
                    </div>
                </footer>
            </div>
        </div>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        <script src="./view/js/scripts.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/simple-datatables@4.0.8" crossorigin="anonymous"></script>
        <script src="./view/js/datatables/datatables-simple-demo.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/litepicker/dist/bundle.js" crossorigin="anonymous"></script>
        <script src="./view/js/litepicker.js"></script>

        <script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" crossorigin="anonymous"></script>

        <script src="./view/js/datatables/datatables-simple-demo1.js"></script>
        <script src="./view/js/datatables/datatables-simple-demo3.js"></script>

        <script>
            var today = new Date().toISOString().split('T')[0];
            document.getElementById("identificacion").setAttribute('max', today);

        </script>

        <script>
            $("#bgu2").hide();
            function bgus() {
                // Verificar si todos los campos requeridos están llenos
                var requiredFields = document.querySelectorAll('input[required]');
                var allRequiredFilled = true;
                requiredFields.forEach(function(field) {
                    if (!field.value.trim()) {
                        allRequiredFilled = false;
                    }
                });

                // Verificar si los campos numéricos cumplen con los requisitos de rango
                var numberFields = document.querySelectorAll('input[type="number"]');
                var allNumbersInRange = true;
                numberFields.forEach(function(field) {
                    var min = field.getAttribute('min');
                    var max = field.getAttribute('max');
                    var value = parseFloat(field.value.trim());
                    if (!isNaN(value) && ((min && value < parseFloat(min)) || (max && value > parseFloat(max)))) {
                        allNumbersInRange = false;
                    }
                });

                // Ejecutar la función si todos los campos cumplen con los requisitos

                if (allRequiredFilled && allNumbersInRange) {
                   
                    $("#bgu").hide();
                    $("#bgu2").show();
                }
            }
        </script>

        <script>

            $("#activar").hide();
            $(document).ready(function(){

                    $("#activar").hide();
            });

            $("#cod").change(function(){

                if($(this).val() != ""){
                    
                    $("#activar").show();


                }else{
                    $("#activar").hide();
                }
            });
        </script>
    </body>
</html>
