<?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">Detalles Nota de Debito
                                <a href="debito_index.php" 
                                   class="btn btn-primary btn-circle pull-right" 
                                   rel='tooltip' title="Atras">
                                    <i class="glyphicon glyphicon-arrow-left"></i> VOLVER
                                </a> 

                            </h3>
                        </div>     

                    </div>
                    <!-- /.cabecera -->
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    Datos Cabecera
                                </div>
                                <?php
                                $notadeb = consultas::get_datos("select * from v_compras_ndebito where cod_notc=" .$_REQUEST['vcod'] . "order by cod_notc asc");
                                ?>                         
                                <!-- /.panel-heading -->
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table width="100%"
                                               class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">#</th>
                                                    <th class="text-center">Nota Debito N°</th> 
                                                    <th class="text-center">Factura Compra N°</th> 
                                                    <th class="text-center">Proveedor</th>
                                                    <th class="text-center">Fecha</th>
                                                     <th class="text-center">IVA</th>
                                                    <th class="text-center">Total</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php foreach ($notadeb as $notac) { ?> 
                                                    <tr>
                                                        <td class="text-center"><?php echo $notac['cod_notc']; ?></td>
                                                        <td class="text-center"><?php echo $notac['notc_numero']; ?></td>
                                                        <td class="text-center"><?php echo $notac['com_nro_factura']; ?></td>
                                                        <td class="text-left"><?php echo $notac['prv_razonsoc']; ?></td>
                                                        <td class="text-center"><?php echo date("d/m/Y", strtotime($notac['notc_fecha_sistema'])); ?></td>
                                                        <td class="text-center"><?php echo number_format($notac['notc_totiva'], 0, ',', '.'); ?></td>
                                                        <td class="text-center"><?php echo number_format($notac['notc_monto'], 0, ',', '.'); ?></td>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>                         
                                    </div>
                                </div>
                            </div>


                            <!--consulta para el detalle-->
                            <?php
                            $detnotac = consultas::get_datos("select * from v_compras_ndebito_detalle"
                                            . " where cod_notc = " . $_REQUEST['vcod'] . " order by cod_notc asc");
                            ?>
                            <!-- /.cabecera -->

                            <!--GRILLA DETALLE-->
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="panel panel-primary">
                                        <div class="panel-heading">
                                            Detalles
                                        </div>
                                        <?php if (!empty($detnotac)) { ?>
                                            <div class="table-responsive">
                                                <table class="table table-striped">
                                                    <thead> 
                                                        <tr>
                                                            <th>Articulo</th>
                                                            <th>Precio</th>
                                                            <th>Cantidad</th>
                                                            <th>Subtotal</th>
                                                            <th>IVA 5</th>
                                                            <th>IVA 10</th>
                                                            <th>Accion</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php foreach ($detnotac as $detnotac1) { ?>
                                                            <tr>
                                                                <td><?php echo $detnotac1['art_descri']; ?></td>
                                                                <td><?php echo number_format($detnotac1['precio_unit'], 0, ',', '.'); ?></td>
                                                                <td><?php echo $detnotac1['cantidad']; ?></td>
                                                                <td><?php echo number_format($detnotac1['subtotal'], 0, ',', '.'); ?></td>
                                                                
                                                                <td><?php echo number_format($detnotac1['iva5'], 0, ',', '.'); ?></td>
                                                                <td><?php echo number_format($detnotac1['iva10'], 0, ',', '.'); ?></td>
                                                                <td>
                                                                    <?php if ($notac['notc_estado'] == 'ACTIVO') { ?>   
                                                                        <a onclick="editar(this)" data-datos2='<?= json_encode($detnotac1); ?>'
                                                                           class="btn btn-xs btn-success" rel='tooltip' data-title="Editar" 
                                                                           data-toggle="modal" data-target="#editar">
                                                                            <span class="glyphicon glyphicon-erase"></span>
                                                                        </a>
                                                                    <?php } else { ?>
                                                                    <?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> 
                            <!--GRILLA DETALLE-->
                        </div>
                    </div>
                    <!--editar-->
                    <div id="editar" class="modal fade" tabindex="-1" 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"><strong>Editar Compra</strong></h4>
                                </div>
                                <div class="panel-body">
                                    <form action="detcredito_control.php" method="post" accept-charset="utf-8" class="form-horizontal"> 
                                        <input name="accion" value="1" type="hidden"/>
                                        <input type="hidden" name="pagina" value="detdebito_agregar.php"> 
                                        <input type="hidden" name="vcod" id="vcredito" >
                                        <input type="hidden" name="vart" id="vart" >
                                        <input type="hidden" name="vdep" id="vdep" >
                                        <input type="hidden" name="vcant" id="vcant" >
                                        <input type="hidden" name="vprecio" id="vprecio" >

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Cantidad:</label> 
                                            <div class="col-md-2" >
                                                <input  type="number" required="" 
                                                        class="form-control" name="vcant"  id="vcant_edi"                                                    
                                                        style="width : 60px;"
                                                        min='1'
                                                        onkeypress="return numeros(event)">
                                            </div>
                                        </div>

                                        <div class="modal-footer">
                                            <button type="reset" data-dismiss="modal" class="btn btn-danger pull-left">
                                                <i class="fa fa-close "></i> Cerrar</button>
                                            <button type="submit" class="btn btn-primary pull-right">
                                                <i class="fa fa-refresh"></i> Actualizar</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--fin editar-->
                    <!--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> 
                    <!--borrar-->
                </div>
            </div>
        </div>
        <!--archivos js-->  
        <?php require '../../menu/js_lte.ctp'; ?>
        <script>
            function calsubtotal() {
                var dat = $('#vart').val().split("_");
                $('#subtotal').val(parseInt(dat[1]) * parseInt($('#cant').val()));
            }

            function calsubtotal1() {
                var dat = $('#vart').val().split("_");
                $('#subtotal').val(parseInt() * parseInt($('#cant').val()));
            }

            function stock() {
                var cant = parseInt($('#cantstock').val());
                if (cant > 0) {
                    if (parseInt($('#cant').val()) > cant) {
                        alert('SOLO HAY ' + cant + ' EN STOCK ESTE PRODUCTO');
                        $('#cant').val(cant);
                    }
                } else {
                    $('#cant').val('0');
                }
            }



            function editar(datos) {
                var dat = $(datos).data('datos2');
                $('#vcredito').val(dat.cod_notc);
                //console.log(dat.cod_notc);
                $('#vart').val(dat.id_articulo);
                //console.log(dat.id_articulo);
                $('#vdep').val(dat.cod_depo);
                //console.log(dat.cod_depo);
                $('#vcant_edi').val(dat.cantidad);
                //console.log(dat.cantidad);
                $('#vprecio').val(dat.precio_unit);
                //console.log(dat.subtotal);
                $('#vsubtotal').val(dat.subtotal);
                //console.log(dat.subtotal);
            }

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


            function numeros(e) {
                key = e.keyCode || e.which;
                tecla = String.fromCharCode(key).toLowerCase();
                letras = "0123456789_";
                especiales = [8, 37, 39, 46];

                tecla_especial = false
                for (var i in especiales) {
                    if (key == especiales[i]) {
                        tecla_especial = true;
                        break;
                    }
                }
                if (letras.indexOf(tecla) == -1 && !tecla_especial)
                    return false;
            }
        </script>

    </body>
</html>
