<?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='21' 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="";
  $M_ventas="active";
  $M_pedidos="";
  $M_pos="";
  $R_reportes="";

  $cotizacion="";
  $ventas="";
  $periodica="active";
  $clientes="";
  $cartera="";
  $garantias="";
  $cotizacion="";
  $abonos="";
  $cotizacion_online="";


  include ('menu.php');
?> 
<div class="main">
   <div class="col-md-2"> 
        <?php include ('include/menu_ventas.php');?>
    </div> <!-- /span6 -->
    <div class="col-md-10">  
        <div class="widget stacked">
            <div class="widget-content">
                <div class="widget stacked">
                    <div class="widget-content">
                        <section id="buttons">
                            <div class="col-md-9">
                                <a class="btn btn-info" href="V_registrar_contrato.php"><i class="icon-plus"></i> Nuevo</a>
                                <a class="btn btn-warning" href="#facturar" data-toggle="modal" ><i class="icon-plus"></i> Facturar</a>
                            </div>
                            <div class="col-md-3">
                                <input id="q" type="text" class="form-control"  placeholder="Buscador" onkeyup='load(1);' autofocus>
                            </div>
                        </section>
                    </div> <!-- /widget-content -->
                </div> <!-- /widget --> 
                <center> <span id="loader"></span></center>
                <div id="resultados"></div><!-- Carga los datos ajax -->
                <div class='outer_div'></div><!-- Carga los datos ajax -->
            </div> <!-- /widget-content -->
        </div> <!-- /widget --></br></br></br>
    </div> <!-- /span9 -->
</div> <!-- /main -->


<div id="facturar" class="modal fade" tabindex="-1" role="dialog" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="alert alert-info alert-dismissable">
                    <strong>Desea Facturar?</strong> 
                </div>
                <div id="resultados_fac"></div>
                <form method="post" id="form_fac" name="form_fac" >
                    <div class="form-group">
                        <label>Fecha de Facturación</label>
                        <input type="date"  name="fecha_facturacion" id="datepicker" class="form-control" value="<?php echo  date('Y-m-d');?>" data-date-format="yyyy-mm-dd" name="desde" autocomplete="off" >

                    </div> <!-- /.form-group -->
                    <div class="form-group">
                        <label>PLAZO DE PAGO</label>
                        <select NAME="dias"  class="form-control name_list input-sm" required>
                            <option VALUE="8">8 Dias</option>
                            <option VALUE="15" selected>15 Dias</option>
                            <option VALUE="30">30 Dias</option>
                            <option VALUE="45">45 Dias</option> 
                            <option VALUE="60">60 Dias</option> 
                        </select>
                    </div> <!-- /.form-group -->
                     <label>NUMERACION</label>
                        <select name="serie_efe" id="serie_efe" class="form-control name_list" >
                            <?php
                                $serie11=mysqli_query($con,"SELECT * FROM serie_factura WHERE empresa='$empresa' and ser_predeterminda='si' and ser_tipo='pos' and ser_estado='activo' ") ;
                                while( $serie1 = mysqli_fetch_array( $serie11 ) )
                                {
                                    echo' <option value="'.$serie1['ser_id'].'">'.$serie1['ser_prefijo'].' '.$serie1['ser_inicio'].'-'.$serie1['ser_fin'].'</option>';
                                }

                                $serie22=mysqli_query($con,"SELECT * FROM serie_factura WHERE empresa='$empresa' and ser_predeterminda='no' and ser_tipo='pos' and ser_estado='activo' ") ;
                                while( $serie2 = mysqli_fetch_array( $serie22 ) )
                                {
                                    echo' <option value="'.$serie2['ser_id'].'">'.$serie2['ser_prefijo'].' '.$serie2['ser_inicio'].'-'.$serie2['ser_fin'].'</option>';
                                }
                            ?>
                        </select>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                        <button name="btn_facturar" id="btn_facturar" class="btn btn-success"><i class="icon-ok"></i> <strong>Aceptar</strong></button>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div> 

<div class="modal fade" id="anular" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Anular</h4>
            </div>
            <div class="modal-body">
                <div id="form-anular"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="desactivar" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Desactivar</h4>
            </div>
            <div class="modal-body">
                <div id="form-desactivar"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$("#form_fac").submit(function( event ) {
$('#btn_facturar').attr("disabled", true);

var parametros = $(this).serialize();
  
   $.ajax({
      type: "POST",
      url: "php_facturacion_periodica/factura_automatica.php",
      data: parametros,
        beforeSend: function(objeto){
         $('#resultados_fac').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
      success: function(datos){
      $("#resultados_fac").html(datos);
      $('#btn_facturar').attr("disabled", false);
      //$('#editModal').modal('hide');
      //$('body').removeClass('modal-open');
      //$('.modal-backdrop').remove();
      //loadTabla();
      }
  });
  event.preventDefault();
})
</script>
<script type="text/javascript" src="php_facturacion_periodica/ajax.js"></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>';
}
?>