<?php
session_start();
require_once('conexion.php');
require_once('include/sesiones.php');
if (isset($_SESSION['usu_nombre']))
{
    $regis=mysqli_query($con,"SELECT * from permiso where modulo_mod_id='17' 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="";
$M_contactos="";
$M_compras="active";
$M_ventas="";
$M_pedidos="";
$M_pos="";
$R_reportes="";

$compras="";
$proveedores="";
$garantias="active";
$egresos="";

include ('menu.php');
?>  
<div class="main">
    <div class="col-md-2">
       <?php include ('include/menu_compras.php');?>
    </div> <!-- /span6 -->
    <div class="col-md-10">  
        <div id="resultados" class="col-md-12"></div>
        <div class="widget stacked">
            <div class="widget-header"></div> 
            <div class="widget-content">
                <?php
                    $can=mysqli_query($con,"SELECT MAX(gar_numero)as numero FROM garantias_proveedor where empresa='$empresa'") or die(mysqli_error($con)); 
                    $dato=mysqli_fetch_array($can); 
                    $numero=$dato['numero']+1;
                    $fecha=date('Y-m-d');
                ?>    
                <form name="form_registrar" id="form_registrar" action="" method="post" enctype="multipart/form-data">
                    <div class="col-md-4">
                        <label>Proveedor</label>
                        <section id="intro" >
                            <select name="art_proveedor" id="art_proveedor" class="form-control name_list input-sm" required>
                                <?php
                                    $result_1 = mysqli_query($con,"SELECT * FROM proveedor WHERE  empresa='$empresa' order by pro_nombre asc");  
                                    while ($row_1=mysqli_fetch_array($result_1)) 
                                    {   
                                      echo "<option value='".$row_1['pro_id']."'>".$row_1['pro_nombre']."</option>"; 
                                    }  
                                ?>
                            </select>
                        </section> 
                        <input type="hidden" name="fecha" value="<?php echo $fecha;?>" class="form-control" required>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Garantia Nº</label>
                            <input type="text" name="gar_numero" value="<?php echo $numero;?>" class="form-control" readonly >
                        </div> <!-- /.form-group -->      
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Fecha</label>
                            <input type="date" name="gar_fecha" value="<?php echo  date('Y-m-d');?>" class="form-control" readonly>
                        </div> <!-- /.form-group -->      
                    </div>
                    <div class="col-md-8"></div>
                    <div class="col-md-4">
                        </br>
                        <div class="btn-group btn-group-justified" align="right">
                            <a href="#myModal" class="btn btn-warning" data-toggle="modal" >
                            <i class="btn-icon-only icon-plus"></i>Agregar Articulos</a>
                        </div></br>
                    </div>

                    <div class="table-responsive">
                        <div id="resultado"></div>
                        <div id="tabla"></div>
                    </div> <!-- /.table-responsive -->
                    <div class="modal-footer">
                         <button href="#completar_compra" class="btn btn-success pull-right" data-toggle="modal" type="button"><i class=" icon-ok"></i> <strong>Registrar </strong></button> 
                    </div>
                    <?php include ('include/pie_de_pagina.php'); ?>
                    <?php include ('php_garantias_proveedor/form_comfirmar.php'); ?>
                </form>
            </div>
        </div> 
    </div> <!-- /.col-md-9 -->
</div> <!-- /container -->
<?php include ('php_buscador/buscador_ajuste.php');?>
<script>
$(document).ready(function(){
  load(1);
});

function load(page)
{
    var q= $("#q").val();
    $("#loader").fadeIn('slow');
    $.ajax({
        url:'./php_buscador/articulos_garantias.php?action=ajax&page='+page+'&q='+q,
         beforeSend: function(objeto){
         $('#loader').html('<img src="./img/ajax-loader.gif"> Cargando...');
        },
        success:function(data){
          $(".outer_div").html(data).fadeIn('slow');
          $('#loader').html('');
        }
    })
}

function loadTabla(){
    $.get("./php_garantias_proveedor/tabla.php","",function(data){
    $("#tabla").html(data);
    })
}
loadTabla();

function agregar (art_id_bod)
{
    var art_id=document.getElementById('art_id_'+art_id_bod).value;
    $.ajax({
        type: "POST",
        url: "./php_garantias_proveedor/form_info.php",
        data: "art_id_bod="+art_id_bod+"&art_id="+art_id,

    beforeSend: function(objeto){
      $("#resultado").html("Mensaje: Cargando...");
      },
    success: function(datos){
    $("#resultado").html(datos);
    }
    });
}

$( "#form_registrar" ).submit(function( event ) {
$('#registrar').attr("disabled", true);
 var formData = new FormData($("#form_registrar")[0]);
  var ruta = "php_garantias_proveedor/registrar_garantia.php";
   $.ajax({
      type: "POST",
      url: ruta,
      data: formData,
      contentType: false,
      processData: false, 
        beforeSend: function(objeto){
         $('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
      success: function(datos){
      $("#resultados").html(datos);
      $('#registrar').attr("disabled", false);
     
      loadTabla();
      }
  });
  event.preventDefault();
})
</script>

<?php
    include ('php_caja/caja_abrir.php');
    include ('script.php');
?>

<?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>';
}
?>