<!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 src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <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>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></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="liquidacion_cliente.php"><i data-feather="corner-up-left"></i></a></div>
                                            ATRÁS
                                        </h1>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </header>
                    <hr class="mt-0 mb-4" />
                    
                    <div class="row">
                        <div class="container-xl px-4 mt-4">
                            
                            <nav class="nav nav-borders">
                                <a class="nav-link active ms-0">LIQUIDACIÓN  - <?=$tecnico['NOMBRES']?></a>
                            </nav>

                            <form method="post" action="liquidacion_cliente_tecnico.php?tecnico=<?=$id?>" enctype="multipart/form-data">
                              
                                <hr class="mt-0 mb-4" />

                                <div class="row">

                                            
                                    
                                    <div class="col-xl-12">
                                        
                                        <div class="card mb-4">
                                                <div class="card-header">LIQUIDACIÓN DE PRODUCTOS A CLIENTE</div>
                                                <div class="card-body">
                                                    
                                                        
                                                        <div class="row gx-3 mb-3">
                                                            
                                                            

                                                            <div class="col-md-12">
                                                                <label class="small mb-1" for="fl">FECHA LIQUIDACIÓN</label>
                                                                <input required class="form-control" id="fl" name="fl" type="date" value="" />
                                                            </div>

                                                        </div>
                                                        <div class="row gx-3 mb-3">
                                                            
                                                            <div class="col-md-6">
                                                                <label class="small mb-1" for="codigo">CÓDIGO CLIENTE</label>
                                                                <input class="form-control" id="codigo" name="codigo" type="text" value="" />
                                                            </div>

                                                            <div class="col-md-6">
                                                                <label class="small mb-1" for="orden">NÚMERO DE ACTIVIDAD</label>
                                                                <input required class="form-control" id="orden" name="orden" type="text" value="" />
                                                            </div>

                                                        </div>
                                                    
                                                </div>
                                        </div>
                                    </div>
                                </div>
                                <hr class="mt-0 mb-4" />

                                <div class="row">
                                    
                                    <div class="col-xl-12">
                                        
                                        <div class="card mb-4">
                                            <div class="card-header">PRODUCTOS ASIGNADOS</div>
                                            <div class="card-body">
                                                
                                                    

                                                    <div class="row gx-3 mb-3" >
                                                        <table id="datatablesSimple2" name="datatablesSimple2">
                                                            <thead>
                                                                <tr>
                                                                    <th>SKU CLIENTE</th>
                                                                    <th>PRODUCTO</th>
                                                                    <th>DISPONIBLE</th>
                                                                    <th>CANTIDAD A LIQUIDAR</th>
                                                                    
                                                                    <th>SERIE</th>
                                                                </tr>
                                                            </thead>
                                                            
                                                            <tbody>
                                                                <?php
                                                                foreach($productos as $producto){
                                                                    if($producto['disponible'] != 0){
                                                                        if($producto['id_catalogo_serializado'] == 2){
                                                                            $liquidados = $ges->get_cantidad_liquidacion($producto['id_producto_servicio'],$id);
                                                                            $producto['disponible'] = $producto['disponible'] - $liquidados['total'];

                                                                ?>
                                                                <tr>
                                                                    <?php
                                                                    if($producto['bio'] == 1){
                                                                    ?>
                                                                    <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /><input class="form-control" id="asig" name="asig[]" type="hidden" value="<?=$producto['asig']?>" /><input class="form-control" id="tecnico" name="tecnico[]" type="hidden" value="<?=$producto['id_tecnico']?>" /></td>
                                                                    <?php
                                                                    }else{
                                                                    ?>
                                                                    <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /><input class="form-control" id="asig" name="asig[]" type="hidden" value="<?=$producto['asig']?>" /><input class="form-control" id="tecnico" name="tecnico[]" type="hidden" value="<?=$producto['id_tecnico']?>" /></td>
                                                                    <?php
                                                                    }
                                                                    ?>
                                                                    <td><?=$producto['nombre_producto']?></td>
                                                                    <td><?=$producto['disponible']?><input class="form-control" id="cantidad" name="cantidad[]" type="hidden" value="<?=$producto['disponible']?>"/></td>
                                                                    <td>
                                                                        <input style="border: 0;" class="form-control" id="devolver" name="devolver[]" type="number" value="0" min="0" max="<?=$producto['disponible']?>"/>
                                                                    </td>
                                                                    
                                                                    <td><input style="border: 0;" class="form-control" id="serie" name="serie[]" type="hidden" value="0" placeholder="serie"/></td>
                                                                </tr>
                                                                <?php
                                                                    }else{

                                                                        foreach($series as $serie){

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

                                                                        
                                                                        ?>
                                                                        <tr>
                                                                    
                                                                            <?php
                                                                            if($producto['bio'] == 1){
                                                                            ?>
                                                                            <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /><input class="form-control" id="asig" name="asig[]" type="hidden" value="<?=$producto['asig']?>" /><input class="form-control" id="tecnico" name="tecnico[]" type="hidden" value="<?=$producto['id_tecnico']?>" /></td>
                                                                            <?php
                                                                            }else{
                                                                            ?>
                                                                            <td><?=$producto['sku_cliente']?><input class="form-control" id="sku" name="sku[]" type="hidden" value="<?=$producto['id_producto']?>" /><input class="form-control" id="asig" name="asig[]" type="hidden" value="<?=$producto['asig']?>" /><input class="form-control" id="tecnico" name="tecnico[]" type="hidden" value="<?=$producto['id_tecnico']?>" /></td>
                                                                            <?php
                                                                            }
                                                                            ?>
                                                                            <td><?=$producto['nombre_producto']?></td>
                                                                            <td>1<input class="form-control" id="cantidad" name="cantidad[]" type="hidden" value="1" /></td>
                                                                            <td>
                                                                                <input style="border: 0;" class="form-control" id="devolver" name="devolver[]" type="number" value="0" min="0" max="1"/>
                                                                            </td>
                                                                            
                                                                            <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 class="modal fade" id="ModalScrollable" tabindex="-1" role="dialog" aria-labelledby="ModalScrollableTitle" aria-hidden="true">
                                                        <div class="modal-dialog modal-dialog-centered modal-sm" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title text-center" id="ModalScrollableTitle11">ALERTA!</h5>
                                                                    <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                                                                </div>
                                                                <div class="modal-body">
                                                                    <div class="col-xxl-12 col-xl-12 mb-4">
                                                                        <div class="timeline-item" style="margin-bottom: 10px;">
                                                                            <div class="timeline-item-content text-center">
                                                                                <b>Esta orden de trabajo ya ha sido liquidado antes.<br>¿Desea Dontinuar?</b>
                                                                            </div>
                                                                            <div class="timeline-item-actions text-center">
                                                                            <button type="button" class="btn btn-primary" onclick="document.getElementById('LIQUIDAR').click();">Sí</button>
                                                                                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">No</button>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                            
                                                    <div class="card-header" id = "indirecto" name = "indirecto">
                                                        <button type="button" class="form-control btn btn-primary" data-bs-toggle="modal" data-bs-target="#ModalScrollable">LIQUIDAR</button>
                                                    </div>
                                                    <div class="card-header" id = "directo" name = "directo">
                                                        <input class="form-control btn btn-primary" type="submit" name="LIQUIDAR" id="LIQUIDAR" value="LIQUIDAR">
                                                    </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </form>
                        </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>

            $("#directo").show();
            $("#indirecto").hide();

            $("#orden").change(function(){
                if($(this).val() != ""){

                    var orden = document.getElementById("orden").value;
                    var formData = new FormData();
                    formData.append('orden', orden);
                    fetch('ajax/consulta_liquidacion.php', {
                        method: 'POST', 
                        body: formData
                    })
                    .then(response => response.text())
                    .then(response => {
                        response = response.trim();
                        if (response === '0') {

                            $("#directo").show();
                            $("#indirecto").hide();
                            
                        }else{

                            $("#directo").hide();
                            $("#indirecto").show();

                        }
                    })
                    .catch(error => {
                        console.error('Error en la solicitud:', error);
                    });

                }
            });
            


        </script>



        <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="./view/js/datatables/datatables-simple-demo1.js"></script>
        <script src="./view/js/datatables/datatables-simple-demo2.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>
            var today = new Date().toISOString().split('T')[0];
            document.getElementById("fl").setAttribute('max', today);
        </script>


        <script>

            function deleteRow(btn) {
                var row = btn.parentNode.parentNode;
                row.parentNode.removeChild(row);
            }

        </script>

        <script>

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

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

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

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


                }else{
                    $("#activar").hide();
                }
            });
        </script>
        <script>
            $('#datatablesSimple1').on('keydown', 'input, select', function(e) {
                if (e.key === "Enter") {
                    var self = $(this), form = self.parents('form:eq(0)'), focusable, next;
                    focusable = form.find('input,a,select,button,textarea').filter(':visible');
                    next = focusable.eq(focusable.index(this)+1);
                    if (next.length) {
                        next.focus();
                    } else {
                        form.submit();
                    }
                    return false;
                }
            });
        </script>
    </body>
</html>
