<?php
session_start();
require_once('conexion.php');
require_once('include/sesiones.php');
if (isset($_SESSION['usu_nombre']))
{
   
?>
<!DOCTYPE html>
<html lang="en">
<head>
	   <?php include ('head.php'); ?>
</head>
<body >
<?php
  $inicio="";
  $M_inventario="";
  $M_contactos="";
  $M_compras="";
  $M_ventas="";
  $M_pedidos="";
  $M_pos="";
  $R_reportes="";

  $m_empresa="";
  $m_sucursales="";
  $m_mesas="";
  $m_configuraciones="";
  $m_online="";

  include ('menu.php');
?>  
<div class="main">
    <div class="col-md-2">
		<?php include ('include/menu_inicio.php'); ?> 
	</div> <!-- /span6 -->
<?php
if ($facturador=='si')
{
?>
    <div class="col-md-10">	
        <div class="widget stacked ">
            <div class="widget stacked ">
                <div class="widget-content">
                    <div class="col-md-11">
                        <form name="form_url" id="form_url" method="post" >
                            <div id="resultados_url"></div>
                            <div class="">
                                <label>Url Api</label>
                                <input type="text" class="form-control input-sm" name="id_url" value="<?php echo $ele_url; ?>" required >
                                <label>Token</label>
                                <input type="text" class="form-control input-sm" name="id_token" value="<?php echo $token; ?>" required >
                                 <label>Fecha expiracion de cerificado</label>
                                <input type="text" class="form-control input-sm" name="fecha_certi" value="<?php echo $fecha_certi; ?>" readonly >
                            </div> <!-- /.form-group -->
               
                            <div class="modal-footer">
                                <button id="boton_url" type="submit" class="btn btn-success">Modificar</button> 
                            </div>
                        </form>
                    </div>
                </div>
            </div>



            <div class="widget stacked ">
                <div class="widget-content">
                    <div class="row-fluid user-row">
                        <div class="col-md-1">
                            <i class="fas fa-briefcase fa-4x"></i>
                        </div>
                        <div class="col-md-10">
                            </br>
                            <h4> <strong>INFORMACIÓN EMPRESA</strong></h4>
                            <span class="text-muted"></span>
                        </div>
                        <div class="col-md-1 dropdown-user" data-for=".empresa">
                            <i class="icon-chevron-down text-muted"></i>
                        </div>
                    </div>

                    <div class="row-fluid user-infos empresa">
                        <form name="form_empresa_registrar" id="form_empresa_registrar" method="post">
                            <div class="col-md-11" id="resultados_empresa_registrar"></div>
                            <div class="col-md-1" ></div>
                            <div class="col-md-4" >
                                <div class="">
                                    <label>Tipo Documento</label>
                                    <select name="api_tipo_doc" class="form-control name_list input-sm" required >
                                        <?php
                                            $datos = mysqli_query($api,"SELECT * FROM type_document_identifications where id=3") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo' <option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                            }
                                           
                                            $datos = mysqli_query($api,"SELECT * FROM type_document_identifications where id<>3") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo' <option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="">
                                    <div class=" col-md-9" style="padding:0px;">
                                        <label>Documento</label>
                                        <input type="number" name="api_documento" onblur="CalcularDv_m()" class="form-control input-sm" value="" required>
                                    </div> <!-- /.form-group -->
                                    <div class="col-md-3" style="padding-left:10px;padding-right: 0px;"> <!-- /.form-group -->
                                        <label>Dv</label>
                                        <input type="number" name="api_dv" class="form-control input-sm" value="" required>
                                    </div>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Nombre</label>
                                    <input type="text" class="form-control input-sm" name="api_nombre" value="" required>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Telefono</label>
                                    <input type="number" class="form-control input-sm" name="api_telefono" value="" required>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Direccion</label>
                                    <input type="text" class="form-control input-sm" name="api_direccion" value="" required>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Ciudad</label>
                                     <section id="intro" >
                                        <select name="api_ciudad" class="form-control name_list input-sm" required>
                                            <option value=""> - </option>
                                            <?php
                                                $datos = mysqli_query($api,"SELECT * FROM municipalities order by name asc") ;
                                                while( $fila = mysqli_fetch_array( $datos ) )
                                                {
                                                echo '<option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                                }
                                            ?>
                                        </select>
                                    </section>
                                </div>
                            </div> 
                            <div class="col-md-4" >
                                <div class="">
                                    <label>Email</label>
                                    <input type="email" class="form-control input-sm" name="api_correo" value="" required>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Registro Mercantil</label>
                                    <input type="text" class="form-control input-sm" name="api_registro" value="" required>
                                </div> <!-- /.form-group -->
                                <div>
                                    <label>Tipo Contribuyente</label>
                                    <select name="api_contribuyente" name="api_contribuyente" class="form-control name_list input-sm" required>
                                        <option value=''> - </option>
                                        <?php
                                            $datos = mysqli_query($api,"SELECT * FROM type_organizations order by id desc") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo '<option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                            }
                                            ?>
                                    </select>
                                </div>
                                <div>
                                    <label>Tipo Regimen</label>
                                    <select name="api_regimen" name="api_regimen" class="form-control name_list input-sm" required >
                                        <option value=''> - </option>
                                        <?php
                                            $datos = mysqli_query($api,"SELECT * FROM type_regimes order by id desc") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo '<option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div>
                                    <label>Tipo liability</label>
                                    <select id="api_liability" name="api_liability"  class="form-control name_list input-sm" required >
                                        <option value=''> - </option>
                                         <?php
                                            $datos = mysqli_query($api,"SELECT * FROM type_liabilities order by id desc") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo '<option value="'.$fila['id'].'">'.$fila['name'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>                           
                            </div>
                            <div class="col-md-3" >
                                <div class="">
                                    <label>Email de Envio de documentos</label>
                                    <input type="email" class="form-control input-sm" name="correo_envio" value="" required>
                                </div> <!-- /.form-group -->
                                <div class="">
                                    <label>Clave</label>
                                    <input type="text" class="form-control input-sm" name="clave_envio" value="" required>
                                </div> <!-- /.form-group --> 
                            </div>

                            <div class="col-md-11" >
                                <div class="modal-footer">
                                    <button id="boton_empresa_registrar" type="submit" class="btn btn-success">REGISTRAR </button> 
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>


            <div class="widget stacked ">
                <div class="widget-content">
                    <div class="row-fluid user-row">
                        <div class="col-md-1">
                            <i class="fas fa-money-bill-alt fa-4x " ></i>
                        </div>
                        <div class="col-md-10">
                            </br>
                            <h4><strong>SOFTWARE</strong></h4>
                            <span class="text-muted"></span>
                        </div>
                        <div class="col-md-1 dropdown-user" data-for=".software">
                            <i class="icon-chevron-down text-muted"></i>
                        </div>
                    </div>
                    <div class="row-fluid user-infos software">
                        
                        <div class="col-md-11" id="resultados_software_registrar" ></div>
                        <div class="col-md-1" ></div>
                        
                        <div class="col-md-3" >
                            <form name="form_software_fac" id="form_software_fac" method="post">
                                          
                                <label>Factura Electronica</label>
                                <input type="text" class="form-control input-sm" name="api_software_fac" value="<?php echo $ele['iden_soft_ele']; ?>" required >
                                <label>Pin</label>
                                <input type="text" class="form-control input-sm" name="api_pin_fac" value="12345" required >
                                <label>settestid</label>
                                <input type="text" class="form-control input-sm" name="settestid_fac" value="<?php echo $ele['ele_settestid']; ?>">
                                <div class="modal-footer">
                                    <?php
                                    if($ele['ele_ambiente_ele']=="produccion")
                                    { ?>
                                        <a data-tipo="ele" onclick="ambiente(this)" class="btn activo">Producción</a>
                                    <?php } else { ?>
                                        <a data-tipo="ele" onclick="ambiente(this)" class="btn inactivo">Habilitación</a>
                                    <?php } ?>  
                                    <button id="boton_software_fac" type="submit" class="btn btn-success">REGISTRAR </button> 
                                </div>

                                 
                           </form>
                        </div> 
                        <div class="col-md-1" ></div>
                        <div class="col-md-3" >
                            <form name="form_software_pos" id="form_software_pos" method="post">
                                <label>Documento Equivalente pos </label>
                                <input type="text" class="form-control input-sm" name="api_software_pos" value="<?php echo $ele['iden_soft_pos']; ?>" required>
                                <label>Pin</label>
                                <input type="text" class="form-control input-sm" name="api_pin_pos" value="12345" required>
                                <label>settestid</label>
                                <input type="text" class="form-control input-sm" name="settestid_pos" value="<?php echo $ele['ele_settestid_pos']; ?>" >
                                <div class="modal-footer">
                                    <?php
                                    if($ele['ele_ambiente_pos']=="produccion")
                                    { ?>
                                        <a data-tipo="pos" onclick="ambiente(this)" class="btn activo">Producción</a>
                                    <?php } else { ?>
                                        <a data-tipo="pos" onclick="ambiente(this)" class="btn inactivo">Habilitación</a>
                                    <?php } ?>  
                                    <button id="boton_software_pos" type="submit" class="btn btn-success">REGISTRAR </button> 
                                </div>
                            </form>
                        </div> 
                        <div class="col-md-1" ></div>
                        <div class="col-md-3" >
                            <form name="form_software_nom" id="form_software_nom" method="post">
                                <label>Nomina </label>
                                <input type="text" class="form-control input-sm" name="api_software_nom" value="<?php echo $ele['iden_soft_nom']; ?>" required>
                                <label>Pin</label>
                                <input type="text" class="form-control input-sm" name="api_pin_nom" value="12345" required>
                                <label>settestid</label>
                                <input type="text" class="form-control input-sm" name="settestid_nom" value="<?php echo $ele['ele_settestid_nomina']; ?>" >
                                <div class="modal-footer">
                                    <?php
                                    if($ele['ele_ambiente_nom']=="produccion")
                                    { ?>
                                        <a data-tipo="nom" onclick="ambiente(this)" class="btn activo">Producción</a>
                                    <?php } else { ?>
                                        <a data-tipo="nom" onclick="ambiente(this)" class="btn inactivo">Habilitación</a>
                                    <?php } ?>  
                                    <button id="boton_software_nom" type="submit" class="btn btn-success">REGISTRAR </button> 
                                </div>
                            </form>
                        </div> 
                    </div>
                </div>
            </div>
           

            <div class="widget stacked ">
                <div class="widget-content">
                    <div class="row-fluid user-row">
                       
                        <div class="col-md-1">
                            <i class="fas fa-reply fa-4x " ></i>
                        </div>
                        <div class="col-md-10">
                            </br>
                            <h4><strong>CERTIFICADO</strong></h4>
                            <span class="text-muted"></span>
                        </div>
                       
                        <div class="col-md-1 dropdown-user" data-for=".certificado">
                            <i class="icon-chevron-down text-muted"></i>
                        </div>
                    </div>
                    <div class="row-fluid user-infos certificado">
                        <form name="form_certificado" id="form_certificado" method="post" enctype="multipart/form-data">
                            <div class="col-md-11" id="resultados_certificado" ></div>
                            <div class="col-md-1" ></div>
                            <div class="col-md-5" >
                                <div class="">
                                    <label>&nbsp;</label>
                                    <label for="imagen" style="width: 100%;">Certificado .pfx </label>
                                    <input type="file" name="certi" id="imagen">
                                </div> <!-- /.form-group -->
                            </div> 

                            <div class="col-md-5" >
                                <div class="">
                                    <label>Contraseña</label>
                                    <input type="text" class="form-control input-sm" id="api_contrasena" name="api_contrasena" value="" required >
                                </div> <!-- /.form-group -->
                            </div> 

                            <div class="col-md-11" >
                                <div class="modal-footer">
                                    <button id="boton_certificado" type="submit" class="btn btn-success">REGISTRAR </button> 
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>





            <div class="widget stacked ">
                <div class="widget-content">
                    <div class="row-fluid user-row">
                        <div class="col-md-1">
                            <i class="fas fa-hashtag fa-4x"></i>
                         </div>
                        <div class="col-md-10">
                            </br>
                            <h4><strong>NUMERACIÓN DE DOCUMENTOS</strong></h4>
                            <span class="text-muted"></span>
                        </div>
                        <div class="col-md-1 dropdown-user" data-for=".serie">
                            <i class="icon-chevron-down text-muted"></i>
                        </div>
                    </div>
                    <div class="row-fluid user-infos serie">
                        <div class="offset1">
                            <div class="col-md-6" style="padding-left: 0px;">
                                <a href="php_api/4_registrar_resolucion.php?tipo_res=electronica" class="btn btn-info">FACTURA ELECTRONICA </a>
                                <a href="php_api/4_registrar_resolucion.php?tipo_res=pos" class="btn btn-info">DOCUMENTO EQUIVALENTE </a>
                            </div>
                            
                            <div class="col-md-10"></br></div>
                            <div class="resultados_tabla_resolucion"></div>    
                        </div>
                    </div>
                </div>
            </div>
        </div> <!-- /widget-content --></br></br></br></br>
    </div> <!-- /container -->
<?php   }  ?>
</div> <!-- /main -->


<div id="clave" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <form method="get" name="form_clave" id="form_clave">
                    <div class="alert alert-info alert-dismissable">
                        <strong>Consultar Clave Tecnica</strong> <a href="#" class="alert-link"></a>
                    </div>
                    <div id="resultados_clave"></div>
                   
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-info" id="btn_clave"><i class="icon-search"></i> <strong>Aceptar</strong></button>
                    </div>
                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div> 
</div> 
<?php
	include ('php_caja/caja_abrir.php');
	include ('script.php');
?> 

<script type="text/javascript">

function ambiente(elemento) {
    let estado, tipo = elemento.getAttribute("data-tipo");

    if (elemento.classList.contains('activo')) {
        elemento.classList.remove('activo');
        elemento.classList.add('inactivo');
        elemento.textContent = 'Habilitación';
        estado = 'habilitacion';
    } else {
        elemento.classList.remove('inactivo');
        elemento.classList.add('activo');
        elemento.textContent = 'Producción';
        estado = 'produccion';
    }

    // Enviar tipo y estado por AJAX
    $.ajax({
        type: "GET",
        url: "php_api/ambiente.php",
        data: {
            tipo: tipo,
            estado: estado
        },
         success: function(datos){
        $("#resultados_software_registrar").html(datos);
        }
    });
}


$("#form_url").submit(function( event ) {
$('#boton_url').attr("disabled", true);
var parametros = $(this).serialize();
    $.ajax({
    type: "POST",
    url: "php_api/editar_url.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_url').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados_url").html(datos);
        $('#boton_url').attr("disabled", false);
        }
    });
    event.preventDefault();
})

  
$("#form_empresa_registrar").submit(function( event ) {
$('#boton_empresa_registrar').attr("disabled", true);
var parametros = $(this).serialize();
    $.ajax({
    type: "POST",
    url: "php_api/1_registrar_empresa.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_empresa_registrar').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados_empresa_registrar").html(datos);
        $('#boton_empresa_registrar').attr("disabled", false);
        }
    });
    event.preventDefault();
})




