<!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">
                                <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_agregar.php" class="btn btn-primary btn-md" 
                                           data-title="Agregar" rel="tooltip"> 
                                            <i class="fa fa-plus"></i> AGREGAR </a>
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                            <form action="diagnostico_index.php" method="post" accept-charset="UTF-8" class="form-horizontal">
                                                <div class="box-body">
                                                    <div class="form-group">
                                                        <div class="col-lg-12 col-md-12 col-sm-12">
                                                            <div class="input-group custom-search-form">
                                                                <input type="search" name="buscar" class="form-control" autofocus=""
                                                                       placeholder="Ingrese descripción a buscar"/>
                                                                <span class="input-group-btn">
                                                                    <button type="submit" class="btn btn-primary" 
                                                                            data-title="Presione para buscar" rel="tooltip">
                                                                        <i class="fa fa-search"></i>
                                                                    </button>
                                                                </span>                                                                
                                                            </div>                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </form>                                            
                                            <?php 
                                            $diagnosticos = consultas::get_datos("select * from v_servicios_diagnostico where cod_suc = ".$_SESSION['cod_suc']." order by diag_fecha::date desc");
                                            if(!empty($diagnosticos)){ ?>
                                            
                                                <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>
                                                            <th class="text-center">Acciones</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>
                                                            <td data-title= "Acciones" class="text-center">
                                                                <?php if($diag['diag_estado']=="ACTIVO"){ ?>
                                                                <a href="diagnostico_det.php?vcod=<?php echo $diag['id_diag'];?>" class="btn btn-primary btn-md" data-title="Detalles" rel="tooltip">
                                                                    <i class="fa fa-list"></i>                                                                    
                                                                </a>     
                                                                <a onclick="anular(<?php echo "'".$diag['id_diag']."_".$diag['cliente']."'"?>)" class="btn btn-danger btn-md" 
                                                                   data-title="Anular" rel="tooltip" data-toggle = "modal" data-target="#anular">
                                                                    <i class="fa fa-remove"></i></a>                                                                
                                                                <?php } ?>
                                                                <a href="diagnostico_printer.php?vcod=<?php echo $diag['id_diag'];?>" class="btn btn-default btn-md" data-title="Imprimir" rel="tooltip" target="print">
                                                                    <i class="fa fa-print"></i>                                                                    
                                                                </a>                                                                
                                                            </td>
                                                        </tr>
                                                         <?php } ?>
                                                    </tbody>
                                                </table>
                   
                                            <?php }else { ?>
                                            <div class="alert alert-info">
                                                <span class="glyphicon glyphicon-info-sign"></span>
                                                No se han registrado pedidos de ventas...
                                            </div>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--archivos js-->  
        <?php require '../../menu/js_lte.ctp'; ?>
            <!-- Inicio Modal Anular-->
            <div class="modal fade" id="anular" 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 anular(datos){
                var dat = datos.split("_");
                $("#si").attr('href', 'diagnostico_control.php?vcod=' + dat[0] + '&accion=3');
                $("#confirmacion").html("<span class='glyphicon glyphicon-warning-sign'>\n\
                </span> Desea anular el diagnostico N° <strong>" 
                + dat[0] + "</strong> del cliente <strong>" + dat[1] + "</strong>?");
            }
        </script>
    </body>
</html>
