<?php
session_start();
require_once('conexion.php');
if (isset($_SESSION['usu_nombre']))
{
    require_once('include/sesiones.php');
    $regis=mysqli_query($con,"SELECT * from permiso where modulo_mod_id='6' and usuario_usu_id='$usu_id'") or die(mysqli_error($con));
    $reg=mysqli_fetch_array($regis);
        if($reg['per_visualizar']=="Activo")
        {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
    include ('head.php');
?>
</head>
<body>
<?php
$inicio="";
$M_inventario="active";
$M_contactos="";
$M_compras="";
$M_ventas="";
$M_pedidos="";
$M_pos="";
$R_reportes="";

$m_familias="";
$m_articulos="";
$m_combos="";
$m_servicios="";
$m_productos="active";
$m_tarifas="";
$m_bodegas="";
$m_traslados="";
$m_ajustes="";
$m_etiquetas="";
$m_ubicacion="";
$m_marca="";
include ('menu.php');
?> 
<div class="main">
    <div class="col-md-2">
        <?php include ('include/menu_inventario.php');?>           
    </div> <!-- /span6 -->      
    <div class="col-md-10"> 
        <div class="widget stacked">
            <div class="widget-header">
                <i class="icon fas fa-hamburger"></i>
                <h3>PRODUCCION</h3>
            </div> 
          
            <form name="form_producto" id="form_producto" action="" method="post" enctype="multipart/form-data">
                <div class="widget-content">
                <div  class="col-md-12 ">
                    <div id="resultados"></div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Codigo</label>
                            <div class="input-group">
                                <input type="text" name="art_referencia" id="art_referencia" class="form-control input-sm"  autocomplete="off" value="" required>
                                <span class="input-group-addon"><div id="Info_referencia"></div> </span>
                            </div>
                        </div> <!-- /.form-group -->

                        <div class="form-group">
                            <label>Codigo de barras</label>
                            <div class="input-group">
                                <input type="text"  name="art_barras" id="art_barras" class="form-control input-sm" autocomplete="off" value="" >
                                <span class="input-group-addon"><div id="Info_barras"></div> </span>
                            </div> <!-- /.form-group -->
                        </div> <!-- /.form-group -->
                        <label>Categorias</label>
                        <section id="intro" >
                            <select name="art_familia" id="art_familia" class="form-control input-sm" required >
                            <?php
                                $datos = mysqli_query($con,"SELECT * FROM familias  WHERE  empresa='$empresa' ") ;
                                while( $fila = mysqli_fetch_array( $datos ) )
                                {
                                    echo' <option value="'.$fila['fam_id'].'">'.$fila['fam_nombre'].'</option>';
                                }
                                ?>
                            </select>
                        </section>
                        <div class="form-group">
                            <label>Nombre</label>
                            <textarea rows="4" name="art_nombre" class="form-control input-sm" required></textarea>
                        </div> <!-- /.form-group -->
                    </div>

                    <div class="col-md-4">
                        <label>Ubicación</label>
                        <section id="intro" >
                            <select name="art_ubicacion" id="art_ubicacion" class="form-control input-sm" required >
                            <?php
                                $datos = mysqli_query($con,"SELECT * FROM ubicacion  WHERE  empresa='$empresa' and sucursal='$sucursal' ") ;
                                while( $fila = mysqli_fetch_array( $datos ) )
                                {
                                    echo' <option value="'.$fila['ubi_id'].'">'.$fila['ubi_nombre'].'</option>';
                                }
                                ?>
                            </select>
                        </section>
                        <div class="form-group">
                            <label>Precio Costo</label>
                            <input type="number" name="art_costo" class="form-control input-sm" required>
                        </div> <!-- /.form-group -->

                        <?php if($emp_regimen=='Responsable de Iva') { ?>
                        <label>Impuesto</label>
                        <select name="art_iva" id="art_iva" class="form-control input-sm" required>
                            <?php
                                $datos=mysqli_query($con,"SELECT * FROM iva where empresa='$empresa' ") ;
                                while( $fila = mysqli_fetch_array( $datos ))
                                {
                                    echo '<option value="'.$fila['iva_id'].'" select>'.$fila['iva_nombre'].'</option>';
                                }
                            ?>
                        </select> 
                            <?php } else { 
                                $datos=mysqli_query($con,"SELECT * FROM iva where iva_porcentaje='0' and empresa='$empresa'");
                                $fila=mysqli_fetch_array($datos);
                                $iva_id=$fila['iva_id'];
                            ?>
                            <input type="hidden" name="art_iva" id="art_iva" class="form-control input-sm" autocomplete="off" value="<?php echo $iva_id;?>">
                            <?php } ?>

                        <div class="form-group">
                            <label>Precio Venta</label>
                            <input type="number" name="art_pvp" class="form-control input-sm" required>
                        </div> <!-- /.form-group -->
                        <label>&nbsp;</label>
                        <label for="imagen" style="width: 100%;"><i class="btn-icon-only icon-upload"></i>Subir Imagen </label>
                        <input type="file" name="imagen" id="imagen" >
                    </div>

                    <div class="col-md-4">
                        <label>&nbsp;</label>
                        <ul class="gallery-container" >
                            <li>
                                <a href="img/articulos/sin_imagen.jpg" class="ui-lightbox">
                                    <img src="img/articulos/sin_imagen.jpg" alt="" height="250px" />
                                </a>
                            </li>
                        </ul>
                    </div>
                   
                    <div class="col-md-8">
                        <div class="form-group">
                            <a href="#" type="button" id="add_field" class="btn btn-primary"><i class="btn-icon-only icon-plus"></i>Añadir Adicionales</a>
                        </div>
                        </br>
                        <div id="listas"></div>
                    </div>
                    
                    <div class="col-xs-12 pull-right">
                        <div class="modal-footer">
                            <a href="I_produccion.php" class="btn btn-default">Cancelar</a>
                            <button id="registrar_producto" type="submit" class="btn btn-success">Registrar </button> 
                        </div>
                        <?php include ('include/pie_de_pagina.php'); ?>
                    </div>
            	</div> <!-- /.widget-content -->
            </form>
        </div> <!-- /.widget -->
    </div> <!-- /.col-md-9 -->
</div> <!-- /main -->

<script src="php_produccion\ajax.js"></script>
      
<script>
$(document).ready(function() 
{  
    $('#art_referencia').blur(function(){
    $('#Info_referencia').html('<img src="img/ajax-loader.gif" alt="" height="16px"  />').fadeOut(1000);
    var art_referencia = $(this).val();    
    var dataString = 'art_referencia='+art_referencia;
    $.ajax({
            type: "POST",
            url: "php_articulo/verificar_articulo_referencia.php",
            data: dataString,
            success: function(data) {
            $('#Info_referencia').fadeIn(1000).html(data);
            }
        });
    });              
});   

$(document).ready(function() 
{  
    $('#art_barras').blur(function(){
    $('#Info_barras').html('<img src="img/ajax-loader.gif" alt="" height="16px"  />').fadeOut(1000);
    var art_barras = $(this).val();    
    var dataString = 'art_barras='+art_barras;
    $.ajax({
            type: "POST",
            url: "php_articulo/verificar_articulo_barras.php",
            data: dataString,
            success: function(data) {
        $('#Info_barras').fadeIn(1000).html(data);
            }
        });
    });              
});   


var campos_max = 1000;   //max de 10 campos
var x = 0;
$('#add_field').click (function(e) {
    e.preventDefault();     //prevenir novos clicks
    if (x < campos_max)
    {
        $('#listas').append('<div>\
            <div class="col-sm-5" style="padding-left: 0px;">\
                <input class="form-control input-sm" placeholder="Nombre" type="text" name="opcion1[]">\
            </div>\
            <div class="col-sm-3">\
                <input class="form-control input-sm" type="text" placeholder="Precio costo" name="opcion2[]">\
            </div>\
            <div class="col-sm-3">\
                <input class="form-control input-sm" type="text" placeholder="Precio venta" name="opcion3[]">\
            </div>\
            <a href="#" class="remover_campo btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>\
            </br></br></div>');
            x++;
    }
});
// Remover o div anterior
$('#listas').on("click",".remover_campo",function(e) {
      e.preventDefault();
      $(this).parent('div').remove();
      x--;
});

</script>
<?php
    include ('php_caja/caja_abrir.php');
    include ('script.php');
?>
</body>
</html>
<?php
}
else
{
   echo '<script>alert("No tienes permiso para ver esta pagina")</script>';
   echo '<script> setTimeout("history.back(1)", 0); </script>';
}
}
else
{
    echo '<script>location.href = "index.php";</script>';
}
?>