$( "#form_software_fac" ).submit(function( event ) {
$('#boton_software_fac').attr("disabled", true);
var parametros = $(this).serialize();

    $.ajax({
    type: "POST",
    url: "php_api/2_registrar_sofware_fac.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_software_registrar').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
     
        success: function(datos){
        $("#resultados_software_registrar").html(datos);
        $('#boton_software_fac').attr("disabled", false);
        }
    });
    event.preventDefault();
})

$( "#form_software_nom" ).submit(function( event ) {
$('#boton_software_nom').attr("disabled", true);
var parametros = $(this).serialize();

    $.ajax({
    type: "POST",
    url: "php_api/2_registrar_sofware_nom.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_software_registrar').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
     
        success: function(datos){
        $("#resultados_software_registrar").html(datos);
        $('#boton_software_nom').attr("disabled", false);
        }
    });
    event.preventDefault();
})

$( "#form_software_pos" ).submit(function( event ) {
$('#boton_software_pos').attr("disabled", true);
var parametros = $(this).serialize();

    $.ajax({
    type: "POST",
    url: "php_api/2_registrar_sofware_pos.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_software_registrar').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
     
        success: function(datos){
        $("#resultados_software_registrar").html(datos);
        $('#boton_software_pos').attr("disabled", false);
        }
    });
    event.preventDefault();
})



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



