<?php
include '../../session.php';
?>

<!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
        require '../../conexion.php';
        require '../../menu/css_lte.ctp';
        ?>
    </head>
    <body class="hold-transition skin-blue sidebar-mini">
        <div id="wrapper">
            <?php require '../../menu/cabecera.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <?php require '../../menu/izquierda.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <div class="content-wrapper">
                <div class="content">   
                    <div class="row">
                        <!--impresion del titulo de la pagina-->
                        <div class="col-lg-12">

                            <h3 class="page-header">Listado de Notas de Remision 
                                <a data-toggle="modal" data-target="#registrar" onclick="registrar1()"
                                   class="btn btn-primary btn-circle pull-right" 
                                   rel="tooltip" data-title="Registrar">
                                    <i class="fa fa-plus"></i> AGREGAR
                                </a>

                            </h3>
                        </div>     
                    </div>
                    <!-- /.row -->
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    Datos
                                </div>
                                <?php
                                if (isset($_SESSION['vcod'])) {
                                    if (($_SESSION['vcod'] > 0)) {
                                        $_REQUEST['vcod'] = $_SESSION['vcod'];
                                    }
                                }
                                $nremision = consultas::get_datos("select * from v_remision_nota_venta order by id_nrv");
                                if (!empty($nremision)) {
                                    ?>                         
                                    <!-- /.panel-heading -->
                                    <div class="panel-body">
                                        <div>
                                            <table id="example1" width="100%" 
                                                   class="table table-striped table-bordered table-hover tablas">
                                                <thead>
                                                    <tr>
                                                        <th class="text-center">#</th>
                                                        <th class="text-center">Fecha</th>
                                                        <th class="text-center">Destinatario</th>
                                                        <th class="text-center">Conductor</th>
                                                        <th class="text-center">Vehiculo </th>
                                                        <th class="text-center">Fecha de Inicio</th>
                                                        <th class="text-center">Fecha de Fin</th>
                                                        <th class="text-center">Estado</th>
                                                        <th class="text-center">Acciones</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="buscar">
                                                    <?php foreach ($nremision as $nremi) { ?> 
                                                        <tr>
                                                            <td class="text-center"><?php echo $nremi['nro_nremision']; ?></td>
                                                            <td class="text-center"><?php echo date("d/m/Y", strtotime($nremi['nrv_fecha'])); ?></td>
                                                            <td class="text-center"><?php echo $nremi['cliente']; ?></td>
                                                            <td class="text-left"><?php echo $nremi['empleado']; ?></td>
                                                            <td class="text-left"><?php echo $nremi['chapa']." ".$nremi['marca']; ?></td>
                                                            <td class="text-center"><?php echo date("d/m/Y", strtotime($nremi['finicio_translado'])); ?></td>
                                                            <td class="text-center"><?php echo date("d/m/Y", strtotime($nremi['ffin_translado'])); ?></td>
                                                            <td class="text-center"><?php echo $nremi['nr_estado']; ?></td>
                                                            <td class="text-center">
                                                                    <?php if ($nremi['nr_estado'] == 'PENDIENTE') { ?>                                                                        
                                                                               <a onclick="confirmar(<?php echo "'" . $nremi['id_nrv'] . "_" . $nremi['nro_nremision'] . "'"; ?>)"
                                                                               data-toggle="modal" data-target="#confirm"
                                                                               class="btn btn-sm btn-success" rel='tooltip' 
                                                                               data-title="Confirmar">
                                                                                <span class="glyphicon glyphicon-check"></span>
                                                                            </a>                                                                         
                                                                    <?php } ?>                                                                
                                                                    <a href="detremision_agregar.php?vcod=<?php echo $nremi['id_nrv']; ?>" class="btn btn-sm btn-primary" rel='tooltip' data-title="Detalles">
                                                                        <i class="fa fa-list"></i>
                                                                    </a>

                                                                    <?php if ($nremi['nr_estado'] === 'PENDIENTE') { ?>
                                                                            <a onclick="anular(<?php echo "'" . $nremi['id_nrv'] . "_" . $nremi['nro_nremision'] . "'"; ?>)"
                                                                               data-toggle="modal" data-target="#delete"
                                                                               class="btn btn-sm btn-danger" rel='tooltip' 
                                                                               data-title="Anular">
                                                                                <span class="glyphicon glyphicon-remove"></span>
                                                                            </a>

                                                                    <?php } ?>
                                                            </td>
                                                        </tr>
                                                    <?php } ?>
                                                </tbody>
                                            </table>                         
                                        </div>
                                    <?php } else { ?>
                                        <div class="alert alert-info alert-dismissable">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
                                                &times;</button>
                                            <strong>No se encontraron registros....!</strong>
                                        </div>
                                    <?php } ?>  
                                    <!-- /.panel-body -->
                                </div>
                            </div>
                            <!-- /.panel -->
                        </div>
                        <!-- /.col-lg-12 -->
                    </div>
                    <!-- /.registrar -->
                    <div id="registrar" class="modal fade" role="dialog">
                        <div class="modal-dialog" >
                            <div class="modal-content" id="detalles_registrar">
                                
                            </div>
                        </div>
                    </div> 
                <!-- /.registrar -->
                <!--borrar-->
                <div class="modal fade" id="confirm" tabindex="-1" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title custom_align" id="Heading">Atenci&oacute;n!!!</h4>
                            </div>
                            <div class="modal-body">

                                <div class="alert alert-success" id="cconfirmacion"></div>

                            </div>
                            <div class="modal-footer">
                                <a id="sic" role="button" class="btn btn-primary" ><span class="glyphicon glyphicon-ok-sign"></span> Si</a>
                                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
                            </div>
                        </div>
                    </div>
                </div>                 
                <!--borrar-->
                <div class="modal fade" id="delete" tabindex="-1" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title custom_align" id="Heading">Atenci&oacute;n!!!</h4>
                            </div>
                            <div class="modal-body">

                                <div class="alert alert-danger" id="confirmacion"></div>

                            </div>
                            <div class="modal-footer">
                                <a id="si" role="button" class="btn btn-primary" ><span class="glyphicon glyphicon-ok-sign"></span> Si</a>
                                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
                            </div>
                        </div>
                    </div>
                </div> 
                <!--fin-->
            </div> 
        </div>
    </div>
    <!--archivos js-->  
    <?php require '../../menu/js_lte.ctp'; ?>

    <script>
            function selclientes(){
                var vcliente = $("#vid_cliente").val();
                if(vcliente !== null){
                $.ajax({
                    type: "POST", url: "remision_clientes.php", data: {vcliente: vcliente}
                }).done(function (datos) {
                    $("#div_comprobantes").html(datos);
                });  
                }
            }        
        function registrar1() {
            $.ajax({
                type: "GET",
                url: "/farmmedi/factura/remision/remision_registrar.php",
                beforeSend: function () {
                    $("#detalles_registrar").html();
                },
                success: function (msg) {
                    $("#detalles_registrar").html(msg);
                }
            });
        };
        
    </script>
    <script>
        function confirmar(datos) {
            var dat = datos.split("_");
            $('#sic').attr('href', 'remision_control.php?vid_nrv=' + dat[0] +
                    '&accion=2');
            $('#cconfirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
        Desea confirmar la nota de remisión N° <i><strong>' + dat[1] + '</strong></i> ?');
        }        
        function anular(datos) {
            var dat = datos.split("_");
            $('#si').attr('href', 'remision_control.php?vid_nrv=' + dat[0] +
                    '&accion=3');
            $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
        Desea anular la nota de remisión N° <i><strong>' + dat[1] + '</strong></i> ?');
        }
        /*PARA TIEMPO DE MENSAJE*/
        $("#mensaje").delay(1000).slideUp(200, function () {
            $(this).alert('close');
        })
    </script>
</body>
</html>
