<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php');
$ven_id=$_GET['id']; 
$can1=mysqli_query($con,"SELECT * FROM ventas where ven_id='$ven_id'") or die(mysqli_error($con)); 
$dato1=mysqli_fetch_array($can1);
$prefijo=$dato1['ven_prefijo'];
$numero=$dato1['ven_n_venta'];
$ven_nombre=$dato1['ven_nombre'];
?>
<div id="resultados_dian"></div>
<div id="enviar_fact">                
    <div class="alert alert-info alert-dismissable">
         Desea convertir la venta <strong> <?php echo $prefijo.$numero; ?></strong>
    </div>

    <label>TIPO DE VENTA</label>
    <section>
        <div class="col-xs-6">
            <input type="radio" id="bot_pos1" name="tipo_venta" class="input_radio" value="pos" onclick="javascript:serie_fac()" >
            <label for="bot_pos1" class="label_radio" > POS ELECTRONICO</label>
        </div>
        <div class="col-xs-6">
            <input type="radio" id="bot_electronica1" name="tipo_venta" class="input_radio" value="electronica" onclick="javascript:serie_fac()" checked >
            <label for="bot_electronica1" class="label_radio"> ELECTRONICA </label>
        </div>
    </section>

    <div id="div_pos1" style="display: none; " >
        <form method="post" action="" id="enviar_pos" name="enviar_pos">
            <label>NUMERACION</label>
            <select name="serie_efe" id="serie_efe" class="form-control name_list" required>
                <?php
                    $serie11=mysqli_query($con,"SELECT * FROM serie_factura WHERE empresa='$empresa' and ser_tipo='pos electronico' 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>';
                    }
                ?>
            </select>
            <input type="hidden" id="ven_id" name="ven_id" value="<?php echo $ven_id; ?>" class="form-control name_list" readonly>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="submit" name="btn_enviar_pos" class="btn btn-success" id="btn_enviar_pos">Enviar</button>
            </div>
        </form>
     </div>


    <div id="div_electronica1" style="display: block; " >
        <form method="post" action="" id="enviar_electronica" name="enviar_electronica">
            <label>NUMERACION</label>
            <select name="serie_efe_electronica" id="serie_efe_electronica" class="form-control name_list" required>
                <?php
                    $serie33=mysqli_query($con,"SELECT * FROM serie_factura WHERE empresa='$empresa' and ser_predeterminda='si' and ser_tipo='electronica' and ser_estado='activo' and ser_tipo_documento='1' ") ;
                    while( $serie3 = mysqli_fetch_array( $serie33 ) )
                    {
                        echo'<option value="'.$serie3['ser_id'].'">'.$serie3['ser_prefijo'].' '.$serie3['ser_inicio'].'-'.$serie3['ser_fin'].'</option>';
                    }
                    $serie44=mysqli_query($con,"SELECT * FROM serie_factura WHERE empresa='$empresa' and ser_predeterminda='no' and ser_tipo='electronica' and ser_estado='activo' and ser_tipo_documento='1' ") ;
                    while( $serie4 = mysqli_fetch_array( $serie44 ) )
                    {
                        echo'<option value="'.$serie4['ser_id'].'">'.$serie4['ser_prefijo'].' '.$serie4['ser_inicio'].'-'.$serie4['ser_fin'].'</option>';
                    }
                ?>
            </select>
            <input type="hidden" id="ven_id" name="ven_id" value="<?php echo $ven_id; ?>" class="form-control name_list" readonly>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="submit" name="btn_enviar_electronica" class="btn btn-success" id="btn_enviar_electronica">Enviar</button>
            </div>
        </form>
    </div>

</div>

<script type="text/javascript">
$( "#enviar_pos" ).submit(function( event ) {
$('#btn_enviar_pos').attr("disabled", true);

var parametros = $(this).serialize();
$.ajax({
    type: "POST",
    url: "php_doc_equivalente/convertir_factura.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_dian').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
    },
        success: function(datos){
        $("#resultados_dian").html(datos);
        $('#btn_enviar_pos').attr("disabled", false);
        $('#enviar_fact').hide(); 
        load(1);
      }
    });
    event.preventDefault();
})



$( "#enviar_electronica" ).submit(function( event ) {
$('#btn_enviar_electronica').attr("disabled", true);

var parametros = $(this).serialize();
$.ajax({
    type: "POST",
    url: "php_doc_factura/convertir_factura.php",
    data: parametros,
        beforeSend: function(objeto){
         $('#resultados_dian').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
    },
        success: function(datos){
        $("#resultados_dian").html(datos);
        $('#btn_enviar_electronica').attr("disabled", false);
        $('#enviar_fact').hide(); 
        load(1);
      }
    });
    event.preventDefault();
})


function serie_fac() 
{
    //efectivo
    bot_pos1 = document.getElementById("bot_pos1");
    bot_electronica1 = document.getElementById("bot_electronica1");    

    div_pos1 = document.getElementById("div_pos1");
    div_electronica1 = document.getElementById("div_electronica1");
    
    if (bot_pos1.checked) 
    {
        div_pos1.style.display='block';
        div_electronica1.style.display='none';
    }
    if (bot_electronica1.checked) 
    {
        div_pos1.style.display='none';
        div_electronica1.style.display='block';
    }  
}
</script>
<style type="text/css">
.input_radio {
  display: none;
  &:not(:disabled) ~ label {
    cursor: pointer;
  }
  &:disabled ~ label {
    color: hsla(150, 5%, 75%, 1);
    border-color: hsla(150, 5%, 75%, 1);
    box-shadow: none;
    cursor: not-allowed;
  }
}
.label_radio {
  height: 100%;
  display: block;
  background: white;
  border: 2px solid hsla(150, 75%, 50%, 1);
  border-radius: 5px;
  padding-top: 1rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  text-align: center;
  box-shadow: 0px 3px 10px -2px hsla(150, 5%, 65%, 0.5);
  position: relative;
}
.input_radio:checked + label {
  background: hsla(150, 75%, 50%, 1);
  color: hsla(215, 0%, 100%, 1);
  box-shadow: 0px 0px 20px hsla(150, 100%, 50%, 0.75);
  &::after {
    color: hsla(215, 5%, 25%, 1);
    font-family: FontAwesome;
    border: 2px solid hsla(150, 75%, 45%, 1);
    content: "\f00c";
    font-size: 15px;
    position: absolute;
    top: -15px;
    left: 91%;
    transform: translateX(-50%);
    height: 35px;
    width: 35px;
    line-height: 30px;
    text-align: center;
    border-radius: 50%;
    background: white;
    box-shadow: 0px 2px 5px -2px hsla(0, 0%, 0%, 0.25);
  }
}
@media only screen and (max-width: 700px) {
  section {
    flex-direction: column;
  }
}
</style>