<?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 Promocion
                                <a href="promo_index.php" 
                                   class="btn btn-primary btn-circle pull-right" 
                                   rel='tooltip' title="Atras">
                                    <i class="glyphicon glyphicon-arrow-left"></i> VOLVER
                                </a> 
                                <?php $spromocion1 = consultas::get_datos("select * from v_servicios_promo where id_promo=" . $_REQUEST['vcod'] . "order by id_promo asc"); ?>
                                    <?php if ($spromocion1[0]['estado'] == 'PENDIENTE') { ?> 
                                        <?php $detallepr = consultas::get_datos("select * from v_servicios_promo_detalle where id_promo=" . $_REQUEST['vcod'] . "order by id_promo asc"); ?>
                                        <?php if (!empty($detallepr)) { ?>
                                            <a  onclick="confirmar(<?php echo "'" . $spromocion1[0]['id_promo']."_".$spromocion1[0]['tipo_promo'] . "'"; ?>)"
                                                data-toggle="modal" data-target="#confirmar"
                                                class="btn btn-circle btn-success pull-right" rel='tooltip' 
                                                data-title="Confirmar">
                                                <span class="glyphicon glyphicon-ok-sign"></span> CONFIRMAR
                                            </a>
                                        <?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 $spromocion = consultas::get_datos("select * from v_servicios_promo where id_promo=" . $_REQUEST['vcod'] . "order by id_promo asc");?>                         
                                <!-- /.panel-heading -->
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table width="100%"
                                               class="table">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">Nro</th>
                                                    <th class="text-center">Tipo de Promo</th>                                        
                                                    <th class="text-center">Fecha de inicio</th>
                                                    <th class="text-center">Fecha de fin</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php foreach ($spromocion as $spromo) { ?> 
                                                    <tr>
                                                        <td class="text-center"><?php echo $spromo['id_promo']; ?></td>
                                                        <td class="text-center"><?php echo $spromo['tipo_promo']; ?></td>
                                                        <td class="text-left"><?php echo date("d/m/Y", strtotime($spromo['fec_inicio'])); ?></td>
                                                        <td class="text-left"><?php echo date("d/m/Y", strtotime($spromo['fec_fin'])); ?></td>

                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>                         
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> 
                    <!--impresion cabecera-->
                    <?php if($spromo['estado'] ==="PENDIENTE"){ ?>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="box box-default">                                                           
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
                                            <!-- FORMULARIO DE PRODUCTOS -->
                                            <form class="" action="detpromo_control.php" method="post" id="frm_add_det">
                                                <input type="hidden" name="accion" value="1">
                                                <input type="hidden" name="vcod" value="<?php echo $_REQUEST['vcod']; ?>" >  
                                                <input type="hidden" name="pagina" value="detpromo_agregar.php" >
                                                <div class="row">                                                            
                                                    <div class="col-md-6 col-sm-6 col-lg-6">
                                                        <div class="form-group">
                                                            <label class="control-label">Producto: </label>
                                                            <?php $articulos = consultas::get_datos("select * from v_articulos"); ?>
                                                            <select name="vart" class="form-control select2" id="vart" required="" onchange="obtenerprecio()">
                                                                   <option value="">Seleccione Articulo</option>
                                                                   <?php
                                                                   if (!empty($articulos)) {
                                                                       foreach ($articulos as $articulo) { ?>
                                                                           <option value="<?php echo $articulo['id_articulo']."_".$articulo['pre_venta']; ?>">
                                                                               <?php echo $articulo['art_descri']." ".($articulo['mar_cod']!=="0" ? $articulo['mar_descrip']:""); ?>
                                                                           </option>
                                                                           <?php
                                                                       }
                                                                   } else { ?>
                                                                       <option value="0">Debe insertar un Articulo</option>
                                                                   <?php } ?>
                                                               </select>
                                                        </div>                                                    
                                                    </div>                                                 
                                                    <div class="col-md-2 col-sm-2 col-lg-2 col-xs-5">
                                                        <div class="form-group">
                                                            <label>Precio:</label>
                                                            <input type="number" id="precio" class="form-control" readonly=""/>
                                                        </div>                                                        
                                                    </div>                                                                                                                
                                                    <div class="col-md-2 col-sm-2 col-lg-2 col-xs-5">
                                                        <div class="form-group">
                                                            <label>Descuento:</label>
                                                            <input type="number" id="descuento" class="form-control" name="vdescuento" min="1" value="1" required=""/>
                                                        </div>                                                        
                                                    </div>                                                            
                                                    <div class="col-md-1 col-sm-1 col-lg-1">
                                                        <div class="form-group">
                                                            <label class="control-label hidden-xs">&nbsp;</label>
                                                            <button type="submit" class="btn btn-primary btn-sm pull-right"><i class="fa fa-plus"></i> AGREGAR</button>
                                                        </div>
                                                    </div>                                                    
                                                </div>                                                                                                                                                                          
                                           </form>
                                                <!-- FIN FORMULARIO DE PRODUCTOS -->                                             
                                        </div>                                        
                                    </div>                                    
                                </div>
                            </div>                                                
                        </div>
                    </div>   
                    <?php } ?>
                    <!--Inicio de listado-->
                    <?php
                    $detpromocion = consultas::get_datos("select * from v_servicios_promo_detalle where id_promo = " . $_REQUEST['vcod'] . " order by id_promo asc");
                    ?>
                    <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                Detalle de Promo
                            </div>
                            <?php if (!empty($detpromocion)) { ?>
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <table class="table table-striped tablas">
                                        <thead>
                                            <tr>
                                                <th class="text-center">Descripción</th>
                                                <th class="text-center">Precio Lista</th>
                                                <th class="text-center">Descuento</th>
                                                <th class="text-center">Accion</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($detpromocion as $detpromo) { ?>
                                                <tr>
                                                    <td class="text-left"><?php echo $detpromo['art_descri']; ?></td>
                                                    <td class="text-center"><?php echo $detpromo['pre_venta']; ?></td>
                                                    <td class="text-center"><?php echo $detpromo['descuento']; ?></td>
                                                    <td class="text-center">
                                                        <?php if ($spromo['estado'] == 'PENDIENTE') { ?>   
                                                            <a onclick="borrar(<?php echo"'" .$detpromo['id_promo']."_".$detpromo['id_articulo']."_".$detpromo['art_descri']."'"; ?>)"
                                                               class="btn btn-sm 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>
                                 </div>
                                </div>
                                <?php } else { ?>
                                        <div class="panel-body">
                                                <div class='alert alert-info'>
                                                    <span class='glyphicon glyphicon-info-sign'>
                                                    </span> A&uacute;n no se han registrado detalles...
                                                </div>                                            
                                        </div>
                                <?php } ?>
                        </div>  
                    </div>
                    </div>
                    <!--fin de listado-->
                </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> 
                <!--borrar-->
                <div class="modal fade" id="confirmar" 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="confirmacions"></div>

                            </div>
                            <div class="modal-footer">
                                <a id="sis" 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 obtenerprecio() {
                var dat = $('#vart').val().split("_");
                if (parseInt($('#vart').val()) > 0) {
                    $("#precio").val(dat[1]);
                    $("#descuento").attr({"max" : dat[1]});
                }
            };            
            function borrar(datos) {
                var dat = datos.split("_");
                $('#si').attr('href',
                        'detpromo_control.php?vcod=' + dat[0] +
                        '&vart=' + dat[1] +
                        '&vdescuento=null' +
                        '&accion=2'+
                        '&pagina=detpromo_agregar.php');
                $('#confirmacion').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                Desea quitar el Articulo <i><strong>' + dat[2] + '</strong></i> del detalle?');
            }

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

             function confirmar(datos) {
                var dat = datos.split("_");
                $('#sis').attr('href', 'promo_control.php?vcod=' + dat[0] +
                        '&vtpromo=null' +
                        '&vusu=null' +
                        '&vsuc=null' +
                        '&vfechainicio=1900-01-01' +
                        '&vfechafin=1900-01-01' +
                        '&vdescripcion=null' +
                        '&accion=2' +
                        '&pagina=promo_index.php');
                $('#confirmacions').html('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                Desea confirmar la promoción <i><strong>' + dat[1] + '</strong></i> ?');
            }

        </script>
        <!--javascript-->  
    </body>
</html>
