<?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 class="wrapper">
            <?php require '../../menu/cabecera.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <?php require '../../menu/izquierda.ctp'; ?><!--BARRA DE HERRAMIENTAS-->

            <div class="content-wrapper">
                <div class="content">   
                    <!--impresion del titulo de la pagina-->
                    <div class="row">
                        <div class="col-lg-12">
                       <h3 class="page-header">Detalles de Transferencia
                                <a href="remision_index.php" 
                                   class="btn btn-primary btn-circle pull-right" 
                                   rel='tooltip' title="VOLVER">
                                    <i class="glyphicon glyphicon-arrow-left"></i> VOLVER
                                </a> 
                                <?php $nremision1 = consultas::get_datos("select * from v_nota_remision where id_nr=" . $_REQUEST['vcod'] . "order by id_nr asc"); ?>
                                <?php foreach ($nremision1 as $nr1) { ?>
                                    <?php if ($nr1['nr_estado'] == 'ACTIVO') { ?> 
                                        <?php $detallenr = consultas::get_datos("select * from v_nota_remision_detalle where id_nr=" . $_REQUEST['vcod'] . "order by id_nr asc"); ?>
                                        <?php if (!empty($detallenr)) { ?>
                                            <?php if ($nr1['sucursal_entrada'] != $_SESSION['cod_suc']) { ?>
                                                <a  onclick="estado(<?php echo "'" . $detallenr[0]['id_nr'] . "'"; ?>)"
                                                    data-toggle="modal" data-target="#delete"
                                                    class="btn btn-circle btn-openid pull-right" rel='tooltip' 
                                                    data-title="Confirmar">
                                                    <span class="glyphicon glyphicon-ok-sign"></span>
                                                </a>
                                            <?php } ?>
                                        <?php } ?>
                                    <?php } ?>
                                <?php } ?>
                            </h3>   
                        </div>     
                    </div>
                    <!--impresion del titulo de la pagina-->
                    <!--impresion cabecera-->
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    Datos Cabecera
                                </div>
                                <?php
                                $nremision = consultas::get_datos("select * from v_nota_remision where id_nr=" . $_REQUEST['vcod'] . "order by id_nr asc");
                                ?>                         
                                <!-- /.panel-heading -->
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table width="100%"
                                               class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">Nro</th>
                                                    <th class="text-center">Destino</th>                                        
                                                    <th class="text-center">Fecha de inicio</th>
                                                    <th class="text-center">Estado</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php foreach ($nremision as $nr) { ?> 
                                                    <tr>
                                                        <td class="text-center"><?php echo $nr['id_nr']; ?></td>
                                                        <td class="text-center"><?php echo $nr['suc_entrada']; ?></td>
                                                        <td class="text-center"><?php echo $nr['fecha_inicio_translado']; ?></td>
                                                        <td class="text-center"><?php echo $nr['nr_estado']; ?></td>

                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>                         
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> 
                    <!--impresion cabecera-->
                    <!--Inicio de listado-->
                    <?php
                    $detnremision = consultas::get_datos("select * from v_nota_remision_detalle where id_nr = " . $_REQUEST['vcod'] . " order by id_nr asc");
                    ?>
                    <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                Detalle de Pedidos
                            </div>
                            <?php if (!empty($detnremision)) { ?>
                                <div class="table-responsive">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th class="text-center">Modelo/Articulo/Marca</th>
                                                <th class="text-center">Deposito Inicial</th>
                                                <th class="text-center">Deposito Destino</th>
                                                <th class="text-center">Cantidad</th>
                                                <th class="text-center">Accion</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($detnremision as $detnr) { ?>
                                                <tr>
                                                    <td class="text-center"><?php echo $detnr['articulo']; ?></td>
                                                    <td class="text-center"><?php echo $detnr['deposito_inicial']; ?></td>
                                                    <td class="text-center"><?php echo $detnr['cod_depo_destino']; ?></td>
                                                    <td class="text-center"><?php echo $detnr['cantidad']; ?></td>
                                                    <td class="text-center">
                                                        <?php if ($nr['nr_estado'] == 'ACTIVO') { ?>   
                                                            <a onclick="borrar(<?php
                                                            echo"'" . $detnr['id_articulo'] . "_" .
                                                            $_REQUEST['vcod'] . "_" .
                                                            $detnr['cod_depo'] . "_" .
                                                            $detnr['cantidad'] . "_" .
                                                            $detnr['articulo'] . "'";
                                                            ?>)"
                                                               class="btn btn-xs btn-danger"
                                                               rel="tooltip" data-title="Borrar"
                                                               data-toggle="modal" data-target="#delete">
                                                                <span class="glyphicon glyphicon-trash"></span>
                                                            </a>
                                                        <?php } ?>
                                                    </td>
                                                </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                <?php } else { ?>
                                    <div class="col-md-12">
                                        <div class="alert alert-info
                                             alert-dismissable">
                                            <button type="button" class="close"
                                                    data-dismiss="alert" aria-hidden="true">&times;
                                            </button>
                                            <strong>No se encontraron detalles...!</strong>
                                        </div>
                                    </div> 
                                <?php } ?>
                            </div>
                        </div>  
                    </div>
                    </div>
                    <!--fin de listado-->

                    <!--carga par el detalle-->
                    <?php if ($nr['nr_estado'] == 'ACTIVO') { ?>  
                        <?php if ($nr1['sucursal_entrada'] != $_SESSION['cod_suc']) { ?>
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="panel-body">
                                        <form action="detremision_control.php" method="get" role="form" class="form-horizontal">
                                            <input type="hidden" name="accion" value="1">
                                            <input type="hidden" name="vcod" value="<?php echo $_REQUEST['vcod']; ?>" >  
                                            <input type="hidden" name="pagina" value="detremision_agregar.php" >

                                            <div class="row">
                                                <div class="col-md-5" style="left: 300px">
                                                    <label class="control-label">Deposito Inicial</label>
                                                    <?php $depositos = consultas::get_datos(" select * from deposito where cod_depo<>0 and cod_suc=" . $_SESSION['cod_suc']); ?>
                                                    <select name="vdep" class="form-control" id="depo" onchange="articulo()" onkeyup="articulos()" style="width : 170px;">>
                                                        <option value="">Seleccione Deposito</option>
                                                        <?php
                                                        if (!empty($depositos)) {
                                                            foreach ($depositos as $deposito) {
                                                                ?>
                                                                <option value="<?php echo $deposito['cod_depo']; ?>">
                                                                    <?php echo $deposito['dep_descrip']; ?>
                                                                </option>
                                                                <?php
                                                            }
                                                        } else {
                                                            ?>
                                                            <option value="0">Debe insertar un deposito</option>
                                                        <?php } ?>
                                                    </select>
                                                </div>

                                                <div class="col-md-4" style="left: 60px" id="detalles" required="">
                                                    <label class="control-label">Articulos</label> 
                                                    <select class="form-control" required="" style="width : 160px;">
                                                        <option>Seleccione Articulo</option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-md-1" style="left: 500px">
                                                    <label class="control-label">Cantidad</label> 
                                                    <input type="number" required="" placeholder="Especifique cantidad"
                                                           class="form-control" require min="1" name="vcant"
                                                           id="cant" value="0"  style="width : 60px;"
                                                           onchange="stock()">
                                                </div>

                                            </div>

                                            <br>
                                            <div class="form-group">
                                                <div class="col-md-offset-4 col-md-10" style="left: 60px">
                                                    <button class="btn btn-success"
                                                            type="submit"><i class="fa fa-floppy-o">
                                                        </i>Grabar
                                                    </button>
                                                </div>
                                            </div>

                                        </form>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    <?php } ?>
                    <!--carga par el detalle-->

                </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-warning" 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> 
            </div>
        </div>

        <!--archivos js-->  
        <?php require '../../menu/js_lte.ctp'; ?>
        <!--archivos js-->  
        <!--javascript-->  
        <script>
            function articulo() {
                if (parseInt($('#depo').val()) > 0) {
                    $.ajax({
                        type: "GET",
                        url: "/farmmedi/compras/remision/lista_articulo_nr.php?vdep=" + $('#depo').val(), cache: false,
                        beforeSend: function () {
                            $('#detalles').html('<img src="/farmmedi/img/ajax-loader.gif">\n\ <strong><i>Cargando...</i></strong>');
                        },
                        success: function (msg) {
                            $('#detalles').html(msg);
                            //obtenerprecio();
                        }
                    });
                }
            }
            function borrar(datos) {
                var dat = datos.split("_");
                $('#si').attr('href',
                        'detremision_control.php?vcod=' + dat[1] +
                        '&vart=' + dat[0] +
                        '&vdep=' + dat[2] +
                        '&vcant=' + dat[3]
                        + '&accion=3'
                        + '&pagina=detremision_agregar.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                Desea Borrar el Articulo <i><strong>' + dat[4] + '</strong></i> del detalle?');
            }

            /*PARA TIEMPO DE MENSAJE*/
            $("#mensaje").delay(1000).slideUp(200, function () {
                $(this).alert('close');
            }
            );

            function estado(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'remision_control.php?vcod=' + dat[0] +
                        '&vusu=null' +
                        '&vempleado=null' +
                        '&vtimbrado=null' +
                        '&vfechainicio=1900-01-01' +
                        '&vmotivo=null' +
                        '&vestado=null' +
                        '&vvehiculo=null' +
                        '&vsucsalida=null' +
                        '&vsucentrada=null' +
                        '&accion=2' +
                        '&pagina=remision_index.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
        Desea confirmar la operacion <i><strong>' + dat[0] + '</strong></i> ?');
            };

            function stock() {
               var cant = $('#vart').val().split("_");
               
                if (parseInt(cant[1]) > 0) {
                    
                    if (parseInt($('#cant').val()) > parseInt(cant[1])) {
                        alert('SOLO HAY ' + cant[1] + ' UNIDADES EN STOCK ESTE PRODUCTO');
                        $('#cant').val(parseInt(cant[1]));                  
                    }
                } else {
                    $('#cant').val('0');
                }
            }
        </script>
        <!--javascript-->  
    </body>
</html>
