<?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">Pedidos de Compras 
                                <a data-toggle="modal" data-target="#registrar" 
                                   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
                                $pedidos = consultas::get_datos("select * from v_compras_pedidos order by codigo desc;");
                                if (!empty($pedidos)) {
                                    ?>                         
                                    <!-- /.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">Sucursal</th>
                                                        <th class="text-center">Fecha</th>
                                                        <th class="text-center">Estado</th>
                                                        <th class="text-center">Acciones</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="buscar">
                                                    <?php foreach ($pedidos as $pedido) { ?> 
                                                        <tr>
                                                            <td class="text-center"><?php echo $pedido['codigo']; ?></td>   
                                                            <td class="text-center"><?php echo $pedido['sucursal']; ?></td>
                                                            <td class="text-center"><?php echo $pedido['fecha']; ?></td>
                                                            <td class="text-center"><?php echo $pedido['estado']; ?></td>

                                                            <td class="text-center">
                                                                <a href="detpedidos_agregar.php?vcod=<?php echo $pedido['codigo']; ?>"
                                                                   class="btn btn-sm btn-primary" rel='tooltip' 
                                                                   data-title="Detalles"> <i class="fa fa-list"></i>
                                                                </a>                                                                    
                                                                <?php if ($pedido['estado'] === 'PENDIENTE') { ?> 
                                                                    <a onclick="anular(<?php echo "'" . $pedido['codigo'] . "'"; ?>)"
                                                                       data-toggle="modal" data-target="#delete"
                                                                       class="btn btn-sm btn-danger" rel='tooltip' 
                                                                       data-title="Anular"> <i class="fa fa-remove"></i>
                                                                    </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>Aún no se registraron pedidos de compras...</strong>
                                        </div>
                                    <?php } ?>  
                                    <!-- /.panel-body -->
                                </div>
                            </div>
                            <!-- /.panel -->
                        </div>
                        <!-- /.col-lg-12 -->
                    </div>
                    <div id="registrar" class="modal fade" role="dialog">
                        <div class="modal-dialog">
                            <!-- Modal content-->
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close"     
                                            data-dismiss="modal" arial-label="Close">x</button>
                                    <h4 class="modal-title"><i class="fa fa-plus"></i> <strong>Registrar Pedidos</strong></h4>
                                </div>
                                <form action="pedidos_control.php" method="post" accept-charset="utf-8" class="form-horizontal">
                                    <div class="modal-body">
                                        <input type="hidden" name="accion"  value="1">
                                        <input type="hidden" name="vped" value="0">
                                        <input type="hidden" name="vestado" value="PENDIENTE">
                                        <input type="hidden" name="vusu" value="<?php echo $_SESSION['usu_cod']; ?>">
                                        <input type="hidden" name="vsuc" value="<?php echo $_SESSION['cod_suc']; ?>">
                                        <input type="hidden" name="pagina" value="pedidos_index.php" id="cod">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">Fecha</label>
                                                <div class="col-sm-3">
                                                    <input type="date" class="form-control" name="vfecha" value="<?php echo date("Y-m-d") ?>" readonly="">
                                                </div>
                                                <label class="col-sm-2 control-label">Sucursal</label>
                                                <div class="col-sm-5">
                                                    <input type="text" class="form-control" name="vsucursal" value="<?php echo $_SESSION['suc_nombre']; ?>" readonly="">
                                                </div>                                                
                                            </div>                                          
                                    </div>

                                    <div class="modal-footer">
                                        <button type="reset" data-dismiss="modal" class="btn btn-default pull-left">
                                            <i class="fa fa-close"></i> Cerrar</button>
                                        <button type="submit" class="btn btn-primary pull-right">
                                            <i class="fa fa-floppy-o"></i> Registrar</button>
                                    </div>
                                </form>
                            </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 estado(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'pedidos_control.php?vped=' + dat[0] +
                        '&vsuc=null' +
                        '&vusu=null' +
                        '&accion=2' +
                        '&pagina=pedidos_index.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                Desea confirmar el pedido <i><strong>' + dat[0] + '</strong></i> ?');
            }
            function anular(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'pedidos_control.php?vped=' + dat[0] +
                        '&vsuc=null' +
                        '&vusu=null' +
                        '&accion=3' +
                        '&pagina=pedidos_index.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                Desea anular el pedido N° <strong>' + dat[0] + '</strong> ?');
            }
            /*PARA TIEMPO DE MENSAJE*/
            $("#mensaje").delay(1000).slideUp(200, function () {
                $(this).alert('close');
            })

        </script>


    </body>
</html>