</script>
<style type="text/css">


.user-row {
    margin-bottom: 0px;
}

.user-row:last-child {
    margin-bottom: 0;
}

.dropdown-user {
    margin: 13px 0;
    padding: 5px;
    height: 100%;
}

.dropdown-user:hover {
    cursor: pointer;
}

</style>
<script type="text/javascript">
    $(document).ready(function() {
    var panels = $('.user-infos');
    var panelsButton = $('.dropdown-user');
    panels.hide();
    //Click dropdown
    panelsButton.click(function() {
        //get data-for attribute
        var dataFor = $(this).attr('data-for');
        var idFor = $(dataFor);

        //current button
        var currentButton = $(this);
        idFor.slideToggle(400, function() {
            //Completed slidetoggle
            if(idFor.is(':visible'))
            {
                currentButton.html('<i class="icon-chevron-up text-muted"></i>');
            }
            else
            {
                currentButton.html('<i class="icon-chevron-down text-muted"></i>');
            }
        })
    });
    $('[data-toggle="tooltip"]').tooltip();
});


</script>  
<style>
    .estado-btn {
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none; /* quita subrayado del enlace */
    display: inline-block;
  }

  .activo {
    background-color: #007bff; /* Verde */
    color: white;
  }

  .inactivo {
    background-color: #dc3545; /* Rojo */
    color: white;
  }
</style> 

    </body>
</html>
<?php
}
else
{
    echo '<script>location.href = "index.php";</script>';
}
?>