<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');
?>
<script type="text/javascript">
$(setup)
function setup() {
      $('#intro select').zelect({ placeholder:'' })
}
</script>
<div id="resultado_adelanto"></div>
<div id="ventana_ade">
    <form method="post" action="" id="form_adelanto" name="form_adelanto">
        <div class="form-group">
            <span class="input-group-btn"  align="right" >
                <button href="#nuevocliente" class="btn btn-default input-sm" data-toggle="modal" type="button" href="#buscarcliente"><i class="btn-icon-only icon-plus"> </i>Nuevo
                </button>
            </span> 
          
            

            <label class="pull-left">Nombre</label>
            <section id="intro" >
                <select name="clie_id" id="clie_id"  class="form-control name_list" required>
                    <option value=""> - </option>
                    <?php  
                        $datos=mysqli_query($con,"SELECT * FROM cliente WHERE empresa='$empresa' and clie_nombre<>'CLIENTE MOSTRADOR'");
                        while( $fila=mysqli_fetch_array($datos))
                        {
                             echo'<option value="'.$fila['clie_id'].'">'.$fila['clie_cc'].' - '.$fila['clie_nombre'].'</option>';
                        }
                    ?>
                </select>
            </section> 
            <label>Concepto </label>
            <input type="text" name="concepto" value="" class="form-control name_list" autocomplete="off" required >
            <label>Valor Total </label>
            <input type="number" name="total" value="" class="form-control name_list" autocomplete="off" required >
            <label class="pull-left">Forma de Pago</label> </br>
            <div class="middle" id="ventana2">
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="efectivo" checked onChange="pago_adelantado(this)"/>
                    <div class="front-end box"><span>EFECTIVO</span></div>
                </label>
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="transferencia" onChange="pago_adelantado(this)"/>
                    <div class="back-end box"><span>TRANSFERENCIA</span></div>
                </label>
                <label>
                    <input type="radio" name="forma_pago" id="forma_pago" value="tarjeta" onChange="pago_adelantado(this)"/>
                    <div class="back-end box"><span>TARJETA</span></div>
                </label>
            </div>
            <div id="div_efectivo_adel" style="display: "> </div>

            <div id="div_nota_adel" style="display: none">
                <label>Nota Credito Disponible</label>
                <input type="text" name="nota_credito" id="nota_credito" value="" class="form-control name_list" autocomplete="off" readonly >
            </div>

            <div id="div_medio_pago_adel" style="display: none">
                <label>PLATAFORMA DE PAGO</label>
                <select name="medio_pago" id="medio_pago" class="form-control name_list input-sm" required>
                    <?php
                        $datos = mysqli_query($con,"SELECT * FROM banco WHERE empresa='$empresa' order by ban_nombre asc") ;
                        while( $fila = mysqli_fetch_array( $datos ) )
                        {
                            echo' <option value="'.$fila['ban_nombre'].'">'.$fila['ban_nombre'].'</option>';
                        }
                    ?>
                </select>
            </div>
            <label>Abono </label>
            <input type="number" name="valor" value="" class="form-control name_list" autocomplete="off" required >
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
            <button type="submit" class="btn btn-info" name="btn_adelanto" id="btn_adelanto">Registrar</button>
        </div>
    </form>
</div>
<script>
function pago_adelantado(sel) {
    if (sel.value=="efectivo")
    {
        divC = document.getElementById("div_nota_adel");
        divC.style.display = "none";
        divT = document.getElementById("div_medio_pago_adel");
        divT.style.display = "none";
        divT = document.getElementById("div_efectivo_adel");
        divT.style.display = "block";
    } 
    else if (sel.value=="nota credito")
    {
        divC = document.getElementById("div_nota_adel");
        divC.style.display = "";
        divT = document.getElementById("div_medio_pago_adel");
        divT.style.display = "none";
        divT = document.getElementById("div_efectivo_adel");
        divT.style.display = "none";
    } 
    else 
    {
        divC = document.getElementById("div_nota_adel");
        divC.style.display="none";
        divT = document.getElementById("div_medio_pago_adel");
        divT.style.display = "";
        divT = document.getElementById("div_efectivo_adel");
        divT.style.display = "none";
    }
}
</script>  
<script>
$("#form_adelanto").submit(function( event ) {
$('#btn_adelanto').attr("disabled", true);
var parametros=$(this).serialize();
    $.ajax({
    type: "POST",
    url: "php_movimientos/registrar_adelanto.php",
    data: parametros,
    beforeSend: function(objeto){
     $('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
    },
    success: function(datos){
    $("#resultados").html(datos);
    $('#btn_adelanto').attr("disabled", false);
    document.getElementById("form_adelanto").reset();
    $('#adelanto').modal('hide');
    $('body').removeClass('modal-open');
    $('.modal-backdrop').remove();
    load(1);
    }
    });
    event.preventDefault();
})
</script>
<style>
.middle {
  width: 100%;
  text-align: center;
  /* Made by */
}
.middle h1 {
  font-family: "Dax", sans-serif;
  color: #ccc;
}
.middle input[type="radio"] {
  display: none;
}
.middle input[type="radio"]:checked + .box {
  background-color: #009e90;
}
.middle input[type="radio"]:checked + .box span {
  color: white;
  transform: translateY(70px);
}
.middle input[type="radio"]:checked + .box span:before {
  transform: translateY(0px);
  opacity: 1;
}
.middle .box {
  width: 131px;
  height: 60px;
  background-color: #ccc;
  transition: all 250ms ease;
  will-change: transition;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  position: relative;
  font-family: "Dax", sans-serif;
  font-weight: 900;
  padding-top: 19px;
}
.middle .box span {
  left: 0;
  right: 0;
}
</style>