<?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">

                            <?php if (!empty($_SESSION['mensaje'])) { ?>
                                <?php
                                $mensaje = explode("_/_", $_SESSION['mensaje']);
                                if (($mensaje[0] == 'NOTICIA')) {
                                    $class = "success";
                                } else {
                                    $class = "danger";
                                }
                                ?>
                                <div class="alert alert-<?= $class; ?>" role="alert" id="mensaje">
                                    <i class="ion ion-information-circled"></i>
                                    <?php
                                    echo $mensaje[1];
                                    $_SESSION['mensaje'] = '';
                                    ?>
                                </div>
                            <?php } ?>

                            <h3 class="page-header">Listado de Notas de Credito 
                                <a data-toggle="modal" data-target="#registrar" onclick="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
                                if (isset($_SESSION['vcod'])) {
                                    if (($_SESSION['vcod'] > 0)) {
                                        $_REQUEST['vcod'] = $_SESSION['vcod'];
                                    }
                                }
                                $ncredito = consultas::get_datos("select * from v_compras_ncredito order by cod_notc asc ");
                                if (!empty($ncredito)) {
                                    ?>                         
                                    <!-- /.panel-heading -->
                                    <div class="panel-body">
                                        <div>
                                            <table id="example1" width="100%" 
                                                   class="table table-striped table-bordered table-hover">
                                                <thead>
                                                    <tr>
                                                        <th class="text-center">#</th>
                                                        <th class="text-center">Fecha</th>
                                                        <th class="text-center">Compra Nº </th>
                                                        <th class="text-center">Nro Documento</th>
                                                        <th class="text-center">Motivo</th>
                                                        <th class="text-center">Total</th>
                                                        <th class="text-center">Estado</th>
                                                        <th class="text-center">Acciones</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="buscar">
                                                    <?php foreach ($ncredito as $ncre) { ?> 
                                                        <tr>
                                                            <td class="text-center"><?php echo $ncre['cod_notc']; ?></td>
                                                            <td class="text-center"><?php echo date("d/m/Y", strtotime($ncre['notc_fecha_sistema'])); ?></td>
                                                            <td class="text-center"><?php echo $ncre['com_cod']; ?></td>
                                                            <td class="text-center"><?php echo $ncre['notc_numero']; ?></td>
                                                            <td class="text-center"><?php echo $ncre['mot_descri']; ?></td>
                                                            <td class="text-center"><?php echo number_format($ncre['notc_monto'], 0, ',', '.'); ?></td>
                                                            <td class="text-center"><?php echo $ncre['notc_estado']; ?></td>
                                                            <td class="text-center">
                                                                <form action="detcredito_agregar.php" method="POST">
                                                                    <?php if ($ncre['notc_estado'] == 'ACTIVO') { ?> 
                                                                    <a href="detcredito_agregar.php?vcod=<?php echo $ncre['cod_notc']; ?>" class="btn btn-sm btn-primary" rel='tooltip' data-title="Detalles">
                                                                        <i class="fa fa-list"></i>
                                                                    </a>                                                                   
                                                                        <a onclick="estado(<?php echo "'" . $ncre['cod_notc'] . "_" . $ncre['com_cod'] . "'"; ?>)"
                                                                           data-toggle="modal" data-target="#delete"
                                                                           class="btn btn-sm btn-warning" rel='tooltip' 
                                                                           data-title="Confirmar">
                                                                            <span class="glyphicon glyphicon-ok-sign"></span>
                                                                        </a>
                                                                    <?php } ?>
                                                                    <?php if ($ncre['notc_estado'] == 'CONFIRMADO') { ?>
                                                                        <a onclick="anular(<?php echo "'" . $ncre['cod_notc'] . "_" . $ncre['com_cod'] . "'"; ?>)"
                                                                           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 } ?>
                                                                </form>
                                                            </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" >
                            <!-- Modal content-->
                            <div class="modal-content" id="detalles_registrar">
                               
                            </div>
                        </div> 
                    </div> 
                    <!-- /.registrar -->
                    
                    <!--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> 
                    <!--fin-->
                </div> 
            </div>
        </div>
        <!--archivos js-->  
        <?php require '../../menu/js_lte.ctp'; ?>


        <script>
            function estado(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'credito_control.php?vcod=' + dat[0] +
                        '&vcompra=' + dat[1] +
                        '&vusu=null' +
                        '&vmotivo=null' +
                        '&vprv=null' +
                        '&vsuc=null' +
                        '&vfecha=1900-01-01' +
                        '&vtotal=null' +
                        '&vtotiva=null' +
                        '&vnumero=null' +
                        '&vtimbrado=null' +
                        '&venc_tim=1900-01-01' +
                        '&accion=2' +
                        '&pagina=credito_index.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
            Desea confirmar la operacion<i><strong>' + dat[0] + '</strong></i> ?');
            }
            function anular(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'credito_control.php?vcod=' + dat[0] +
                         '&vcompra=' + dat[1] +
                        '&vusu=null' +
                        '&vmotivo=null' +
                        '&vprv=null' +
                        '&vsuc=null' +
                        '&vfecha=1900-01-01' +
                        '&vtotal=null' +
                        '&vtotiva=null' +
                        '&vnumero=null' +
                        '&vtimbrado=null' +
                        '&venc_tim=1900-01-01' +
                        '&accion=3' +
                        '&pagina=credito_index.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
            Desea anular el registro <i><strong>' + dat[0] + '</strong></i> ?');
            }
            /*PARA TIEMPO DE MENSAJE*/
            $("#mensaje").delay(1000).slideUp(200, function () {
                $(this).alert('close');
            })
        </script>

        <script type="text/javascript">
            function div_pres() {
                var prv_cod = $("#prv_cod").val();
                $.ajax({
                    type: "POST", url: "div_pres.php", data: {prv_cod: prv_cod}
                }).done(function (datos) {
                    $("#div_presu").html(datos);
                });
            };

            function div_pres_detalle() {
                var com_cod = $("#com_cod").val();
                $.ajax({
                    type: "POST", url: "div_pres_detalle.php", data: {com_cod: com_cod}
                }).done(function (datos) {
                    $("#div_pres_detalle").html(datos);
                });
            };
            
            function registrar() {
            $.ajax({
                type: "GET",
                url: "/farmmedi/compras/credito/credito_registrar.php",
                beforeSend: function () {
                    $("#detalles_registrar").html();
                },
                success: function (msg) {
                    $("#detalles_registrar").html(msg);
                }
            });
        };
        </script>
    </body>
</html>
