<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <?php
        include '../../session.php';
        require '../../conexion.php';
        require '../../menu/css_lte.ctp';
        ?>
    </head>
    <body class="hold-transition skin-blue sidebar-mini">
        <div class="wrapper">
            <?php require '../../menu/cabecera.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <?php require '../../menu/izquierda.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <div class="content-wrapper">
                <!-- AQUI VA EL CONTENIDO DE MARCA -->
                <div class="content">
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <?php if(!empty($_SESSION['mensaje'])){ ?>
                            <div class="alert alert-danger" role="alert" id="mensaje">
                                <span class="glyphicon glyphicon-exclamation-sign"></span>
                                <?php echo $_SESSION['mensaje'];
                                $_SESSION['mensaje'] = '';
                                ?>
                            </div>
                            <?php } ?>
                            <div class="box box-primary">
                                <?php 
                                $diagnosticos = consultas::get_datos("select * from v_servicios_diagnostico where id_diag = ".$_REQUEST['vcod']." order by diag_fecha::date desc");
                                if(!empty($diagnosticos)){ ?>                                
                                <div class="box-header">
                                    <i class="fa fa-list"></i>
                                    <h3 class="box-title">Listado de Diagnostico</h3>
                                    <div class="box-tools">
                                        <a href="diagnostico_index.php" class="btn btn-primary btn-md" 
                                           data-title="Volver" rel="tooltip"> 
                                            <i class="fa fa-arrow-left"></i> VOLVER </a>
                                        <a href="diagnostico_printer.php?vcod=<?php echo $diagnosticos[0]['id_diag'];?>" class="btn btn-default btn-md" 
                                           data-title="Imprimir" rel="tooltip" target="_blank"> 
                                            <i class="fa fa-print"></i> IMPRIMIR </a>                                            
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">                                                                                       
                                                <table class="table table-striped table-condensed table-hover dt-responsive">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Fecha</th>
                                                            <th>Cliente</th>
                                                            <th>Recepción</th>
                                                            <th>Estado</th>                                                            
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php foreach ($diagnosticos as $diag) { ?>                                                               
                                                        <tr>
                                                            <td data-title="Codigo"><?php echo $diag['id_diag'];?></td>
                                                            <td data-title="Fecha"><?php echo date("d/m/Y", strtotime($diag['diag_fecha']));?></td>
                                                            <td data-title="Cliente"><?php echo $diag['cliente'];?></td>
                                                            <td data-title="Total"><?php echo $diag['id_entrada'];?></td>
                                                            <td data-title="Estado"><?php echo ($diag['diag_estado']==="ANULADO")? "<span style='color:red';><strong>".$diag['diag_estado']."</strong></span>":$diag['diag_estado'];?></td>
                                                        </tr>
                                                         <?php } ?>
                                                    </tbody>
                                                </table>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <?php $rep_detalles = consultas::get_datos("select * from v_servicios_entrada_detalle where id_entrada=".$diagnosticos[0]['id_entrada']." "
                                                    . "and not exists (select * from servicios_diagnostico_detalle where id_diag =".$diagnosticos[0]['id_diag'].")");
                                            if(!empty($rep_detalles)){ ?>
                                            <div class="box-header">
                                                <i class="fa fa-list"></i>
                                                <h3 class="box-title">Detalles de Recepción</h3>
                                            </div>
                                            <div class="table-responsive">
                                                <table class="table table-striped table-condensed table-hover dt-responsive">
                                                    <thead>
                                                        <tr>
                                                            <th>Item</th>
                                                            <th>Descripción Recepción</th>
                                                            <th class="text-center">Acciones</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php foreach ($rep_detalles as $repd) { ?>                                                               
                                                        <tr>
                                                            <td data-title="Descripción"><?php echo $repd['producto']."/".$repd['modelo']."/".$repd['marca'];?></td>
                                                            <td data-title="Descripción"><?php echo $repd['observacion'];?></td>
                                                            <td data-title= "Acciones" class="text-center">
                                                                <a onclick="add(<?php echo $diagnosticos[0]['id_diag'];?>,<?php echo $repd['id_entrada'];?>,<?php echo "'".$repd['producto']."'";?>)" class="btn btn-success btn-md" 
                                                                   data-title="Agregar" rel="tooltip" data-toggle="modal" data-target="#mymodal">
                                                                    <i class="fa fa-plus"></i>                                                                    
                                                                </a>                                                                                                                                
                                                            </td>
                                                        </tr>
                                                         <?php } ?>
                                                    </tbody>
                                                </table>                                                
                                            </div>
                                            <?php } ?>
                                        </div>
                                    </div><!-- Fin detalles RECEPCION-->                                    
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <?php $detalles = consultas::get_datos("select * from v_servicios_diagnostico_detalle where id_diag=".$diagnosticos[0]['id_diag']);
                                            if(!empty($detalles)){ ?>
                                            <div class="box-header">
                                                <i class="fa fa-list"></i>
                                                <h3 class="box-title">Detalles del pedido</h3>
                                            </div>
                                            <div class="table-responsive">
                                                <table class="table table-striped table-condensed table-hover dt-responsive">
                                                    <thead>
                                                        <tr>
                                                            <th>Descripción</th>
                                                            <th>Diagnostico</th>
                                                            <th class="text-center">Acciones</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php foreach ($detalles as $detalle) { ?>                                                               
                                                        <tr>
                                                            <td data-title="Descripción"><?php echo $detalle['producto']."/".$detalle['modelo']."/".$detalle['marca'];?></td>
                                                            <td data-title="Diagnostico"><?php echo $detalle['diag_obs'];?></td>
                                                            <td data-title= "Acciones" class="text-center">
                                                                <a onclick="borrar(<?php echo $detalle['id_diag'];?>,<?php echo $detalle['id_entrada'];?>,<?php echo "'".$detalle['producto']."'";?>)" class="btn btn-danger btn-md" 
                                                                   data-title="Borrar" rel="tooltip" data-toggle="modal" data-target="#borrar">
                                                                    <i class="fa fa-trash"></i>                                                                    
                                                                </a>                                                                                                                                
                                                            </td>
                                                        </tr>
                                                         <?php } ?>
                                                    </tbody>
                                                </table>                                                
                                            </div>
                                            <?php }else{ ?>
                                                <div class="alert alert-info">
                                                    <span class="glyphicon glyphicon-info-sign"></span>
                                                    El diagnostico aún no posee detalles...
                                                </div>                                                
                                            <?php } ?>
                                        </div>
                                    </div><!-- Fin detalles-->                                    
                                </div>
                                <?php }else { ?>
                                <div class="box-header">                                    
                                    <h3 class="box-title"></h3>
                                    <div class="box-tools">
                                        <a href="diagnostico_index.php" class="btn btn-primary btn-md" 
                                           data-title="Volver" rel="tooltip"> 
                                            <i class="fa fa-arrow-left"></i> VOLVER </a>                                           
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="alert alert-info">
                                        <span class="glyphicon glyphicon-info-sign"></span>
                                        No se encontraron diagnosticos con esos parametros...
                                    </div>                                    
                                </div>                                
                                <?php } ?>                                
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--archivos js-->  
        <?php require '../../menu/js_lte.ctp'; ?>
            <!-- MODAL-->
            <div class="modal fade" id="mymodal" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content" id="detalles">
                        
                    </div>
                </div>
            </div>
            <!-- FIN MODAL-->        
            <!-- Inicio Modal Anular-->
            <div class="modal fade" id="borrar" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">x</button>
                            <h4 class="modal-title custom-align"> <strong>Atención!!!</strong></h4>
                        </div>
                        <div class="modal-body">
                            <div class="alert alert-danger" id="confirmacion">

                            </div>
                        </div>
                        <div class="modal-footer">
                            <a id="si" role="buttom" class="btn btn-primary">
                                <i class="fa fa-check"></i> Si
                            </a>
                            <button type="reset" data-dismiss="modal" class="btn btn-default" 
                                    data-title="Cancelar" rel="tooltip">
                                <i class="fa fa-close"></i> No
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Fin Modal -->         
        <script>
            function add(diag,entra,prod){
                //alert(diag+'-'+entra+'-'+prod)
                $.ajax({
                    type: "get",
                    url : "diagnostico_entrada?vcod="+diag+"&ventrada="+entra+"&vproducto="+prod,
                    cache:false,
                    beforeSend:function(){
                        $("#detalles").html('<img src="../../img/ajax-loader.gif"/><strong>Cargando...</strong>');
                    },
                    success:function(data){
                        $("#detalles").html(data)
                    }
                });
            }             
            function borrar(diag,entra,prod){
                $("#si").attr('href', 'diagnostico_dcontrol.php?vcod=' + diag + '&vrecepcion='+ entra +'&vproducto='+prod+'&accion=3');
                $("#confirmacion").html("<span class='glyphicon glyphicon-warning-sign'>\n\
                </span> Desea quitar el item <strong>"+prod+"</strong>?");
            }
        </script>
    </body>
</html>
